-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdocker-bake.hcl
127 lines (122 loc) · 4.23 KB
/
docker-bake.hcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# docker-bake.hcl
/*
* Extract platform (arch) from current default host
* Utilizes built-in var BAKE_LOCAL_PLATFORM
* https://docs.docker.com/build/bake/file-definition/#built-in-variables
*
*/
function hostArch {
params = []
result = element(split("/", BAKE_LOCAL_PLATFORM), 1)
}
/*
* Docker Tagging variables
*
* Used to manage container images, and it's layers and cache
* Best effort Tags for local development vs Github Actions build/publish
* Local development: "latest"
* Github Actions: "$(git rev-parse --short HEAD)" -> "abc1234"
*/
variable "AWS_ACCOUNT_ID" {}
variable "PRIVATE_REGISTRY" { default = "${AWS_ACCOUNT_ID}.dkr.ecr.us-west-2.amazonaws.com" }
variable "REFERENCE" { default = "latest" }
variable "GITHUB_ACTIONS" { default = "false" }
variable "DOCKER_TAG" { default = notequal("false",GITHUB_ACTIONS) ? "${REFERENCE}": "latest" }
function "dockerTag" {
params = [image, tag, prefix]
result = concat(
notequal(prefix, "") ?
["${PRIVATE_REGISTRY}/${image}:${prefix}-${tag}"]:
["${PRIVATE_REGISTRY}/${image}:${tag}"],
)
}
/*
* Cache Layers in Github Actions
*
* Utilize S3 cache if AWS cli credentials are present
* More information
* https://docs.docker.com/build/cache/backends/s3/
*/
variable "AWS_ACCESS_KEY_ID" { default = "false" }
variable "AWS_SECRET_ACCESS_KEY" { default = "false" }
variable "DOCKER_S3_CACHE" {
default = "type=s3,mode=max,region=us-west-1,bucket=opensourcesanjose-cache"
}
function "dockerS3Cache" {
params = [cacheid]
result = and(
notequal("false",AWS_ACCESS_KEY_ID),
notequal("false",AWS_SECRET_ACCESS_KEY)
) ? join(",",
[
"${DOCKER_S3_CACHE}",
"name=${cacheid}",
]
): ""
}
variable "OUTPUT" { # output to docker for local development rather than GHCR
default = notequal("false",GITHUB_ACTIONS) ? "type=registry": "type=docker"
}
variable "CACHE_ID" {
default = "docker-happeningatm-${hostArch()}"
}
target "_common" {
output = ["${OUTPUT}"]
}
/*
* Virtual Base Targets
*
* This section defines virtual base targets, which are shared across the
* different dependent targets.
*/
// This builds the frontend bundle and serves using nginx
variable "PUBLIC_URL" { default = "http://localhost" }
variable "REACT_APP_GRAPHQL_URL" { default = "http://localhost" }
variable "REACT_APP_JWT_ISSUER" { default = "default-jwt" }
target "build" {
dockerfile = "docker/frontend/Dockerfile"
context = "./"
target = "nginx-build"
args = {
PUBLIC_URL = "${PUBLIC_URL}"
REACT_APP_GRAPHQL_URL = "${REACT_APP_GRAPHQL_URL}"
REACT_APP_JWT_ISSUER = "${REACT_APP_JWT_ISSUER}"
}
inherits = ["_common"]
tags = dockerTag("happeningatm", "${DOCKER_TAG}", "frontend")
cache-from = [dockerS3Cache("${CACHE_ID}-frontend")]
cache-to = [notequal("false",GITHUB_ACTIONS) ? dockerS3Cache("${CACHE_ID}-frontend"): ""]
}
target "frontend" {
dockerfile = "docker/frontend/Dockerfile"
context = "./"
target = "local"
inherits = ["_common"]
tags = dockerTag("happeningatm", "${DOCKER_TAG}", "frontend")
cache-from = [dockerS3Cache("${CACHE_ID}-frontend")]
cache-to = [notequal("false",GITHUB_ACTIONS) ? dockerS3Cache("${CACHE_ID}-frontend"): ""]
}
target "backend" {
dockerfile = "docker/backend/Dockerfile"
context = "./"
inherits = ["_common"]
tags = dockerTag("happeningatm", "${DOCKER_TAG}", "backend")
cache-from = [dockerS3Cache("${CACHE_ID}-backend")]
cache-to = [notequal("false",GITHUB_ACTIONS) ? dockerS3Cache("${CACHE_ID}-backend"): ""]
}
target "graphql" {
dockerfile = "docker/graphql/Dockerfile"
context = "./"
inherits = ["_common"]
tags = dockerTag("happeningatm", "${DOCKER_TAG}", "graphql")
cache-from = [dockerS3Cache("${CACHE_ID}-graphql")]
cache-to = [notequal("false",GITHUB_ACTIONS) ? dockerS3Cache("${CACHE_ID}-graphql"): ""]
}
/*
* Default Target(s) to build
* https://docs.docker.com/build/bake/file-definition/#default-targetgroup
* "docker buildx bake" == "docker buildx bake default"
*/
group "default" {
targets = ["frontend", "backend", "graphql"]
}