1+ PGO_IMAGE_NAME ?= postgres-operator
2+ PGO_IMAGE_MAINTAINER ?= Crunchy Data
3+ PGO_IMAGE_SUMMARY ?= Crunchy PostgreSQL Operator
4+ PGO_IMAGE_DESCRIPTION ?= $(PGO_IMAGE_SUMMARY )
5+ PGO_IMAGE_URL ?= https://www.crunchydata.com/products/crunchy-postgresql-for-kubernetes
6+ PGO_IMAGE_PREFIX ?= localhost
7+
8+ CRUNCHY_POSTGRES_EXPORTER_IMAGE_NAME ?= crunchy-postgres-exporter
9+ CRUNCHY_POSTGRES_EXPORTER_MAINTAINER ?= $(PGO_IMAGE_MAINTAINER )
10+ CRUNCHY_POSTGRES_EXPORTER_SUMMARY ?= Metrics exporter for PostgreSQL
11+ CRUNCHY_POSTGRES_EXPORTER_DESCRIPTION ?= \
12+ When run with the crunchy-postgres family of containers, crunchy-postgres-exporter reads the PostgreSQL data directory \
13+ and has a SQL interface to a database to allow for metrics collection.
14+ CRUNCHY_POSTGRES_EXPORTER_URL ?= https://www.crunchydata.com/products/crunchy-postgresql-for-kubernetes
15+ CRUNCHY_POSTGRES_EXPORTER_IMAGE_PREFIX ?= $(PGO_IMAGE_PREFIX )
16+ CRUNCHY_POSTGRES_EXPORTER_PG_VERSION ?= 14
17+ CRUNCHY_POSTGRES_EXPORTER_PG_FULL_VERSION ?= 14.6
18+
19+ PGMONITOR_DIR ?= hack/tools/pgmonitor
20+ PGMONITOR_VERSION ?= 'v4.8.0'
21+ POSTGRES_EXPORTER_VERSION ?= 0.10.1
22+ POSTGRES_EXPORTER_URL ?= https://github.com/prometheus-community/postgres_exporter/releases/download/v${POSTGRES_EXPORTER_VERSION}/postgres_exporter-${POSTGRES_EXPORTER_VERSION}.linux-amd64.tar.gz
123
2- # Default values if not already set
3- PGOROOT ?= $(CURDIR )
4- PGO_BASEOS ?= ubi8
5- PGO_IMAGE_PREFIX ?= crunchydata
6- PGO_IMAGE_TAG ?= $(PGO_BASEOS ) -$(PGO_VERSION )
7- PGO_VERSION ?= $(shell git describe --tags)
8- PGO_PG_VERSION ?= 14
9- PGO_PG_FULLVERSION ?= 14.6
10- PGO_KUBE_CLIENT ?= kubectl
11-
12- # Valid values: buildah (default), docker
13- IMGBUILDER ?= buildah
14- # Determines whether or not rootless builds are enabled
15- IMG_ROOTLESS_BUILD ?= false
16- # Defines the sudo command that should be prepended to various build commands when rootless builds are
17- # not enabled
18- IMGCMDSUDO =
19- ifneq ("$(IMG_ROOTLESS_BUILD ) ", "true")
20- IMGCMDSUDO=sudo --preserve-env
21- endif
22- IMGCMDSTEM =$(IMGCMDSUDO ) buildah bud --layers $(SQUASH )
2324# Buildah's "build" used to be "bud". Use the alias to be compatible for a while.
2425BUILDAH_BUILD ?= buildah bud
2526
26- # Default the buildah format to docker to ensure it is possible to pull the images from a docker
27- # repository using docker (otherwise the images may not be recognized)
28- export BUILDAH_FORMAT ?= docker
29-
30- # Allows simplification of IMGBUILDER switching
31- ifeq ("$(IMGBUILDER ) ","docker")
32- IMGCMDSTEM =docker build
33- endif
34-
35- # set the proper packager, registry and base image based on the PGO_BASEOS configured
36- DOCKERBASEREGISTRY =
37- BASE_IMAGE_OS =
38- ifeq ("$(PGO_BASEOS ) ", "ubi8")
39- BASE_IMAGE_OS =ubi8-minimal
40- DOCKERBASEREGISTRY =registry.access.redhat.com/
41- PACKAGER =microdnf
42- endif
43-
4427DEBUG_BUILD ?= false
4528GO ?= go
4629GO_BUILD = $(GO_CMD ) build -trimpath
@@ -78,8 +61,19 @@ all: build-crunchy-postgres-exporter-image
7861
7962.PHONY : setup
8063setup : # # Run Setup needed to build images
81- PGOROOT=' $(PGOROOT)' ./bin/get-deps.sh
82- ./bin/check-deps.sh
64+ setup : get-pgmonitor
65+ setup : get-postgres-exporter
66+
67+ .PHONY : get-pgmonitor
68+ get-pgmonitor :
69+ git -C ' $(dir $(PGMONITOR_DIR))' clone https://github.com/CrunchyData/pgmonitor.git || git -C ' $(PGMONITOR_DIR)' fetch origin
70+ @git -C ' $(PGMONITOR_DIR)' checkout ' $(PGMONITOR_VERSION)'
71+ @git -C ' $(PGMONITOR_DIR)' config pull.ff only
72+
73+ .PHONY : get-postgres-exporter
74+ get-postgres-exporter :
75+ [ ! -e hack/tools/postgres_exporter.tar.gz ] || (rm hack/tools/postgres_exporter.tar.gz && echo " Deleting old exporter" )
76+ wget -O hack/tools/postgres_exporter.tar.gz ' $(POSTGRES_EXPORTER_URL)'
8377
8478.PHONY : clean
8579clean : # # Clean resources
@@ -92,7 +86,8 @@ clean: clean-deprecated
9286[ ! -f hack/tools/setup-envtest ] || hack/tools/setup-envtest --bin-dir=hack/tools/envtest cleanup
9387[ ! -f hack/tools/setup-envtest ] || rm hack/tools/setup-envtest
9488[ ! -d hack/tools/envtest ] || rm -r hack/tools/envtest
95- [ ! -n " $$ (ls hack/tools)" ] || rm hack/tools/*
89+ [ ! -d hack/tools/pgmonitor ] || rm -rf hack/tools/pgmonitor
90+ [ ! -n " $$ (ls hack/tools)" ] || rm -r hack/tools/*
9691[ ! -d hack/.kube ] || rm -r hack/.kube
9792
9893.PHONY : clean-deprecated
@@ -113,40 +108,40 @@ clean-deprecated: ## Clean deprecated resources
113108# #@ Deployment
114109.PHONY : createnamespaces
115110createnamespaces : # # Create operator and target namespaces
116- $( PGO_KUBE_CLIENT ) apply -k ./config/namespace
111+ kubectl apply -k ./config/namespace
117112
118113.PHONY : deletenamespaces
119114deletenamespaces : # # Delete operator and target namespaces
120- $( PGO_KUBE_CLIENT ) delete -k ./config/namespace
115+ kubectl delete -k ./config/namespace
121116
122117.PHONY : install
123118install : # # Install the postgrescluster CRD
124- $( PGO_KUBE_CLIENT ) apply --server-side -k ./config/crd
119+ kubectl apply --server-side -k ./config/crd
125120
126121.PHONY : uninstall
127122uninstall : # # Delete the postgrescluster CRD
128- $( PGO_KUBE_CLIENT ) delete -k ./config/crd
123+ kubectl delete -k ./config/crd
129124
130125.PHONY : deploy
131126deploy : # # Deploy the PostgreSQL Operator (enables the postgrescluster controller)
132- $( PGO_KUBE_CLIENT ) apply --server-side -k ./config/default
127+ kubectl apply --server-side -k ./config/default
133128
134129.PHONY : undeploy
135130undeploy : # # Undeploy the PostgreSQL Operator
136- $( PGO_KUBE_CLIENT ) delete -k ./config/default
131+ kubectl delete -k ./config/default
137132
138133.PHONY : deploy-dev
139134deploy-dev : # # Deploy the PostgreSQL Operator locally
140135deploy-dev : build-postgres-operator
141136deploy-dev : createnamespaces
142- $( PGO_KUBE_CLIENT ) apply --server-side -k ./config/dev
137+ kubectl apply --server-side -k ./config/dev
143138hack/create-kubeconfig.sh postgres-operator pgo
144139env \
145140CRUNCHY_DEBUG=true \
146141CHECK_FOR_UPGRADES=' $(if $(CHECK_FOR_UPGRADES),$(CHECK_FOR_UPGRADES),false)' \
147142KUBECONFIG=hack/.kube/postgres-operator/pgo \
148143PGO_NAMESPACE=' postgres-operator' \
149- $(shell $( PGO_KUBE_CLIENT ) kustomize ./config/dev | \
144+ $(shell kubectl kustomize ./config/dev | \
150145sed -ne ' /^kind: Deployment/,/^---/ { \
151146/RELATED_IMAGE_/ { N; s,.* \( RELATED_[^[:space:]]* \) .* value:[[:space:]]* \( [^[:space:]]* \) ,\1 = " \2" ,; p; }; \
152147}' ) \
@@ -160,52 +155,81 @@ build-postgres-operator: ## Build the postgres-operator binary
160155-o bin/postgres-operator ./cmd/postgres-operator
161156
162157# #@ Build - Images
163- .PHONY : build-pgo-base-image
164- build-pgo-base-image : # # Build the pgo-base
165- build-pgo-base-image : licenses
166- build-pgo-base-image : $(PGOROOT ) /build/pgo-base/Dockerfile
167- $(IMGCMDSTEM ) \
168- -f $(PGOROOT ) /build/pgo-base/Dockerfile \
169- -t $(PGO_IMAGE_PREFIX ) /pgo-base:$(PGO_IMAGE_TAG ) \
170- --build-arg BASE_IMAGE_OS=$(BASE_IMAGE_OS ) \
171- --build-arg BASEOS=$(PGO_BASEOS ) \
172- --build-arg RELVER=$(PGO_VERSION ) \
173- --build-arg DOCKERBASEREGISTRY=$(DOCKERBASEREGISTRY ) \
174- --build-arg PACKAGER=$(PACKAGER ) \
175- --build-arg PG_FULL=$(PGO_PG_FULLVERSION ) \
176- --build-arg PGVERSION=$(PGO_PG_VERSION ) \
177- $(PGOROOT )
178-
179158.PHONY : build-crunchy-postgres-exporter-image
180159build-crunchy-postgres-exporter-image : # # Build the crunchy-postgres-exporter image
181- build-crunchy-postgres-exporter-image : build-pgo-base-image
182- build-crunchy-postgres-exporter-image : $(PGOROOT ) /build/crunchy-postgres-exporter/Dockerfile
183- $(IMGCMDSTEM ) \
184- -f $(PGOROOT ) /build/crunchy-postgres-exporter/Dockerfile \
185- -t $(PGO_IMAGE_PREFIX ) /crunchy-postgres-exporter:$(PGO_IMAGE_TAG ) \
186- --build-arg BASEOS=$(PGO_BASEOS ) \
187- --build-arg BASEVER=$(PGO_VERSION ) \
188- --build-arg PACKAGER=$(PACKAGER ) \
189- --build-arg PGVERSION=$(PGO_PG_VERSION ) \
190- --build-arg PREFIX=$(PGO_IMAGE_PREFIX ) \
191- $(PGOROOT )
160+ build-crunchy-postgres-exporter-image : CRUNCHY_POSTGRES_EXPORTER_IMAGE_REVISION := $(shell git rev-parse HEAD)
161+ build-crunchy-postgres-exporter-image : CRUNCHY_POSTGRES_EXPORTER_IMAGE_TIMESTAMP := $(shell date -u +% FT% TZ)
162+ build-crunchy-postgres-exporter-image : build/crunchy-postgres-exporter/Dockerfile
163+ $(if $(shell (echo 'buildah version 1.24'; $(word 1,$(BUILDAH_BUILD ) ) --version) | sort -Vc 2>&1) , \
164+ $(warning WARNING: old buildah does not invalidate its cache for changed labels: \
165+ https://github.com/containers/buildah/issues/3517))
166+ $(if $(IMAGE_TAG ) ,,$(error missing IMAGE_TAG) )
167+ $(BUILDAH_BUILD ) \
168+ --tag $(BUILDAH_TRANSPORT )$(CRUNCHY_POSTGRES_EXPORTER_IMAGE_PREFIX ) /$(CRUNCHY_POSTGRES_EXPORTER_IMAGE_NAME ) :$(IMAGE_TAG ) \
169+ --build-arg PGVERSION=$(CRUNCHY_POSTGRES_EXPORTER_PG_VERSION ) \
170+ --label name=' $(CRUNCHY_POSTGRES_EXPORTER_IMAGE_NAME)' \
171+ --label build-date=' $(CRUNCHY_POSTGRES_EXPORTER_IMAGE_TIMESTAMP)' \
172+ --label description=' $(CRUNCHY_POSTGRES_EXPORTER_DESCRIPTION)' \
173+ --label maintainer=' $(CRUNCHY_POSTGRES_EXPORTER_MAINTAINER)' \
174+ --label summary=' $(CRUNCHY_POSTGRES_EXPORTER_SUMMARY)' \
175+ --label url=' $(CRUNCHY_POSTGRES_EXPORTER_URL)' \
176+ --label vcs-ref=' $(CRUNCHY_POSTGRES_EXPORTER_IMAGE_REVISION)' \
177+ --label vendor=' $(CRUNCHY_POSTGRES_EXPORTER_MAINTAINER)' \
178+ --label postgres.version.major=' $(CRUNCHY_POSTGRES_EXPORTER_PG_VERSION)' \
179+ --label postgres.version=' $(CRUNCHY_POSTGRES_EXPORTER_PG_FULL_VERSION)' \
180+ --label io.k8s.display-name=' $(CRUNCHY_POSTGRES_EXPORTER_IMAGE_NAME)' \
181+ --label io.k8s.description=' $(CRUNCHY_POSTGRES_EXPORTER_DESCRIPTION)' \
182+ --label io.openshift.tags=" postgresql,postgres,monitoring,database,crunchy" \
183+ --annotation org.opencontainers.image.authors=' $(CRUNCHY_POSTGRES_EXPORTER_MAINTAINER)' \
184+ --annotation org.opencontainers.image.vendor=' $(CRUNCHY_POSTGRES_EXPORTER_MAINTAINER)' \
185+ --annotation org.opencontainers.image.created=' $(CRUNCHY_POSTGRES_EXPORTER_IMAGE_TIMESTAMP)' \
186+ --annotation org.opencontainers.image.description=' $(CRUNCHY_POSTGRES_EXPORTER_DESCRIPTION)' \
187+ --annotation org.opencontainers.image.revision=' $(CRUNCHY_POSTGRES_EXPORTER_IMAGE_REVISION)' \
188+ --annotation org.opencontainers.image.title=' $(CRUNCHY_POSTGRES_EXPORTER_SUMMARY)' \
189+ --annotation org.opencontainers.image.url=' $(CRUNCHY_POSTGRES_EXPORTER_URL)' \
190+ $(if $(PGO_VERSION ) ,$(strip \
191+ --label release=' $(PGO_VERSION)' \
192+ --label version=' $(PGO_VERSION)' \
193+ --annotation org.opencontainers.image.version=' $(PGO_VERSION)' \
194+ )) \
195+ --file $< --format docker --layers .
192196
193197.PHONY : build-postgres-operator-image
194198build-postgres-operator-image : # # Build the postgres-operator image
199+ build-postgres-operator-image : PGO_IMAGE_REVISION := $(shell git rev-parse HEAD)
200+ build-postgres-operator-image : PGO_IMAGE_TIMESTAMP := $(shell date -u +% FT% TZ)
195201build-postgres-operator-image : build-postgres-operator
196- build-postgres-operator-image : $(PGOROOT ) /build/postgres-operator/Dockerfile
197- $(IMGCMDSTEM ) \
198- -f $(PGOROOT ) /build/postgres-operator/Dockerfile \
199- -t $(PGO_IMAGE_PREFIX ) /postgres-operator:$(PGO_IMAGE_TAG ) \
200- --build-arg BASE_IMAGE_OS=$(BASE_IMAGE_OS ) \
201- --build-arg PACKAGER=$(PACKAGER ) \
202- --build-arg PGVERSION=$(PGO_PG_VERSION ) \
203- --build-arg RELVER=$(PGO_VERSION ) \
204- --build-arg DOCKERBASEREGISTRY=$(DOCKERBASEREGISTRY ) \
205- --build-arg PACKAGER=$(PACKAGER ) \
206- --build-arg PG_FULL=$(PGO_PG_FULLVERSION ) \
207- --build-arg PGVERSION=$(PGO_PG_VERSION ) \
208- $(PGOROOT )
202+ build-postgres-operator-image : build/postgres-operator/Dockerfile
203+ $(if $(shell (echo 'buildah version 1.24'; $(word 1,$(BUILDAH_BUILD ) ) --version) | sort -Vc 2>&1) , \
204+ $(warning WARNING: old buildah does not invalidate its cache for changed labels: \
205+ https://github.com/containers/buildah/issues/3517))
206+ $(if $(IMAGE_TAG ) ,,$(error missing IMAGE_TAG) )
207+ $(BUILDAH_BUILD ) \
208+ --tag $(BUILDAH_TRANSPORT )$(PGO_IMAGE_PREFIX ) /$(PGO_IMAGE_NAME ) :$(IMAGE_TAG ) \
209+ --label name=' $(PGO_IMAGE_NAME)' \
210+ --label build-date=' $(PGO_IMAGE_TIMESTAMP)' \
211+ --label description=' $(PGO_IMAGE_DESCRIPTION)' \
212+ --label maintainer=' $(PGO_IMAGE_MAINTAINER)' \
213+ --label summary=' $(PGO_IMAGE_SUMMARY)' \
214+ --label url=' $(PGO_IMAGE_URL)' \
215+ --label vcs-ref=' $(PGO_IMAGE_REVISION)' \
216+ --label vendor=' $(PGO_IMAGE_MAINTAINER)' \
217+ --label io.k8s.display-name=' $(PGO_IMAGE_NAME)' \
218+ --label io.k8s.description=' $(PGO_IMAGE_DESCRIPTION)' \
219+ --label io.openshift.tags=" postgresql,postgres,sql,nosql,crunchy" \
220+ --annotation org.opencontainers.image.authors=' $(PGO_IMAGE_MAINTAINER)' \
221+ --annotation org.opencontainers.image.vendor=' $(PGO_IMAGE_MAINTAINER)' \
222+ --annotation org.opencontainers.image.created=' $(PGO_IMAGE_TIMESTAMP)' \
223+ --annotation org.opencontainers.image.description=' $(PGO_IMAGE_DESCRIPTION)' \
224+ --annotation org.opencontainers.image.revision=' $(PGO_IMAGE_REVISION)' \
225+ --annotation org.opencontainers.image.title=' $(PGO_IMAGE_SUMMARY)' \
226+ --annotation org.opencontainers.image.url=' $(PGO_IMAGE_URL)' \
227+ $(if $(PGO_VERSION ) ,$(strip \
228+ --label release=' $(PGO_VERSION)' \
229+ --label version=' $(PGO_VERSION)' \
230+ --annotation org.opencontainers.image.version=' $(PGO_VERSION)' \
231+ )) \
232+ --file $< --format docker --layers .
209233
210234# #@ Test
211235.PHONY : check
@@ -295,8 +319,8 @@ generate-crd: ## Generate crd
295319paths=' ./pkg/apis/...' \
296320output:dir=' build/crd/pgupgrades/generated' # build/crd/{plural}/generated/{group}_{plural}.yaml
297321@
298- $( PGO_KUBE_CLIENT ) kustomize ./build/crd/postgresclusters > ./config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml
299- $( PGO_KUBE_CLIENT ) kustomize ./build/crd/pgupgrades > ./config/crd/bases/postgres-operator.crunchydata.com_pgupgrades.yaml
322+ kubectl kustomize ./build/crd/postgresclusters > ./config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml
323+ kubectl kustomize ./build/crd/pgupgrades > ./config/crd/bases/postgres-operator.crunchydata.com_pgupgrades.yaml
300324
301325.PHONY : generate-crd-docs
302326generate-crd-docs : # # Generate crd-docs
@@ -323,3 +347,27 @@ generate-rbac: ## Generate rbac
323347license : licenses
324348licenses : # # Aggregate license files
325349./bin/license_aggregator.sh ./cmd/...
350+
351+ .PHONY : release-postgres-operator-image release-postgres-operator-image-labels
352+ release-postgres-operator-image : # # Build the postgres-operator image and all its prerequisites
353+ release-postgres-operator-image : release-postgres-operator-image-labels
354+ release-postgres-operator-image : licenses
355+ release-postgres-operator-image : build-postgres-operator-image
356+ release-postgres-operator-image-labels :
357+ $(if $(PGO_IMAGE_DESCRIPTION ) ,,$(error missing PGO_IMAGE_DESCRIPTION) )
358+ $(if $(PGO_IMAGE_MAINTAINER ) ,, $(error missing PGO_IMAGE_MAINTAINER) )
359+ $(if $(PGO_IMAGE_NAME ) ,, $(error missing PGO_IMAGE_NAME) )
360+ $(if $(PGO_IMAGE_SUMMARY ) ,, $(error missing PGO_IMAGE_SUMMARY) )
361+ $(if $(PGO_VERSION ) ,,$(error missing PGO_VERSION) )
362+
363+ .PHONY : release-crunchy-postgres-exporter-image release-crunchy-postgres-exporter-image-labels
364+ release-crunchy-postgres-exporter-image : # # Build the postgres-operator image and all its prerequisites
365+ release-crunchy-postgres-exporter-image : release-crunchy-postgres-exporter-image-labels
366+ release-crunchy-postgres-exporter-image : licenses
367+ release-crunchy-postgres-exporter-image : build-postgres-operator-image
368+ release-crunchy-postgres-exporter-image-labels :
369+ $(if $(PGO_IMAGE_DESCRIPTION ) ,,$(error missing PGO_IMAGE_DESCRIPTION) )
370+ $(if $(PGO_IMAGE_MAINTAINER ) ,, $(error missing PGO_IMAGE_MAINTAINER) )
371+ $(if $(PGO_IMAGE_NAME ) ,, $(error missing PGO_IMAGE_NAME) )
372+ $(if $(PGO_IMAGE_SUMMARY ) ,, $(error missing PGO_IMAGE_SUMMARY) )
373+ $(if $(PGO_VERSION ) ,,$(error missing PGO_VERSION) )
0 commit comments