-
Notifications
You must be signed in to change notification settings - Fork 143
/
generate-docker-bake.sh
executable file
·89 lines (73 loc) · 2.04 KB
/
generate-docker-bake.sh
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
#!/bin/sh
set -e
GOCRONVER="v0.0.11"
MAIN_TAG="17"
TAGS_EXTRA="16 15 14 13"
PLATFORMS="linux/amd64 linux/arm64 linux/arm/v7 linux/s390x linux/ppc64le"
DOCKER_BAKE_FILE="${1:-docker-bake.hcl}"
cd "$(dirname "$0")"
P="\"$(echo $PLATFORMS | sed 's/ /", "/g')\""
T="\"debian-latest\", \"alpine-latest\", \"$(echo debian-$TAGS_EXTRA | sed 's/ /", "debian-/g')\", \"$(echo alpine-$TAGS_EXTRA | sed 's/ /", "alpine-/g')\""
cat > "$DOCKER_BAKE_FILE" << EOF
group "default" {
targets = [$T]
}
variable "REGISTRY_PREFIX" {
default = ""
}
variable "IMAGE_NAME" {
default = "postgres-backup-local"
}
variable "BUILD_REVISION" {
default = ""
}
target "debian" {
args = {"GOCRONVER" = "$GOCRONVER"}
dockerfile = "debian.Dockerfile"
}
target "alpine" {
args = {"GOCRONVER" = "$GOCRONVER"}
dockerfile = "alpine.Dockerfile"
}
target "debian-latest" {
inherits = ["debian"]
platforms = [$P]
args = {"BASETAG" = "$MAIN_TAG"}
tags = [
"\${REGISTRY_PREFIX}\${IMAGE_NAME}:latest",
"\${REGISTRY_PREFIX}\${IMAGE_NAME}:$MAIN_TAG",
notequal("", BUILD_REVISION) ? "\${REGISTRY_PREFIX}\${IMAGE_NAME}:$MAIN_TAG-debian-\${BUILD_REVISION}" : ""
]
}
target "alpine-latest" {
inherits = ["alpine"]
platforms = [$P]
args = {"BASETAG" = "$MAIN_TAG-alpine"}
tags = [
"\${REGISTRY_PREFIX}\${IMAGE_NAME}:alpine",
"\${REGISTRY_PREFIX}\${IMAGE_NAME}:$MAIN_TAG-alpine",
notequal("", BUILD_REVISION) ? "\${REGISTRY_PREFIX}\${IMAGE_NAME}:$MAIN_TAG-alpine-\${BUILD_REVISION}" : ""
]
}
EOF
for TAG in $TAGS_EXTRA; do cat >> "$DOCKER_BAKE_FILE" << EOF
target "debian-$TAG" {
inherits = ["debian"]
platforms = [$P]
args = {"BASETAG" = "$TAG"}
tags = [
"\${REGISTRY_PREFIX}\${IMAGE_NAME}:$TAG",
notequal("", BUILD_REVISION) ? "\${REGISTRY_PREFIX}\${IMAGE_NAME}:$TAG-debian-\${BUILD_REVISION}" : ""
]
}
target "alpine-$TAG" {
inherits = ["alpine"]
platforms = [$P]
args = {"BASETAG" = "$TAG-alpine"}
tags = [
"\${REGISTRY_PREFIX}\${IMAGE_NAME}:$TAG-alpine",
notequal("", BUILD_REVISION) ? "\${REGISTRY_PREFIX}\${IMAGE_NAME}:$TAG-alpine-\${BUILD_REVISION}" : ""
]
}
EOF
done