-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
374 lines (323 loc) · 14 KB
/
Makefile
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
ifndef CCPROOT
export CCPROOT=$(shell pwd)
endif
# Default values if not already set
CCP_BASEOS ?= debian
BASE_IMAGE_OS ?= $(CCP_BASEOS)
CCP_PGVERSION ?= 14
CCP_PG_FULLVERSION ?= 14.2
CCP_PATRONI_VERSION ?= 2.1.3
CCP_BACKREST_VERSION ?= 2.36
CCP_VERSION ?= 2.1.1
CCP_POSTGIS_VERSION ?= 3.1
PACKAGER ?= apt
DOCKERBASEREGISTRY ?= docker.io/
CCP_IMAGE_TAG ?= $(CCP_BASEOS)-$(CCP_PG_FULLVERSION)-$(CCP_VERSION)
CCP_POSTGIS_IMAGE_TAG ?= $(CCP_BASEOS)-$(CCP_PG_FULLVERSION)-$(CCP_POSTGIS_VERSION)-$(CCP_VERSION)
CCP_IMAGE_PREFIX ?= radondb
test:
@echo $(CCP_POSTGIS_IMAGE_TAG)
# Valid values: buildah (default), docker
IMGBUILDER ?= docker
# Determines whether or not images should be pushed to the local docker daemon when building with
# a tool other than docker (e.g. when building with buildah)
IMG_PUSH_TO_DOCKER_DAEMON ?= true
# The utility to use when pushing/pulling to and from an image repo (e.g. docker or buildah)
IMG_PUSHER_PULLER ?= docker
# Defines the sudo command that should be prepended to various build commands when rootless builds are
# not enabled
IMGCMDSUDO=
ifneq ("$(IMG_ROOTLESS_BUILD)", "true")
IMGCMDSUDO=sudo --preserve-env
endif
IMGCMDSTEM=$(IMGCMDSUDO) buildah bud --layers $(SQUASH)
DFSET=$(CCP_BASEOS)
# Default the buildah format to docker to ensure it is possible to pull the images from a docker
# repository using docker (otherwise the images may not be recognized)
export BUILDAH_FORMAT ?= docker
# Allows simplification of IMGBUILDER switching
ifeq ("$(IMGBUILDER)","docker")
IMGCMDSTEM=docker build
endif
# Allows consolidation of debian Dockerfile sets
ifeq ("$(CCP_BASEOS)", "debian")
DFSET=debian
PACKAGER=apt
BASE_IMAGE_OS=bullseye-slim
endif
.PHONY: all license pgbackrest-images pg-independent-images pgimages
# list of image names, helpful in pushing
images = radondb-postgres \
radondb-postgres-ha \
radondb-upgrade \
radondb-pgbackrest \
radondb-pgbackrest-repo \
radondb-pgadmin4 \
radondb-pgbadger \
radondb-pgbouncer \
radondb-pgpool
# Default target
all: pgimages pg-independent-images pgbackrest-images
# Build images that either don't have a PG dependency or using the latest PG version is all that is needed
pg-independent-images: pgbadger pgbouncer pgpool
# pg-independent-images: pgbadger pgpool
# Build images that require a specific postgres version - ordered for potential concurrent benefits
pgimages: postgres postgres-ha postgres-gis postgres-gis-ha upgrade
# Build images based on pgBackRest
pgbackrest-images: pgbackrest pgbackrest-repo
#===========================================
# Targets generating pg-based images
#===========================================
pgadmin4: pgadmin4-img-$(IMGBUILDER)
pgbackrest: pgbackrest-pgimg-$(IMGBUILDER)
pgbackrest-repo: pgbackrest-repo-pgimg-$(IMGBUILDER)
pgbadger: pgbadger-img-$(IMGBUILDER)
pgbouncer: pgbouncer-img-$(IMGBUILDER)
pgpool: pgpool-img-$(IMGBUILDER)
postgres: postgres-pgimg-$(IMGBUILDER)
postgres-ha: postgres-ha-pgimg-$(IMGBUILDER)
postgres-gis: postgres-gis-pgimg-$(IMGBUILDER)
postgres-gis-ha: postgres-gis-ha-pgimg-$(IMGBUILDER)
#===========================================
# Pattern-based image generation targets
#===========================================
$(CCPROOT)/build/%/Dockerfile:
$(error No Dockerfile found for $* naming pattern: [$@])
# ----- Base Image -----
ccbase-image: ccbase-image-$(IMGBUILDER) pg-base-image-build
pg-base-image-build: $(CCPROOT)/$(CCP_PGVERSION)/bullseye/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/$(CCP_PGVERSION)/bullseye/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/radondb-pg-base:$(CCP_IMAGE_TAG) \
--build-arg PREFIX=$(CCP_IMAGE_PREFIX) \
--build-arg BASEOS=$(CCP_BASEOS) \
--build-arg BASEVER=$(CCP_VERSION) \
--build-arg PG_FULL=$(CCP_PG_FULLVERSION) \
$(CCPROOT)
ccbase-image-build: $(CCPROOT)/build/base/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/base/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/radondb-base:$(CCP_IMAGE_TAG) \
--build-arg BASEOS=$(CCP_BASEOS) \
--build-arg RELVER=$(CCP_VERSION) \
--build-arg DFSET=$(DFSET) \
--build-arg PACKAGER=$(PACKAGER) \
--build-arg DOCKERBASEREGISTRY=$(DOCKERBASEREGISTRY) \
--build-arg BASE_IMAGE_OS=$(BASE_IMAGE_OS) \
--build-arg PG_LBL=${subst .,,$(CCP_PGVERSION)} \
$(CCPROOT)
ccbase-image-buildah: ccbase-image-build ;
# only push to docker daemon if variable IMG_PUSH_TO_DOCKER_DAEMON is set to "true"
ifeq ("$(IMG_PUSH_TO_DOCKER_DAEMON)", "true")
sudo --preserve-env docker push $(CCP_IMAGE_PREFIX)/radondb-base:$(CCP_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/radondb-base:$(CCP_IMAGE_TAG)
endif
ccbase-image-docker: ccbase-image-build
# ----- Base Image Ext -----
ccbase-ext-image-build: ccbase-image $(CCPROOT)/build/base-ext/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/base-ext/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/radondb-base-ext:$(CCP_IMAGE_TAG) \
--build-arg BASEOS=$(CCP_BASEOS) \
--build-arg BASEVER=$(CCP_VERSION) \
--build-arg PACKAGER=$(PACKAGER) \
--build-arg PREFIX=$(CCP_IMAGE_PREFIX) \
--build-arg PG_FULL=$(CCP_PG_FULLVERSION) \
$(CCPROOT)
ccbase-ext-image-buildah: ccbase-ext-image-build ;
# only push to docker daemon if variable IMG_PUSH_TO_DOCKER_DAEMON is set to "true"
ifeq ("$(IMG_PUSH_TO_DOCKER_DAEMON)", "true")
sudo --preserve-env docker push $(CCP_IMAGE_PREFIX)/radondb-base-ext:$(CCP_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/radondb-base-ext:$(CCP_IMAGE_TAG)
endif
ccbase-ext-image-docker: ccbase-ext-image-build
# ----- Special case pg-based image (postgres) -----
# Special case args: BACKREST_VER
postgres-pgimg-build: ccbase-image $(CCPROOT)/build/postgres/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/postgres/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/radondb-postgres:$(CCP_IMAGE_TAG) \
--build-arg BASEOS=$(CCP_BASEOS) \
--build-arg BASEVER=$(CCP_VERSION) \
--build-arg PG_FULL=$(CCP_PG_FULLVERSION) \
--build-arg PG_LBL=${subst .,,$(CCP_PGVERSION)} \
--build-arg PG_MAJOR=$(CCP_PGVERSION) \
--build-arg PREFIX=$(CCP_IMAGE_PREFIX) \
--build-arg BACKREST_VER=$(CCP_BACKREST_VERSION) \
--build-arg DFSET=$(DFSET) \
--build-arg PACKAGER=$(PACKAGER) \
--build-arg BASE_IMAGE_NAME=radondb-base \
--build-arg PATRONI_VER=$(CCP_PATRONI_VERSION) \
$(CCPROOT)
postgres-pgimg-buildah: postgres-pgimg-build ;
# only push to docker daemon if variable IMG_PUSH_TO_DOCKER_DAEMON is set to "true"
ifeq ("$(IMG_PUSH_TO_DOCKER_DAEMON)", "true")
sudo --preserve-env docker push $(CCP_IMAGE_PREFIX)/radondb-postgres:$(CCP_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/radondb-postgres:$(CCP_IMAGE_TAG)
endif
postgres-pgimg-docker: postgres-pgimg-build
# ----- Special case pg-based image (postgres-gis-base) -----
# Used as the base for the postgres-gis image.
postgres-gis-base-pgimg-build: ccbase-ext-image-build $(CCPROOT)/build/postgres/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/postgres/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/radondb-postgres-gis-base:$(CCP_IMAGE_TAG) \
--build-arg BASEOS=$(CCP_BASEOS) \
--build-arg BASEVER=$(CCP_VERSION) \
--build-arg PG_FULL=$(CCP_PG_FULLVERSION) \
--build-arg PG_LBL=${subst .,,$(CCP_PGVERSION)} \
--build-arg PG_MAJOR=$(CCP_PGVERSION) \
--build-arg PREFIX=$(CCP_IMAGE_PREFIX) \
--build-arg BACKREST_VER=$(CCP_BACKREST_VERSION) \
--build-arg DFSET=$(DFSET) \
--build-arg PACKAGER=$(PACKAGER) \
--build-arg PATRONI_VER=$(CCP_PATRONI_VERSION) \
--build-arg BASE_IMAGE_NAME=radondb-base-ext \
$(CCPROOT)
postgres-gis-base-pgimg-buildah: postgres-gis-base-pgimg-build ;
# only push to docker daemon if variable IMG_PUSH_TO_DOCKER_DAEMON is set to "true"
ifeq ("$(IMG_PUSH_TO_DOCKER_DAEMON)", "true")
sudo --preserve-env docker push $(CCP_IMAGE_PREFIX)/radondb-postgres-gis-base:$(CCP_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/radondb-postgres-gis-base:$(CCP_IMAGE_TAG)
endif
# ----- Special case pg-based image (postgres-gis) -----
# Special case args: POSTGIS_LBL
postgres-gis-pgimg-build: $(CCPROOT)/build/postgres-gis/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/postgres-gis/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/radondb-postgres-gis:$(CCP_POSTGIS_IMAGE_TAG) \
--build-arg BASEOS=$(CCP_BASEOS) \
--build-arg BASEVER=$(CCP_VERSION) \
--build-arg PG_FULL=$(CCP_PG_FULLVERSION) \
--build-arg PG_MAJOR=$(CCP_PGVERSION) \
--build-arg PREFIX=$(CCP_IMAGE_PREFIX) \
--build-arg POSTGIS_LBL=$(subst .,,$(CCP_POSTGIS_VERSION)) \
--build-arg DFSET=$(DFSET) \
--build-arg PACKAGER=$(PACKAGER) \
$(CCPROOT)
postgres-gis-pgimg-buildah: postgres-gis-pgimg-build ;
# only push to docker daemon if variable IMG_PUSH_TO_DOCKER_DAEMON is set to "true"
ifeq ("$(IMG_PUSH_TO_DOCKER_DAEMON)", "true")
sudo --preserve-env docker push $(CCP_IMAGE_PREFIX)/radondb-postgres-gis:$(CCP_POSTGIS_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/radondb-postgres-gis:$(CCP_POSTGIS_IMAGE_TAG)
endif
postgres-gis-pgimg-docker: postgres-gis-pgimg-build
# ----- Special case image (pgbackrest) -----
# build the needed binary
build-pgbackrest:
go build -o bin/pgbackrest/pgbackrest ./cmd/pgbackrest
# Special case args: BACKREST_VER
pgbackrest-pgimg-build: build-pgbackrest $(CCPROOT)/build/pgbackrest/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/pgbackrest/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/radondb-pgbackrest:$(CCP_IMAGE_TAG) \
--build-arg BASEOS=$(CCP_BASEOS) \
--build-arg BASEVER=$(CCP_VERSION) \
--build-arg PG_FULL=$(CCP_PG_FULLVERSION) \
--build-arg PG_MAJOR=$(CCP_PGVERSION) \
--build-arg BASE_IMAGE_OS=$(BASE_IMAGE_OS) \
--build-arg PREFIX=$(CCP_IMAGE_PREFIX) \
--build-arg BACKREST_VER=$(CCP_BACKREST_VERSION) \
--build-arg PACKAGER=$(PACKAGER) \
$(CCPROOT)
pgbackrest-pgimg-buildah: pgbackrest-pgimg-build ;
# only push to docker daemon if variable IMG_PUSH_TO_DOCKER_DAEMON is set to "true"
ifeq ("$(IMG_PUSH_TO_DOCKER_DAEMON)", "true")
sudo --preserve-env docker push $(CCP_IMAGE_PREFIX)/radondb-pgbackrest:$(CCP_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/radondb-pgbackrest:$(CCP_IMAGE_TAG)
endif
pgbackrest-pgimg-docker: pgbackrest-pgimg-build
# ----- Special case image (upgrade) -----
# Special case args: UPGRADE_PG_VERSIONS (defines all versions of PG that will be installed)
upgrade-img-build: ccbase-image $(CCPROOT)/build/upgrade/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/upgrade/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/radondb-upgrade:$(CCP_IMAGE_TAG) \
--build-arg BASEOS=$(CCP_BASEOS) \
--build-arg BASEVER=$(CCP_VERSION) \
--build-arg PG_FULL=$(CCP_PG_FULLVERSION) \
--build-arg PG_MAJOR=$(CCP_PGVERSION) \
--build-arg PREFIX=$(CCP_IMAGE_PREFIX) \
--build-arg DFSET=$(DFSET) \
--build-arg PACKAGER=$(PACKAGER) \
--build-arg UPGRADE_PG_VERSIONS="$(shell ls|grep "^[0-9][0-9]$")" \
$(CCPROOT)
upgrade-img-buildah: upgrade-img-build ;
# only push to docker daemon if variable IMG_PUSH_TO_DOCKER_DAEMON is set to "true"
ifeq ("$(IMG_PUSH_TO_DOCKER_DAEMON)", "true")
sudo --preserve-env docker push $(CCP_IMAGE_PREFIX)/radondb-upgrade:$(CCP_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/radondb-upgrade:$(CCP_IMAGE_TAG)
endif
upgrade-img-docker: upgrade-img-build
# ----- Extra images -----
%-img-build: $(CCPROOT)/build/%/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/$*/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/radondb-$*:$(CCP_IMAGE_TAG) \
--build-arg BASEOS=$(CCP_BASEOS) \
--build-arg BASEVER=$(CCP_VERSION) \
--build-arg PG_FULL=$(CCP_PG_FULLVERSION) \
--build-arg PG_MAJOR=$(CCP_PGVERSION) \
--build-arg PREFIX=$(CCP_IMAGE_PREFIX) \
--build-arg DFSET=$(DFSET) \
--build-arg BASE_IMAGE_OS=$(BASE_IMAGE_OS) \
--build-arg PACKAGER=$(PACKAGER) \
$(CCPROOT)
%-img-buildah: %-img-build ;
# only push to docker daemon if variable IMG_PUSH_TO_DOCKER_DAEMON is set to "true"
ifeq ("$(IMG_PUSH_TO_DOCKER_DAEMON)", "true")
sudo --preserve-env docker push $(CCP_IMAGE_PREFIX)/radondb-$*:$(CCP_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/radondb-$*:$(CCP_IMAGE_TAG)
endif
%-img-docker: %-img-build ;
# ----- Upgrade Images -----
upgrade: upgrade-$(CCP_PGVERSION)
upgrade-%: upgrade-img-$(IMGBUILDER) ;
upgrade-9.5: # Do nothing but log to avoid erroring out on missing Dockerfile
$(info Upgrade build skipped for 9.5)
#=================
# Utility targets
#=================
setup:
$(CCPROOT)/bin/install-deps.sh
docbuild:
cd $(CCPROOT) && ./generate-docs.sh
license:
./bin/license_aggregator.sh
push: push-gis $(images:%=push-%) ;
push-gis:
$(IMG_PUSHER_PULLER) push $(CCP_IMAGE_PREFIX)/radondb-postgres-gis:$(CCP_POSTGIS_IMAGE_TAG)
push-%:
$(IMG_PUSHER_PULLER) push $(CCP_IMAGE_PREFIX)/$*:$(CCP_IMAGE_TAG)
-include Makefile.build
postgres-ha-pgimg-docker: postgres-ha-pgimg-build
postgres-ha-pgimg-build: postgres-pgimg-build $(CCPROOT)/build/postgres-ha/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/postgres-ha/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/radondb-postgres-ha:$(CCP_IMAGE_TAG) \
--build-arg BASEOS=$(CCP_BASEOS) \
--build-arg BASEVER=$(CCP_VERSION) \
--build-arg PG_FULL=$(CCP_PG_FULLVERSION) \
--build-arg PG_MAJOR=$(CCP_PGVERSION) \
--build-arg PREFIX=$(CCP_IMAGE_PREFIX) \
--build-arg PATRONI_VER=$(CCP_PATRONI_VERSION) \
--build-arg DFSET=$(DFSET) \
--build-arg PACKAGER=$(PACKAGER) \
$(CCPROOT)
postgres-gis-ha-pgimg-docker: postgres-gis-ha-pgimg-build
postgres-gis-ha-pgimg-build: postgres-gis-pgimg-build $(CCPROOT)/build/postgres-gis-ha/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/postgres-gis-ha/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/radondb-postgres-gis-ha:$(CCP_POSTGIS_IMAGE_TAG) \
--build-arg BASEOS=$(CCP_BASEOS) \
--build-arg BASEVER=$(CCP_VERSION) \
--build-arg PG_FULL=$(CCP_PG_FULLVERSION) \
--build-arg PG_MAJOR=$(CCP_PGVERSION) \
--build-arg PATRONI_VER=$(CCP_PATRONI_VERSION) \
--build-arg POSTGIS_VER=$(CCP_POSTGIS_VERSION) \
--build-arg PREFIX=$(CCP_IMAGE_PREFIX) \
--build-arg DFSET=$(DFSET) \
--build-arg PACKAGER=$(PACKAGER) \
$(CCPROOT)
pgbackrest-repo-pgimg-docker: pgbackrest-repo-pgimg-build
pgbackrest-repo-pgimg-build: ccbase-image build-pgbackrest pgbackrest $(CCPROOT)/build/pgbackrest-repo/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/pgbackrest-repo/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/radondb-pgbackrest-repo:$(CCP_IMAGE_TAG) \
--build-arg BASEOS=$(CCP_BASEOS) \
--build-arg BASEVER=$(CCP_VERSION) \
--build-arg PG_FULL=$(CCP_PG_FULLVERSION) \
--build-arg PREFIX=$(CCP_IMAGE_PREFIX) \
$(CCPROOT)