-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMakefile
More file actions
137 lines (109 loc) · 4.86 KB
/
Copy pathMakefile
File metadata and controls
137 lines (109 loc) · 4.86 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
## local variables.
commit_sha = $(strip $(shell git rev-parse HEAD))
source_url = $(strip $(shell git remote get-url origin))
release_version = v$(strip $(shell git branch --show-current | cut -d'-' -f2))
## cert-manager-operator-release and cert-manager follow same naming for release
## branches except for cert-manager-operator which has release version as suffix in
## the branch name like in aforementioned repositories, which will be used for
## deriving the submodules branch.
PARENT_BRANCH_SUFFIX = $(strip $(shell git branch --show-current | cut -d'-' -f2))
## container build tool to use for creating images.
CONTAINER_ENGINE ?= podman
## image name for cert-manager catalog.
CATALOG_IMAGE ?= cert-manager-catalog
## image version to tag the created images with.
IMAGE_VERSION ?= $(release_version)
## image tag makes use of the branch name and
## when branch name is `main` use `latest` as the tag.
ifeq ($(PARENT_BRANCH_SUFFIX), main)
IMAGE_VERSION = latest
endif
## args to pass during image build
IMAGE_BUILD_ARGS ?= --build-arg RELEASE_VERSION=$(release_version) --build-arg COMMIT_SHA=$(commit_sha) --build-arg SOURCE_URL=$(source_url)
## tailored command to build images.
IMAGE_BUILD_CMD = $(CONTAINER_ENGINE) build $(IMAGE_BUILD_ARGS)
## path to store the tools binary.
TOOL_BIN_DIR = $(strip $(shell git rev-parse --show-toplevel --show-superproject-working-tree | tail -1))/bin/tools
## URL to download Operator Package Manager tool.
OPM_DOWNLOAD_URL = https://github.com/operator-framework/operator-registry/releases/download/v1.48.0/$(shell go env GOOS)-$(shell go env GOARCH)-opm
## Operator Package Manager tool path.
OPM_TOOL_PATH ?= $(TOOL_BIN_DIR)/opm
## Operator bundle image to use for generating catalog.
OPERATOR_BUNDLE_IMAGE ?=
## Catalog directory where generated catalog will be stored (e.g. catalogs/v4.22/catalog).
CATALOG_DIR ?=
## Bundle file name to generate under the package directory (e.g. bundle-v1.20.0.yaml).
BUNDLE_FILE_NAME ?=
## OCP versions to replicate the bundle to: no | yes | 4.19,4.20 | 4.19-4.22
REPLICATE_BUNDLE_FILE_IN_CATALOGS ?= no
.DEFAULT_GOAL := help
## usage summary.
.PHONY: help
help:
@ echo
@ echo ' Usage:'
@ echo ''
@ echo ' make <target> [flags...]'
@ echo ''
@ echo ' Targets:'
@ echo ''
@ awk '/^#/{ comment = substr($$0,3) } comment && /^[a-zA-Z][a-zA-Z0-9_-]+ ?:/{ print " ", $$1, comment }' $(MAKEFILE_LIST) | column -t -s ':' | sort
@ echo ''
@ echo ' Flags:'
@ echo ''
@ awk '/^#/{ comment = substr($$0,3) } comment && /^[a-zA-Z][a-zA-Z0-9_-]+ ?\?=/{ print " ", $$1, $$2, comment }' $(MAKEFILE_LIST) | column -t -s '?=' | sort
@ echo ''
## execute all required targets.
.PHONY: all
all: verify
## build operator catalog image.
.PHONY: build-catalog-image
build-catalog-image:
$(CONTAINER_ENGINE) build -f Containerfile.catalog -t $(CATALOG_IMAGE):$(IMAGE_VERSION) .
## update catalog using the provided bundle image.
.PHONY: update-catalog
update-catalog: get-opm
@test -n "$(OPERATOR_BUNDLE_IMAGE)" || { echo "OPERATOR_BUNDLE_IMAGE is required"; exit 1; }
@test -n "$(CATALOG_DIR)" || { echo "CATALOG_DIR is required (e.g. catalogs/v4.22/catalog)"; exit 1; }
@test -n "$(BUNDLE_FILE_NAME)" || { echo "BUNDLE_FILE_NAME is required (e.g. bundle-v1.20.0.yaml)"; exit 1; }
@#ex.: make update-catalog OPERATOR_BUNDLE_IMAGE=registry.stage.redhat.io/cert-manager/cert-manager-operator-bundle@sha256:39404aefc48202660c9b4dfae18672cc4ed66d0a9b08fcf5ae70a4504c4e7dff CATALOG_DIR=catalogs/v4.19/catalog BUNDLE_FILE_NAME=bundle-v1.20.0.yaml REPLICATE_BUNDLE_FILE_IN_CATALOGS=4.19-5.0 USE_MIGRATE_LEVEL_FLAG=yes
./hack/update_catalog.sh $(OPM_TOOL_PATH) $(OPERATOR_BUNDLE_IMAGE) $(CATALOG_DIR) $(BUNDLE_FILE_NAME) $(REPLICATE_BUNDLE_FILE_IN_CATALOGS) $(USE_MIGRATE_LEVEL_FLAG)
## update catalog and build catalog image.
.PHONY: catalog
catalog: get-opm build-catalog-image
# Only run update-catalog if OPERATOR_BUNDLE_IMAGE is set
ifneq ($(OPERATOR_BUNDLE_IMAGE),)
catalog: get-opm update-catalog build-catalog-image
endif
## check shell scripts.
.PHONY: verify-shell-scripts
verify-shell-scripts:
./hack/shell-scripts-linter.sh
## check containerfiles.
.PHONY: verify-containerfiles
verify-containerfiles:
./hack/containerfile-linter.sh
## verify the changes are working as expected.
.PHONY: verify
verify: verify-shell-scripts verify-containerfiles validate-renovate-config
## get opm(operator package manager) tool.
.PHONY: get-opm
get-opm:
$(call get-bin,$(OPM_TOOL_PATH),$(TOOL_BIN_DIR),$(OPM_DOWNLOAD_URL))
define get-bin
@[ -f "$(1)" ] || { \
[ ! -d "$(2)" ] && mkdir -p "$(2)" || true ;\
echo "Downloading $(3)" ;\
curl -fL $(3) -o "$(1)" ;\
chmod +x "$(1)" ;\
}
endef
## clean up temp dirs, images.
.PHONY: clean
clean:
$(CONTAINER_ENGINE) rmi -i $(CATALOG_IMAGE):$(IMAGE_VERSION)
rm -r $(TOOL_BIN_DIR)
## validate renovate config.
.PHONY: validate-renovate-config
validate-renovate-config:
./hack/renovate-config-validator.sh