-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-bake.hcl
More file actions
254 lines (233 loc) · 8.41 KB
/
Copy pathdocker-bake.hcl
File metadata and controls
254 lines (233 loc) · 8.41 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# docker-bake.hcl - Parallel Docker builds for BPP
#
# Obraz dbservera (iplweb/bpp_dbserver) jest budowany w osobnym repo:
# https://github.com/iplweb/bpp-dbserver
#
# Usage:
# make build # Tylko lokalny obraz dev (ten z compose)
# make build-production # Obrazy produkcyjne (base + 5 serwisow)
# make build-all # Jedno i drugie
# make build-base # Build only base image
# docker buildx bake --print # Show build plan without executing
#
# Variables can be overridden via environment or --set flag:
# DOCKER_VERSION=202601.1234 make build
# docker buildx bake --set PUSH=true
variable "DOCKER_VERSION" {
default = "latest"
}
variable "PLATFORM" {
default = "linux/amd64"
}
variable "PUSH" {
default = false
}
variable "GIT_SHA" {
default = "unknown"
}
# Kontrolowany salt cache dla pakietów systemowych i zależności. Oficjalny
# workflow ustawia tydzień ISO, więc cache pozostaje szybki między buildami,
# ale co najmniej raz w tygodniu pobieramy świeże pakiety z repozytoriów.
variable "BUILD_CACHE_EPOCH" {
default = "manual"
}
# Rozróżnienie release vs developer build. Master release -> "release"
# (stopka pokazuje tylko numer wersji); PR/feature/lokalne -> "dev"
# (stopka dokleja `(<image_tag>, commit XXXXXXX)` po wersji, dla łatwego
# namierzenia którego commitu/buildu dotyczy obraz, gdy tag jest
# niejednoznaczny).
variable "BPP_BUILD_FLAVOR" {
default = "dev"
}
# Kanoniczny tag obrazu (np. "119-merge", nazwa brancha, "202604.1364"
# dla mastera). Workflow przekazuje wartość z steps.tag.outputs.final_tag.
variable "BPP_IMAGE_TAG" {
default = "unknown"
}
# Opcjonalny alias nazwy brancha dla starszych obrazow PR lub buildow lokalnych.
# Biezacy workflow CI pozostawia go pusty.
variable "BPP_BRANCH_TAG" {
default = ""
}
variable "TAG_LATEST" {
default = "true"
}
# R16: zstd compression przy pushu do rejestru (~20-30% mniejszy transfer
# pull/push niz gzip). Dotyczy TYLKO `type=registry` — lokalny `type=docker`
# zapisuje uncompressed do daemon storage. Override wartosci:
# COMPRESSION=gzip make build # stare zachowanie
# COMPRESSION_LEVEL=9 make build # wyzsza kompresja, wolniejszy push
# Docker Hub wspiera zstd od 2023; klienci z Docker 23+ pullna natywnie,
# starsi dostana gzip fallback (koszt po stronie rejestru).
variable "COMPRESSION" {
default = "zstd"
}
variable "COMPRESSION_LEVEL" {
default = "3"
}
# Build groups for different scenarios
#
# UWAGA: `testserver` celowo NIE nalezy do zadnej grupy. Grupa "default" to
# obrazy produkcyjne — buduje ja `make build-production` oraz
# `make build-branch` (bez nazw targetow, z PUSH=true, na Docker Build Cloud
# pod linux/amd64). `bpp_testserver:dev` jest obrazem wylacznie lokalnym, wiec
# w takim buildzie bylby czysta strata czasu i zasobow chmury.
#
# Lokalny obraz dev buduje sie przez nazwany target: `make build` woła
# `bake testserver` (patrz Makefile, sekcja "Docker build (buildx bake)").
group "default" {
targets = ["appserver", "workerserver",
"beatserver", "authserver", "denorm-queue"]
}
group "base-only" {
targets = ["base"]
}
group "app-services" {
targets = ["appserver", "workerserver", "beatserver", "authserver", "denorm-queue"]
}
# Base image - critical path, app services depend on this
target "base" {
dockerfile = "docker/bpp_base/Dockerfile"
context = "."
args = {
GIT_SHA = GIT_SHA
BUILD_CACHE_EPOCH = BUILD_CACHE_EPOCH
BPP_BUILD_FLAVOR = BPP_BUILD_FLAVOR
BPP_IMAGE_TAG = BPP_IMAGE_TAG
BPP_BRANCH_TAG = BPP_BRANCH_TAG
}
tags = TAG_LATEST == "true" ? [
"iplweb/bpp_base:${DOCKER_VERSION}",
"iplweb/bpp_base:latest"
] : [
"iplweb/bpp_base:${DOCKER_VERSION}"
]
# Cache jest celowo włączony. GIT_SHA unieważnia snapshot kodu na każdy
# commit, a BUILD_CACHE_EPOCH okresowo odświeża wcześniejsze warstwy pakietów.
platforms = [PLATFORM]
output = PUSH ? ["type=registry,compression=${COMPRESSION},compression-level=${COMPRESSION_LEVEL},force-compression=true"] : ["type=docker"]
}
# Lokalny obraz developerski — stage `testserver` z tego samego Dockerfile'a co
# `base`. To obraz, ktorym docker-compose.yml uruchamia WSZYSTKIE serwisy
# aplikacyjne (appserver/beatserver/workerserver/denorm-queue), czyli jedyny
# obraz, ktory developer faktycznie odpala lokalnie.
#
# Dlaczego w ogole tu jest (kiedys swiadomie go nie bylo): dopoki target nie
# istnial, `make build` odswiezal piec obrazow produkcyjnych i ani razu nie
# dotykal tego jednego, ktory realnie chodzi na maszynie. Obraz cichutko
# starzal sie w nieskonczonosc, a compose bind-mountuje swieze `./src` na jego
# stary `/opt/venv` — wiec kod z dzisiaj spotykal zaleznosci sprzed tygodnia
# (klasyczny objaw: ModuleNotFoundError na paczce dodanej do pyproject.toml
# juz po zbudowaniu obrazu). `make build` bez tego targetu dawal falszywe
# poczucie "mam swieze obrazy" — dzis `make build` buduje wlasnie ten obraz
# i tylko jego, bo tylko jego docker-compose.yml uruchamia.
#
# `output` jest zahardkodowany na type=docker i celowo IGNORUJE zmienna PUSH:
# ten obraz nie ma tagu w rejestrze i nigdy nie ma trafic na Docker Hub.
target "testserver" {
dockerfile = "docker/bpp_base/Dockerfile"
target = "testserver"
context = "."
args = {
GIT_SHA = GIT_SHA
BUILD_CACHE_EPOCH = BUILD_CACHE_EPOCH
BPP_BUILD_FLAVOR = BPP_BUILD_FLAVOR
BPP_IMAGE_TAG = BPP_IMAGE_TAG
BPP_BRANCH_TAG = BPP_BRANCH_TAG
}
# Tag musi sie zgadzac z `image:` w docker-compose.yml.
tags = ["bpp_testserver:dev"]
platforms = [PLATFORM]
output = ["type=docker"]
}
# Dependent images - wait for base to complete via contexts dependency
target "appserver" {
dockerfile = "docker/appserver/Dockerfile"
context = "."
args = {
BPP_BASE_TAG = DOCKER_VERSION
}
contexts = {
"iplweb/bpp_base:${DOCKER_VERSION}" = "target:base"
}
tags = TAG_LATEST == "true" ? [
"iplweb/bpp_appserver:${DOCKER_VERSION}",
"iplweb/bpp_appserver:latest"
] : [
"iplweb/bpp_appserver:${DOCKER_VERSION}"
]
platforms = [PLATFORM]
output = PUSH ? ["type=registry,compression=${COMPRESSION},compression-level=${COMPRESSION_LEVEL},force-compression=true"] : ["type=docker"]
}
target "workerserver" {
dockerfile = "docker/workerserver/Dockerfile"
context = "."
args = {
BPP_BASE_TAG = DOCKER_VERSION
}
contexts = {
"iplweb/bpp_base:${DOCKER_VERSION}" = "target:base"
}
tags = TAG_LATEST == "true" ? [
"iplweb/bpp_workerserver:${DOCKER_VERSION}",
"iplweb/bpp_workerserver:latest"
] : [
"iplweb/bpp_workerserver:${DOCKER_VERSION}"
]
platforms = [PLATFORM]
output = PUSH ? ["type=registry,compression=${COMPRESSION},compression-level=${COMPRESSION_LEVEL},force-compression=true"] : ["type=docker"]
}
target "beatserver" {
dockerfile = "docker/beatserver/Dockerfile"
context = "."
args = {
BPP_BASE_TAG = DOCKER_VERSION
}
contexts = {
"iplweb/bpp_base:${DOCKER_VERSION}" = "target:base"
}
tags = TAG_LATEST == "true" ? [
"iplweb/bpp_beatserver:${DOCKER_VERSION}",
"iplweb/bpp_beatserver:latest"
] : [
"iplweb/bpp_beatserver:${DOCKER_VERSION}"
]
platforms = [PLATFORM]
output = PUSH ? ["type=registry,compression=${COMPRESSION},compression-level=${COMPRESSION_LEVEL},force-compression=true"] : ["type=docker"]
}
target "authserver" {
dockerfile = "docker/authserver/Dockerfile"
context = "."
args = {
BPP_BASE_TAG = DOCKER_VERSION
}
contexts = {
"iplweb/bpp_base:${DOCKER_VERSION}" = "target:base"
}
tags = TAG_LATEST == "true" ? [
"iplweb/bpp_authserver:${DOCKER_VERSION}",
"iplweb/bpp_authserver:latest"
] : [
"iplweb/bpp_authserver:${DOCKER_VERSION}"
]
platforms = [PLATFORM]
output = PUSH ? ["type=registry,compression=${COMPRESSION},compression-level=${COMPRESSION_LEVEL},force-compression=true"] : ["type=docker"]
}
target "denorm-queue" {
dockerfile = "docker/denorm-queue/Dockerfile"
context = "."
args = {
BPP_BASE_TAG = DOCKER_VERSION
}
contexts = {
"iplweb/bpp_base:${DOCKER_VERSION}" = "target:base"
}
tags = TAG_LATEST == "true" ? [
"iplweb/bpp_denorm_queue:${DOCKER_VERSION}",
"iplweb/bpp_denorm_queue:latest"
] : [
"iplweb/bpp_denorm_queue:${DOCKER_VERSION}"
]
platforms = [PLATFORM]
output = PUSH ? ["type=registry,compression=${COMPRESSION},compression-level=${COMPRESSION_LEVEL},force-compression=true"] : ["type=docker"]
}