Skip to content

Commit 68ad16c

Browse files
committed
[ci] build catalog image
1 parent 9a9d9c8 commit 68ad16c

File tree

2 files changed

+101
-3
lines changed

2 files changed

+101
-3
lines changed

.github/workflows/build-images-base.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,43 @@ jobs:
150150
run: |
151151
echo "Bundle image(s) pushed:"
152152
echo "${{ steps.bundle-meta.outputs.tags }}"
153+
154+
build-catalog:
155+
needs: [build, build-bundle]
156+
name: Build Catalog
157+
runs-on: ubuntu-latest
158+
steps:
159+
- name: Check out code
160+
uses: actions/checkout@v5
161+
- name: Setup Go
162+
uses: actions/setup-go@v6
163+
with:
164+
go-version-file: go.mod
165+
id: go
166+
- name: Set up Docker Buildx
167+
uses: docker/setup-buildx-action@v3
168+
- name: Login to container registry
169+
uses: docker/login-action@v2
170+
with:
171+
username: ${{ secrets.IMG_REGISTRY_USERNAME }}
172+
password: ${{ secrets.IMG_REGISTRY_TOKEN }}
173+
registry: ${{ env.IMG_REGISTRY_HOST }}
174+
- name: Extract catalog metadata
175+
id: catalog-meta
176+
uses: docker/metadata-action@v5
177+
with:
178+
images: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/${{ env.OPERATOR_NAME }}-catalog
179+
tags: |
180+
type=raw,value=${{ env.IMG_TAGS }}
181+
type=raw,value=${{ github.sha }},enable={{is_default_branch}}
182+
- name: Build and Push Catalog Image
183+
id: build-catalog-image
184+
env:
185+
CATALOG_IMG=${{ steps.catalog-meta.outputs.tags }}
186+
run: |
187+
make catalog-build
188+
make catalog-push
189+
- name: Print Catalog Image URL
190+
run: |
191+
echo "Catalog image(s) pushed:"
192+
echo "${{ steps-catalog-meta.outputs.tags }}"

Makefile

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ SHELL := /bin/bash
33
VERSION ?= 0.0.1
44
# Current Threescale version
55
THREESCALE_VERSION ?= 2.16
6-
# Default bundle image tag
7-
BUNDLE_IMG ?= controller-bundle:$(VERSION)
6+
87
# Options for 'bundle-build'
98
ifneq ($(origin CHANNELS), undefined)
109
BUNDLE_CHANNELS := --channels=$(CHANNELS)
@@ -17,8 +16,32 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
1716
OS := $(shell uname | awk '{print tolower($$0)}' | sed -e s/linux/linux-gnu/ )
1817
ARCH := $(shell uname -m)
1918

19+
# Address of the container registry
20+
REGISTRY = quay.io
21+
22+
# Organization in container resgistry
23+
ORG ?= 3scale
24+
REPO_NAME ?= 3scale-operator
25+
26+
# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
27+
# This variable is used to construct full image tags for bundle and catalog images.
28+
#
29+
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
30+
# quay.io/kuadrant/limitador-operator-bundle:$VERSION and quay.io/kuadrant/limitador-operator-catalog:$VERSION.
31+
IMAGE_TAG_BASE ?= $(REGISTRY)/$(ORG)/$(REPO_NAME)
32+
33+
# Default bundle image tag
34+
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
35+
2036
# Image URL to use all building/pushing image targets
21-
IMG ?= quay.io/3scale/3scale-operator:master
37+
IMG ?= $(IMAGE_TAG_BASE):master
38+
39+
# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
40+
# These images MUST exist in a registry and be pull-able.
41+
BUNDLE_IMGS ?= $(BUNDLE_IMG)
42+
43+
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
44+
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
2245

2346
CRD_OPTIONS ?= "crd:crdVersions=v1"
2447

@@ -294,6 +317,41 @@ bundle-custom-build: | bundle-custom-updates bundle-build bundle-restore
294317
bundle-run: $(OPERATOR_SDK)
295318
$(OPERATOR_SDK) run bundle --namespace openshift-marketplace $(BUNDLE_IMG)
296319

320+
.PHONY: opm
321+
OPM = $(LOCALBIN)/opm
322+
opm: ## Download opm locally if necessary.
323+
ifeq (,$(wildcard $(OPM)))
324+
ifeq (,$(shell which opm 2>/dev/null))
325+
@{ \
326+
set -e ;\
327+
mkdir -p $(dir $(OPM)) ;\
328+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
329+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.55.0/$${OS}-$${ARCH}-opm ;\
330+
chmod +x $(OPM) ;\
331+
}
332+
else
333+
OPM = $(shell which opm)
334+
endif
335+
endif
336+
337+
338+
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
339+
ifneq ($(origin CATALOG_BASE_IMG), undefined)
340+
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
341+
endif
342+
343+
# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
344+
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
345+
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
346+
.PHONY: catalog-build
347+
catalog-build: opm ## Build a catalog image.
348+
$(OPM) index add --container-tool $(DOCKER) --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
349+
350+
# Push the catalog image.
351+
.PHONY: catalog-push
352+
catalog-push: ## Push a catalog image.
353+
$(DOCKER) push ${CATALOG_IMG}
354+
297355
# 3scale-specific targets
298356

299357
# find or download yq

0 commit comments

Comments
 (0)