Skip to content

Commit 795d085

Browse files
committed
standarize makefile
1 parent c703c83 commit 795d085

2 files changed

Lines changed: 108 additions & 43 deletions

File tree

installers/olm/Makefile

Lines changed: 103 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,146 @@
1+
# ==============================================================================
2+
# Percona PostgreSQL Operator - OLM Bundle Generation
3+
# ==============================================================================
4+
5+
# Default target
16
.DEFAULT_GOAL := help
27
.SUFFIXES:
8+
SHELL := /bin/bash
39

10+
# ==============================================================================
11+
# Configuration Variables
12+
# ==============================================================================
13+
14+
# Project configuration
15+
NAME ?= percona-postgresql-operator
16+
IMAGE_TAG_OWNER ?= perconalab
17+
IMAGE_TAG_BASE ?= $(IMAGE_TAG_OWNER)/$(NAME)
418
CONTAINER ?= docker
19+
20+
# Bundle configuration
521
OPENSHIFT_VERSIONS ?= v4.17-v4.21
622
PACKAGE_CHANNEL ?= preview
723
MIN_KUBE_VERSION ?= 1.23.0
824
DOCKER_DEFAULT_PLATFORM ?= linux/amd64
9-
SHELL := /bin/bash
1025

11-
IMAGE_TAG_BASE ?= perconalab/percona-postgresql-operator
26+
# Image configuration
27+
IMAGE ?= $(IMAGE_TAG_BASE):$(VERSION)
1228
BUNDLE_REPO ?= $(IMAGE_TAG_BASE)
29+
BUNDLE_DISTRO ?= community
30+
BUNDLE_IMG ?= $(BUNDLE_REPO):community-bundle-$(VERSION)
1331
REDHAT_OPERATOR_IMAGE ?= registry.connect.redhat.com/percona/percona-postgresql-operator:$(VERSION)
1432

15-
IMAGE ?= $(IMAGE_TAG_BASE):$(VERSION)
33+
# Paths
34+
REPO_ROOT := $(shell git rev-parse --show-toplevel)
35+
KUSTOMIZE := $(REPO_ROOT)/bin/kustomize
36+
37+
# Tool versions
38+
JQ_VERSION := 1.7.1
39+
OPERATOR_SDK_VERSION := v1.42.2
40+
OPM_VERSION := v1.66.0
1641

1742
ifneq ($(shell bash -c 'test "$${BASH_VERSINFO[0]}" -ge 5 && echo yes'),yes)
1843
$(error You need to use bash 5.x+ for this Makefile)
1944
endif
2045

2146
OS_KERNEL ?= $(shell bash -c 'echo $${1,,}' - `uname -s`)
2247
OS_MACHINE ?= $(shell bash -c 'echo $${1/x86_/amd}' - `uname -m`)
23-
SYSTEM = $(OS_KERNEL)-$(OS_MACHINE)
48+
SYSTEM := $(OS_KERNEL)-$(OS_MACHINE)
2449

2550
export PATH := $(CURDIR)/tools/$(SYSTEM):$(PATH)
2651

27-
export VERSION
28-
export BUNDLE_REPO
29-
export OPENSHIFT_VERSIONS
30-
export PACKAGE_CHANNEL
31-
export MIN_KUBE_VERSION
32-
export DOCKER_DEFAULT_PLATFORM
52+
# Display colors
53+
GREEN := $(shell tput setaf 2)
54+
RESET := $(shell tput sgr0)
3355

34-
REPO_ROOT = $(shell git rev-parse --show-toplevel)
56+
# Export variables for generate.sh
57+
export VERSION BUNDLE_REPO OPENSHIFT_VERSIONS PACKAGE_CHANNEL MIN_KUBE_VERSION DOCKER_DEFAULT_PLATFORM
3558

36-
distros = community redhat
59+
# ==============================================================================
60+
# Bundle Targets
61+
# ==============================================================================
3762

38-
check-version:
39-
ifndef VERSION
40-
$(error VERSION is not set)
41-
endif
42-
43-
KUSTOMIZE = $(REPO_ROOT)/bin/kustomize
44-
45-
$(KUSTOMIZE):
46-
$(MAKE) -C '$(REPO_ROOT)' kustomize
63+
DISTROS := community redhat
4764

4865
.PHONY: bundles
49-
bundles: ## Build OLM bundles
50-
bundles: check-version tools $(KUSTOMIZE) $(distros:%=bundles/%)
66+
bundles: ## Build all OLM bundles (community, redhat)
67+
bundles: check-prereqs $(DISTROS:%=bundles/%)
5168

5269
# https://olm.operatorframework.io/docs/tasks/creating-operator-bundle/#validating-your-bundle
5370
.PHONY: bundles/community
54-
bundles/community:
71+
bundles/community: tools $(KUSTOMIZE)
72+
@echo "$(GREEN)Building community bundle...$(RESET)"
5573
cd ../../config/manager/default/ && $(KUSTOMIZE) edit set image 'postgres-operator=$(IMAGE)'
5674
./generate.sh community
57-
env operator-sdk bundle validate $@ --select-optional='suite=operatorframework'
75+
operator-sdk bundle validate $@ --select-optional='suite=operatorframework'
76+
@echo "$(GREEN)Bundle stored in installers/olm/bundles/community$(RESET)"
5877

5978
# https://redhat-connect.gitbook.io/certified-operator-guide/ocp-deployment/operator-metadata/reviewing-your-metadata-bundle
6079
.PHONY: bundles/redhat
61-
bundles/redhat:
80+
bundles/redhat: tools $(KUSTOMIZE)
81+
@echo "$(GREEN)Building redhat bundle...$(RESET)"
6282
cd ../../config/manager/default/ && $(KUSTOMIZE) edit set image 'postgres-operator=$(REDHAT_OPERATOR_IMAGE)'
6383
./generate.sh redhat
64-
env operator-sdk bundle validate $@ --select-optional='suite=operatorframework'
84+
operator-sdk bundle validate $@ --select-optional='suite=operatorframework'
85+
@echo "$(GREEN)Bundle stored in installers/olm/bundles/redhat$(RESET)"
86+
87+
# ==============================================================================
88+
# Docker Build & Push Targets
89+
# ==============================================================================
90+
91+
.PHONY: build
92+
build: ## Build bundle image (set BUNDLE_DISTRO=community|redhat)
93+
build: check-version bundles/$(BUNDLE_DISTRO)
94+
@echo "$(GREEN)Building bundle image...$(RESET)"
95+
$(CONTAINER) build -t $(BUNDLE_IMG) --platform=$(DOCKER_DEFAULT_PLATFORM) bundles/$(BUNDLE_DISTRO)
96+
@echo "$(GREEN)Bundle image built: $(BUNDLE_IMG)$(RESET)"
97+
98+
.PHONY: push
99+
push: ## Push bundle image to registry
100+
push: check-version
101+
@echo "$(GREEN)Pushing bundle image to registry...$(RESET)"
102+
$(CONTAINER) push $(BUNDLE_IMG)
103+
@echo "$(GREEN)Bundle image pushed: $(BUNDLE_IMG)$(RESET)"
104+
105+
# ==============================================================================
106+
# Utility Targets
107+
# ==============================================================================
108+
109+
.PHONY: check-prereqs
110+
check-prereqs: check-version tools $(KUSTOMIZE)
111+
112+
.PHONY: check-version
113+
check-version:
114+
ifndef VERSION
115+
$(error VERSION is not set)
116+
endif
117+
118+
$(KUSTOMIZE):
119+
$(MAKE) -C '$(REPO_ROOT)' kustomize
120+
121+
.PHONY: install-olm
122+
install-olm: ## Install OLM in Kubernetes
123+
install-olm: tools
124+
operator-sdk olm install
65125

66126
.PHONY: clean
67127
clean: ## Remove generated files and downloaded tools
68128
rm -rf ./bundles ./projects ./tools
69129

70130
.PHONY: help
71-
help: ALIGN=18
72-
help: ## Print this message
73-
@awk -F ': ## ' -- "/^[^':]+: ## /"' { printf "'$$(tput bold)'%-$(ALIGN)s'$$(tput sgr0)' %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
131+
help: ## Show this help message
132+
@awk 'BEGIN {FS = ": ## "; printf "\n$(GREEN)Usage:$(RESET)\n make [target]\n\n$(GREEN)Targets:$(RESET)\n"} /^[a-zA-Z_-]+: ## / {printf " %-24s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
74133

75-
.PHONY: install-olm
76-
install-olm: ## Install OLM in Kubernetes
77-
env operator-sdk olm install
134+
# ==============================================================================
135+
# Tool Management
136+
# ==============================================================================
78137

79138
.PHONY: tools
80-
tools: ## Download tools needed to build bundles
81-
139+
tools: ## Download required tools
82140
tools: tools/$(SYSTEM)/jq
83141
tools/$(SYSTEM)/jq:
84142
install -d '$(dir $@)'
85-
curl -fSL -o '$@' "https://github.com/stedolan/jq/releases/download/jq-1.7.1/jq-$$(SYSTEM='$(SYSTEM)'; \
143+
curl -fSL -o '$@' "https://github.com/stedolan/jq/releases/download/jq-$(JQ_VERSION)/jq-$$(SYSTEM='$(SYSTEM)'; \
86144
case "$$SYSTEM" in \
87145
(linux-*) echo "$${SYSTEM/-amd/}";; (darwin-*) echo "$${SYSTEM/darwin-*/osx-amd64}";; (*) echo '$(SYSTEM)';; \
88146
esac)"
@@ -98,13 +156,13 @@ tools/$(SYSTEM)/kubectl:
98156
tools: tools/$(SYSTEM)/operator-sdk
99157
tools/$(SYSTEM)/operator-sdk:
100158
install -d '$(dir $@)'
101-
curl -fSL -o '$@' 'https://github.com/operator-framework/operator-sdk/releases/download/v1.42.2/operator-sdk_$(OS_KERNEL)_$(OS_MACHINE)'
159+
curl -fSL -o '$@' 'https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$(OS_KERNEL)_$(OS_MACHINE)'
102160
chmod u+x '$@'
103161

104162
tools: tools/$(SYSTEM)/opm
105163
tools/$(SYSTEM)/opm:
106164
install -d '$(dir $@)'
107-
curl -fSL -o '$@' 'https://github.com/operator-framework/operator-registry/releases/download/v1.66.0/$(OS_KERNEL)-$(OS_MACHINE)-opm'
165+
curl -fSL -o '$@' 'https://github.com/operator-framework/operator-registry/releases/download/$(OPM_VERSION)/$(OS_KERNEL)-$(OS_MACHINE)-opm'
108166
chmod u+x '$@'
109167

110168
tools/$(SYSTEM)/venv:
@@ -116,11 +174,15 @@ tools/$(SYSTEM)/yq: | tools/$(SYSTEM)/venv
116174
'tools/$(SYSTEM)/venv/bin/python' -m pip install yq
117175
cd '$(dir $@)' && ln -s venv/bin/yq
118176

177+
# ==============================================================================
178+
# Development Targets
179+
# ==============================================================================
180+
119181
.PHONY: validate-bundles
120182
validate-bundles: ## Build temporary bundle images and run scorecard tests in Kubernetes
121183
validate-bundles: tools
122-
validate-bundles: $(distros:%=validate-%-image)
123-
validate-bundles: $(distros:%=validate-%-directory)
184+
validate-bundles: $(DISTROS:%=validate-%-image)
185+
validate-bundles: $(DISTROS:%=validate-%-directory)
124186

125187
validate-%-directory:
126188
./validate-directory.sh 'bundles/$*'
@@ -129,7 +191,7 @@ validate-%-image:
129191
./validate-image.sh '$(CONTAINER)' 'bundles/$*'
130192

131193
.PHONY: build-bundle-images
132-
build-bundle-images: check-version $(distros:%=build-%-image)
194+
build-bundle-images: check-version $(DISTROS:%=build-%-image)
133195

134196
build-%-image:
135197
./build-image.sh '$(CONTAINER)' 'bundles/$*' '$*' '$(VERSION)'

installers/olm/generate.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ redhat_image_ref() {
8888
local name="$1" repository="$2" tag="$3" digest_var digest
8989
digest_var="REDHAT_IMAGE_DIGEST_$(redhat_digest_override_key "${name}")"
9090
digest="${!digest_var:-}"
91-
[[ -n ${digest} ]] || digest=$(redhat_catalog_digest "${repository}" "${tag}")
91+
if [[ -z ${digest} ]]; then
92+
digest=$(redhat_catalog_digest "${repository}" "${tag}") || exit
93+
fi
94+
[[ -n ${digest} ]] || abort "empty Red Hat image digest for ${redhat_registry}/${repository}:${tag}"
9295
[[ ${digest} == sha256:* ]] || digest="sha256:${digest#sha256:}"
9396
printf '%s/%s@%s\n' "${redhat_registry}" "${repository}" "${digest}"
9497
}
@@ -132,7 +135,7 @@ build_redhat_related_images() {
132135

133136
current_pg_major=$(yq --raw-output '.spec.postgresVersion' ../../deploy/cr.yaml)
134137
redhat_operator_image="${redhat_image_refs[operator]}"
135-
redhat_postgres_image="${redhat_image_refs[ppg${current_pg_major} - postgres]}"
138+
redhat_postgres_image="${redhat_image_refs[ppg${current_pg_major}-postgres]}"
136139
redhat_pgbouncer_image="${redhat_image_refs[pgbouncer]}"
137140
redhat_pgbackrest_image="${redhat_image_refs[pgbackrest]}"
138141
redhat_pmm_image="${redhat_image_refs[pmm]}"

0 commit comments

Comments
 (0)