-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathdocker-bake.hcl
More file actions
189 lines (169 loc) · 6.13 KB
/
docker-bake.hcl
File metadata and controls
189 lines (169 loc) · 6.13 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
variable "IMAGE_NAME" {
default = "dunglas/frankenphp"
}
variable "VERSION" {
default = "dev"
}
variable "PHP_VERSION" {
default = "8.2,8.3,8.4,8.5"
}
variable "GO_VERSION" {
default = "1.26"
}
variable "BASE_FINGERPRINT" {
default = ""
}
variable "SPC_OPT_BUILD_ARGS" {
default = ""
}
variable "SHA" {}
variable "LATEST" {
default = true
}
variable "CACHE" {
default = ""
}
variable "CI" {
# CI flag coming from the environment or --set; empty by default
default = ""
}
variable DEFAULT_PHP_VERSION {
default = "8.5"
}
function "tag" {
params = [version, os, php-version, tgt]
result = [
version == "" ? "" : "${IMAGE_NAME}:${trimprefix("${version}${tgt == "builder" ? "-builder" : ""}-php${php-version}-${os}", "latest-")}",
php-version == DEFAULT_PHP_VERSION && os == "trixie" && version != "" ? "${IMAGE_NAME}:${trimprefix("${version}${tgt == "builder" ? "-builder" : ""}", "latest-")}" : "",
php-version == DEFAULT_PHP_VERSION && version != "" ? "${IMAGE_NAME}:${trimprefix("${version}${tgt == "builder" ? "-builder" : ""}-${os}", "latest-")}" : "",
os == "trixie" && version != "" ? "${IMAGE_NAME}:${trimprefix("${version}${tgt == "builder" ? "-builder" : ""}-php${php-version}", "latest-")}" : "",
]
}
# cleanTag ensures that the tag is a valid Docker tag
# cleanTag ensures that the tag is a valid Docker tag
# see https://github.com/distribution/distribution/blob/v2.8.2/reference/regexp.go#L37
function "clean_tag" {
params = [tag]
result = substr(regex_replace(regex_replace(tag, "[^\\w.-]", "-"), "^([^\\w])", "r$0"), 0, 127)
}
# semver adds semver-compliant tag if a semver version number is passed, or returns the revision itself
# see https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
function "semver" {
params = [rev]
result = __semver(_semver(regexall("^v?(?P<major>0|[1-9]\\d*)\\.(?P<minor>0|[1-9]\\d*)\\.(?P<patch>0|[1-9]\\d*)(?:-(?P<prerelease>(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$", rev)))
}
function "_semver" {
params = [matches]
result = length(matches) == 0 ? {} : matches[0]
}
function "__semver" {
params = [v]
result = v == {} ? [clean_tag(VERSION)] : v.prerelease == null ? [v.major, "${v.major}.${v.minor}", "${v.major}.${v.minor}.${v.patch}"] : ["${v.major}.${v.minor}.${v.patch}-${v.prerelease}"]
}
function "php_version" {
params = [v]
result = _php_version(v, regexall("(?P<major>\\d+)\\.(?P<minor>\\d+)", v)[0])
}
function "_php_version" {
params = [v, m]
result = "${m.major}.${m.minor}" == DEFAULT_PHP_VERSION ? [v, "${m.major}.${m.minor}", "${m.major}"] : [v, "${m.major}.${m.minor}"]
}
target "default" {
name = "${tgt}-php-${replace(php-version, ".", "-")}-${os}"
matrix = {
os = ["trixie", "bookworm", "alpine"]
php-version = split(",", PHP_VERSION)
tgt = ["builder", "runner"]
}
contexts = {
php-base = "docker-image://php:${php-version}-zts-${os}"
golang-base = "docker-image://golang:${GO_VERSION}-${os}"
}
dockerfile = os == "alpine" ? "alpine.Dockerfile" : "Dockerfile"
context = "./"
target = tgt
# arm/v6 is only available for Alpine: https://github.com/docker-library/golang/issues/502
platforms = os == "alpine" ? [
"linux/amd64",
"linux/386",
"linux/arm/v6",
"linux/arm/v7",
"linux/arm64",
] : [
"linux/amd64",
"linux/386",
"linux/arm/v7",
"linux/arm64"
]
tags = distinct(flatten(
[for pv in php_version(php-version) : flatten([
LATEST ? tag("latest", os, pv, tgt) : [],
tag(SHA == "" || VERSION != "dev" ? "" : "sha-${substr(SHA, 0, 7)}", os, pv, tgt),
VERSION == "dev" ? [] : [for v in semver(VERSION) : tag(v, os, pv, tgt)]
])
]))
labels = {
"org.opencontainers.image.created" = "${timestamp()}"
"org.opencontainers.image.version" = VERSION
"org.opencontainers.image.revision" = SHA
"dev.frankenphp.base.fingerprint" = BASE_FINGERPRINT
}
args = {
FRANKENPHP_VERSION = VERSION
}
secret = ["id=github-token,env=GITHUB_TOKEN"]
}
target "static-builder-musl" {
contexts = {
golang-base = "docker-image://golang:${GO_VERSION}-alpine"
}
dockerfile = "static-builder-musl.Dockerfile"
context = "./"
platforms = [
"linux/amd64",
"linux/arm64",
]
tags = distinct(flatten([
LATEST ? "${IMAGE_NAME}:static-builder-musl" : "",
SHA == "" || VERSION != "dev" ? "" : "${IMAGE_NAME}:static-builder-musl-sha-${substr(SHA, 0, 7)}",
VERSION == "dev" ? [] : [for v in semver(VERSION) : "${IMAGE_NAME}:static-builder-musl-${v}"]
]))
labels = {
"org.opencontainers.image.created" = "${timestamp()}"
"org.opencontainers.image.version" = VERSION
"org.opencontainers.image.revision" = SHA
"dev.frankenphp.base.fingerprint" = BASE_FINGERPRINT
}
args = {
FRANKENPHP_VERSION = VERSION
CI = CI
SPC_OPT_BUILD_ARGS = SPC_OPT_BUILD_ARGS
}
secret = ["id=github-token,env=GITHUB_TOKEN"]
}
target "static-builder-gnu" {
dockerfile = "static-builder-gnu.Dockerfile"
context = "./"
platforms = [
"linux/amd64",
"linux/arm64"
]
tags = distinct(flatten([
LATEST ? "${IMAGE_NAME}:static-builder-gnu" : "",
SHA == "" || VERSION != "dev" ? "" : "${IMAGE_NAME}:static-builder-gnu-sha-${substr(SHA, 0, 7)}",
VERSION == "dev" ? [] : [for v in semver(VERSION) : "${IMAGE_NAME}:static-builder-gnu-${v}"]
]))
labels = {
"org.opencontainers.image.created" = "${timestamp()}"
"org.opencontainers.image.version" = VERSION
"org.opencontainers.image.revision" = SHA
"dev.frankenphp.base.fingerprint" = BASE_FINGERPRINT
}
args = {
FRANKENPHP_VERSION = VERSION
GO_VERSION = GO_VERSION
CI = CI
SPC_OPT_BUILD_ARGS = SPC_OPT_BUILD_ARGS
}
secret = ["id=github-token,env=GITHUB_TOKEN"]
}