Skip to content

Commit b23f0be

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

File tree

2 files changed

+89
-3
lines changed

2 files changed

+89
-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: 49 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,20 @@ 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+
IMAGE_TAG_BASE ?= quay.io/3scale-operator
20+
21+
# Default bundle image tag
22+
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
23+
2024
# Image URL to use all building/pushing image targets
21-
IMG ?= quay.io/3scale/3scale-operator:master
25+
IMG ?= $(IMAGE_TAG_BASE):master
26+
27+
# 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).
28+
# These images MUST exist in a registry and be pull-able.
29+
BUNDLE_IMGS ?= $(BUNDLE_IMG)
30+
31+
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
32+
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
2233

2334
CRD_OPTIONS ?= "crd:crdVersions=v1"
2435

@@ -294,6 +305,41 @@ bundle-custom-build: | bundle-custom-updates bundle-build bundle-restore
294305
bundle-run: $(OPERATOR_SDK)
295306
$(OPERATOR_SDK) run bundle --namespace openshift-marketplace $(BUNDLE_IMG)
296307

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

299345
# find or download yq

0 commit comments

Comments
 (0)