-
Notifications
You must be signed in to change notification settings - Fork 11
/
docker-bake.hcl
91 lines (87 loc) · 2.74 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
# 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-eimmigrate-${hostArch()}"
}
target "_common" {
dockerfile = "Dockerfile"
context = "./"
cache-from = [dockerS3Cache("${CACHE_ID}")]
cache-to = [notequal("false",GITHUB_ACTIONS) ? dockerS3Cache("${CACHE_ID}"): ""]
output = ["${OUTPUT}"]
}
/*
* Virtual Base Targets
*
* This section defines virtual base targets, which are shared across the
* different dependent targets.
*/
target "app" {
inherits = ["_common"]
tags = dockerTag("eimmigrate", "${DOCKER_TAG}", "")
}
/*
* 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 = ["app"]
}