-
Notifications
You must be signed in to change notification settings - Fork 327
/
Makefile
374 lines (315 loc) · 13.9 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=$(GOPATH)/src/github.com/crunchydata/crunchy-containers
endif
# Default values if not already set
CCP_BASEOS ?= ubi8
BASE_IMAGE_OS ?= $(CCP_BASEOS)
CCP_IMAGE_PREFIX ?= crunchydata
CCP_PGVERSION ?= 15
CCP_PG_FULLVERSION ?= 15.2
CCP_PATRONI_VERSION ?= 2.1.7
CCP_BACKREST_VERSION ?= 2.41
CCP_VERSION ?= 5.3.1
CCP_POSTGIS_VERSION ?= 3.3
CCP_POSTGIS_FULL_VERSION ?= 3.3.2
CCP_PGADMIN_VERSION ?= 4.30
CCP_PGBOUNCER_VERSION ?= 1.18.0
CCP_IMAGE_TAG ?= $(CCP_BASEOS)-$(CCP_PG_FULLVERSION)-$(CCP_VERSION)
CCP_POSTGIS_IMAGE_TAG ?= $(CCP_BASEOS)-$(CCP_PG_FULLVERSION)-$(CCP_POSTGIS_VERSION)-$(CCP_VERSION)
PACKAGER ?= yum
# Valid values: buildah (default), docker
IMGBUILDER ?= buildah
# 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)
DOCKERBASEREGISTRY=registry.access.redhat.com/
# 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 ubi/rhel Dockerfile sets
ifeq ("$(CCP_BASEOS)", "ubi8")
DFSET=rhel
PACKAGER=microdnf
BASE_IMAGE_OS=ubi8-minimal
endif
ifeq ("$(CCP_BASEOS)", "centos8")
DFSET=centos
PACKAGER=dnf
DOCKERBASEREGISTRY=docker.io/centos:
endif
.PHONY: all license pgbackrest-images pg-independent-images pgimages
# list of image names, helpful in pushing
images = crunchy-postgres \
crunchy-upgrade \
crunchy-pgbackrest \
crunchy-pgbouncer \
crunchy-pgadmin4
# crunchy-pgbadger
# crunchy-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: pgbouncer pgadmin4
# pg-independent-images: pgbadger pgpool
# Build images that require a specific postgres version - ordered for potential concurrent benefits
pgimages: postgres postgres-gis upgrade
# Build images based on pgBackRest
pgbackrest-images: pgbackrest
#===========================================
# Targets generating pg-based images
#===========================================
pgadmin4: pgadmin4-img-$(IMGBUILDER)
pgbackrest: pgbackrest-pgimg-$(IMGBUILDER)
pgbadger: pgbadger-img-$(IMGBUILDER)
pgbouncer: pgbouncer-img-$(IMGBUILDER)
pgpool: pgpool-img-$(IMGBUILDER)
postgres: postgres-pgimg-$(IMGBUILDER)
postgres-gis: postgres-gis-pgimg-$(IMGBUILDER)
#===========================================
# Pattern-based image generation targets
#===========================================
$(CCPROOT)/build/%/Dockerfile:
$(error No Dockerfile found for $* naming pattern: [$@])
# ----- Base Image -----
ccbase-image: ccbase-image-$(IMGBUILDER)
ccbase-image-build: build-pgbackrest license $(CCPROOT)/build/base/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/base/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/crunchy-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 buildah push $(CCP_IMAGE_PREFIX)/crunchy-base:$(CCP_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/crunchy-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)/crunchy-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 buildah push $(CCP_IMAGE_PREFIX)/crunchy-base-ext:$(CCP_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/crunchy-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)/crunchy-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=crunchy-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 buildah push $(CCP_IMAGE_PREFIX)/crunchy-postgres:$(CCP_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/crunchy-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)/crunchy-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=crunchy-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 buildah push $(CCP_IMAGE_PREFIX)/crunchy-postgres-gis-base:$(CCP_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/crunchy-postgres-gis-base:$(CCP_IMAGE_TAG)
endif
# ----- Special case pg-based image (postgres-gis) -----
# Special case args: POSTGIS_LBL
postgres-gis-pgimg-build: postgres-gis-base-pgimg-build $(CCPROOT)/build/postgres-gis/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/postgres-gis/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/crunchy-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 POSTGIS_FULL_VER=$(CCP_POSTGIS_FULL_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 buildah push $(CCP_IMAGE_PREFIX)/crunchy-postgres-gis:$(CCP_POSTGIS_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/crunchy-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: ccbase-image build-pgbackrest $(CCPROOT)/build/pgbackrest/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/pgbackrest/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/crunchy-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 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 buildah push $(CCP_IMAGE_PREFIX)/crunchy-pgbackrest:$(CCP_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/crunchy-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)/crunchy-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 find $(CCPROOT)/conf -type f -name "crunchypg*.repo" | \
grep -o [1-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 buildah push $(CCP_IMAGE_PREFIX)/crunchy-upgrade:$(CCP_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/crunchy-upgrade:$(CCP_IMAGE_TAG)
endif
upgrade-img-docker: upgrade-img-build
# Special case args: CCP_PGADMIN_VERSION
pgadmin4-img-build: ccbase-image $(CCPROOT)/build/pgadmin4/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/pgadmin4/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/crunchy-pgadmin4:$(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 PGADMIN_VER=$(CCP_PGADMIN_VERSION) \
--build-arg PACKAGER=$(PACKAGER) \
$(CCPROOT)
pgadmin4-img-buildah: pgadmin4-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 buildah push $(CCP_IMAGE_PREFIX)/crunchy-pgadmin4:$(CCP_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/crunchy-pgadmin4:$(CCP_IMAGE_TAG)
endif
pgadmin4-img-docker: pgadmin-img-build
# Special case args: CCP_PGBOUNCER_VERSION
pgbouncer-img-build: ccbase-image $(CCPROOT)/build/pgbouncer/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/pgbouncer/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/crunchy-pgbouncer:$(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 PGBOUNCER_VER=$(CCP_PGBOUNCER_VERSION) \
--build-arg DFSET=$(DFSET) \
--build-arg PACKAGER=$(PACKAGER) \
$(CCPROOT)
pgbouncer-img-buildah: pgbouncer-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 buildah push $(CCP_IMAGE_PREFIX)/crunchy-pgbouncer:$(CCP_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/crunchy-pgbouncer:$(CCP_IMAGE_TAG)
endif
pgbouncer-img-docker: pgbouncer-img-build
# ----- Extra images -----
%-img-build: ccbase-image $(CCPROOT)/build/%/Dockerfile
$(IMGCMDSTEM) \
-f $(CCPROOT)/build/$*/Dockerfile \
-t $(CCP_IMAGE_PREFIX)/crunchy-$*:$(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) \
$(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 buildah push $(CCP_IMAGE_PREFIX)/crunchy-$*:$(CCP_IMAGE_TAG) docker-daemon:$(CCP_IMAGE_PREFIX)/crunchy-$*:$(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)/crunchy-postgres-gis:$(CCP_POSTGIS_IMAGE_TAG)
push-%:
$(IMG_PUSHER_PULLER) push $(CCP_IMAGE_PREFIX)/$*:$(CCP_IMAGE_TAG)
-include Makefile.build