Skip to content

Commit

Permalink
Ci improve build images job for release tag (#1007)
Browse files Browse the repository at this point in the history
* 🤖 ci: Improve build images job for release tags

Signed-off-by: Eguzki Astiz Lezaun <[email protected]>

* Makefile: fix make/release.mk file generation

Signed-off-by: Eguzki Astiz Lezaun <[email protected]>

* RELEASE.md: update doc

Signed-off-by: Eguzki Astiz Lezaun <[email protected]>

---------

Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
  • Loading branch information
eguzki authored Nov 14, 2024
1 parent dcd7544 commit fe39f7f
Show file tree
Hide file tree
Showing 9 changed files with 307 additions and 61 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-images-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set IMG_TAG to lower case
id: lower-img-tag
run: echo "IMG_TAGS=${IMG_TAGS@L}" >> $GITHUB_ENV
Expand All @@ -128,6 +128,7 @@ jobs:
QUAY_IMAGE_EXPIRY=${{ inputs.quayImageExpiry }}
GIT_SHA=${{ github.sha }}
DIRTY=false
VERSION=${{ inputs.operatorVersion }}
- name: Print Image URL
run: echo "Image pushed to ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/${{ env.OPERATOR_NAME }}:${{ env.IMG_TAGS }}"

Expand Down
196 changes: 196 additions & 0 deletions .github/workflows/build-images-for-tag-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
name: Build and Publish Images For Tag Release

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
env:
IMG_REGISTRY_HOST: quay.io
IMG_REGISTRY_ORG: kuadrant
OPERATOR_NAME: kuadrant-operator

jobs:
build:
name: Build and Push image
runs-on: ubuntu-latest
outputs:
build-tags: ${{ steps.build-image.outputs.tags }}
image: ${{ steps.push-to-quay.outputs.registry-path }}
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Read release string version
id: release
run: |
version=`make read-release-version`
echo version=$version >> $GITHUB_OUTPUT
- name: Print tags
run: echo "Git reference name = ${{ github.ref_name }}, release version = ${{ steps.release.outputs.version }}"
- name: Verify git reference name matches the release version
if: ${{ github.ref_name != steps.release.outputs.version }}
run: exit 1

- name: Install qemu dependency
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Build Image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.OPERATOR_NAME }}
tags: ${{ github.ref_name }}
platforms: linux/amd64,linux/arm64
build-args: |
GIT_SHA=${{ github.sha }}
DIRTY=false
VERSION=${{ github.ref_name }}
dockerfiles: |
./Dockerfile
- name: Print Build Info
run: echo "Image = ${{ steps.build-image.outputs.image }}, Tags = ${{ steps.build-image.outputs.tags }}"

- name: Push Image
if: github.repository_owner == 'kuadrant'
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}
username: ${{ secrets.IMG_REGISTRY_USERNAME }}
password: ${{ secrets.IMG_REGISTRY_TOKEN }}

- name: Print Image URL
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"

build-bundle:
name: Build and Push bundle image
needs: [build]
runs-on: ubuntu-latest
outputs:
build-tags: ${{ steps.build-image.outputs.tags }}
image: ${{ steps.push-to-quay.outputs.registry-path }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install yq tool
run: |
# following sub-shells running make target should have yq already installed
make yq
- name: Read operator image reference URL from the manifest bundle
id: parsed-operator-image
run: |
url=`make bundle-operator-image-url`
echo url=$url >> $GITHUB_OUTPUT
- name: Print tags and references
run: echo "Operator image tag = ${{ needs.build.outputs.image }}, Reference in bundle = ${{ steps.parsed-operator-image.outputs.url }}"
- name: Verify referenced operator image tag matches the tag currently being built
if: ${{ needs.build.outputs.image != steps.parsed-operator-image.outputs.url }}
run: exit 1

- name: Install qemu dependency
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Build Image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.OPERATOR_NAME }}-bundle
tags: ${{ needs.build.outputs.build-tags }}
platforms: linux/amd64,linux/arm64
dockerfiles: |
./bundle.Dockerfile
- name: Print Build Info
run: echo "Image = ${{ steps.build-image.outputs.image }}, Tags = ${{ steps.build-image.outputs.tags }}, Operator IMG = ${{ steps.parsed-operator-image.outputs.url }}"

- name: Push Image
if: github.repository_owner == 'kuadrant'
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}
username: ${{ secrets.IMG_REGISTRY_USERNAME }}
password: ${{ secrets.IMG_REGISTRY_TOKEN }}

- name: Print Image URL
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"

build-catalog:
name: Build and Push catalog image
needs: [build, build-bundle]
runs-on: ubuntu-latest
outputs:
build-tags: ${{ steps.build-image.outputs.tags }}
image: ${{ steps.push-to-quay.outputs.registry-path }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install yq tool
run: |
# following sub-shells running make target should have yq already installed
make yq
- name: Read operator bundle image reference
id: parsed-operator-bundle
run: |
image=`make print-bundle-image`
echo image=$image >> $GITHUB_OUTPUT
- name: Print tags and references
run: echo "Operator bundle image tag = ${{ needs.build-bundle.outputs.image }}, Reference in catalog = ${{ steps.parsed-operator-bundle.outputs.image }}"
- name: Verify referenced bundle tag matches the bundle tag currently being built
if: ${{ needs.build-bundle.outputs.image != steps.parsed-operator-bundle.outputs.image }}
run: exit 1
- name: Generate Catalog Content
run: make catalog
- name: Install qemu dependency
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Build Image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.OPERATOR_NAME }}-catalog
tags: ${{ needs.build.outputs.build-tags }}
platforms: linux/amd64,linux/arm64
context: ./catalog
dockerfiles: ./catalog/${{ env.OPERATOR_NAME }}-catalog.Dockerfile

- name: Print Build Info
run: echo "Image = ${{ steps.build-image.outputs.image }}, Tags = ${{ steps.build-image.outputs.tags }}, Bundle IMG = ${{ steps.parsed-operator-bundle.outputs.image }}"

- name: Push Image
if: github.repository_owner == 'kuadrant'
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}
username: ${{ secrets.IMG_REGISTRY_USERNAME }}
password: ${{ secrets.IMG_REGISTRY_TOKEN }}

- name: Print Image URL
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"

verify-builds:
name: Ensure all image references are equal (operator, bundle, catalog)
needs: [build, build-bundle, build-catalog]
runs-on: ubuntu-latest
steps:
- name: Verify bundle and operator image tags match
if: ${{ needs.build.outputs.build-tags != needs.build-bundle.outputs.build-tags }}
run: exit 1
- name: Verify catalog and bundle tags match
if: ${{ needs.build-bundle.outputs.build-tags != needs.build-catalog.outputs.build-tags }}
run: exit 1
31 changes: 18 additions & 13 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ on:
type: string
authorinoOperatorVersion:
description: Authorino Operator bundle version
default: latest
default: 0.0.0
type: string
limitadorOperatorVersion:
description: Limitador Operator bundle version
default: latest
default: 0.0.0
type: string
dnsOperatorVersion:
description: DNS Operator bundle version
default: latest
default: 0.0.0
type: string
wasmShimVersion:
description: WASM Shim version
default: latest
default: 0.0.0
type: string
consolePluginImageURL:
description: ConsolePlugin image URL
Expand All @@ -38,7 +38,7 @@ on:
jobs:
build:
name: Release operator
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Install gettext-base
run: |
Expand All @@ -50,28 +50,33 @@ jobs:
go-version: 1.21.x
id: go
- name: Checkout code at git ref
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ inputs.gitRef }}
token: ${{ secrets.KUADRANT_DEV_PAT }}
- name: Create release branch
if: ${{ !startsWith(inputs.gitRef, 'release-v') }}
run: |
git checkout -b release-v${{ inputs.kuadrantOperatorVersion }}
- name: Prepare release
run: |
make prepare-release \
VERSION=${{ inputs.kuadrantOperatorVersion }} \
AUTHORINO_OPERATOR_VERSION=${{ inputs.authorinoOperatorVersion }} \
LIMITADOR_OPERATOR_VERSION=${{ inputs.limitadorOperatorVersion }} \
DNS_OPERATOR_VERSION=${{ inputs.dnsOperatorVersion }} \
WASM_SHIM_VERSION=${{ inputs.wasmShimVersion }} \
RELATED_IMAGE_CONSOLEPLUGIN=${{ inputs.consolePluginImageURL }} \
make prepare-release
RELATED_IMAGE_CONSOLEPLUGIN=${{ inputs.consolePluginImageURL }}
- name: Commit and push
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add -A && git commit -s -m "Prepared release v${{ inputs.kuadrantOperatorVersion }}"
git push origin release-v${{ inputs.kuadrantOperatorVersion }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Prepared release v${{ inputs.kuadrantOperatorVersion }}"
commit_user_name: "github-actions[bot]"
commit_user_email: "github-actions[bot]@users.noreply.github.com"
branch: release-v${{ inputs.kuadrantOperatorVersion }}
create_branch: true
tagging_message: v${{ inputs.kuadrantOperatorVersion }}
commit_options: '--signoff'
- name: Create release
uses: softprops/action-gh-release@v1
with:
Expand Down
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY pkg/ pkg/
COPY version/ version/

# Set environment variables for cross-compilation
ARG TARGETARCH
Expand All @@ -23,10 +22,13 @@ ARG TARGETARCH

ARG GIT_SHA
ARG DIRTY
ARG VERSION

ENV GIT_SHA=${GIT_SHA:-unknown}
ENV DIRTY=${DIRTY:-unknown}
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -a -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" -o manager main.go
ENV VERSION=${VERSION:-unknown}

RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -a -ldflags "-X main.version=${VERSION} -X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
36 changes: 33 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ else
GOBIN=$(shell go env GOBIN)
endif

RELEASE_FILE = $(PROJECT_PATH)/make/release.mk

# Kuadrant Namespace
KUADRANT_NAMESPACE ?= kuadrant-system
OPERATOR_NAMESPACE ?= $(KUADRANT_NAMESPACE)
Expand Down Expand Up @@ -332,15 +334,15 @@ test-unit: clean-cov generate fmt vet ## Run Unit tests.
build: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown")
build: DIRTY=$(shell $(PROJECT_PATH)/utils/check-git-dirty.sh || echo "unknown")
build: generate fmt vet ## Build manager binary.
go build -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" -o bin/manager main.go
go build -ldflags "-X main.version=v$(VERSION) -X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" -o bin/manager main.go

run: export LOG_LEVEL = debug
run: export LOG_MODE = development
run: export OPERATOR_NAMESPACE := $(OPERATOR_NAMESPACE)
run: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown")
run: DIRTY=$(shell $(PROJECT_PATH)/utils/check-git-dirty.sh || echo "unknown")
run: generate fmt vet ## Run a controller from your host.
go run -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" --race ./main.go
go run -ldflags "-X main.version=v$(VERSION) -X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" --race ./main.go

docker-build: GIT_SHA=$(shell git rev-parse HEAD || echo "unknown")
docker-build: DIRTY=$(shell $(PROJECT_PATH)/utils/check-git-dirty.sh || echo "unknown")
Expand All @@ -349,6 +351,7 @@ docker-build: ## Build docker image with the manager.
--build-arg QUAY_IMAGE_EXPIRY=$(QUAY_IMAGE_EXPIRY) \
--build-arg GIT_SHA=$(GIT_SHA) \
--build-arg DIRTY=$(DIRTY) \
--build-arg VERSION=v$(VERSION) \
--build-arg QUAY_IMAGE_EXPIRY=$(QUAY_IMAGE_EXPIRY) \
--load \
-t $(IMG) .
Expand Down Expand Up @@ -442,6 +445,23 @@ bundle-push: ## Push the bundle image.

.PHONY: prepare-release
prepare-release: ## Prepare the manifests for OLM and Helm Chart for a release.
echo -e "#Release default values\\n\
AUTHORINO_OPERATOR_VERSION=$(AUTHORINO_OPERATOR_VERSION)\\n\
AUTHORINO_OPERATOR_BUNDLE_IMG=$(AUTHORINO_OPERATOR_BUNDLE_IMG)\\n\
LIMITADOR_OPERATOR_VERSION=$(LIMITADOR_OPERATOR_VERSION)\\n\
LIMITADOR_OPERATOR_BUNDLE_IMG=$(LIMITADOR_OPERATOR_BUNDLE_IMG)\\n\
DNS_OPERATOR_VERSION=$(DNS_OPERATOR_VERSION)\\n\
DNS_OPERATOR_BUNDLE_IMG=$(DNS_OPERATOR_BUNDLE_IMG)\\n\
WASM_SHIM_VERSION=$(WASM_SHIM_VERSION)\\n\
RELATED_IMAGE_WASMSHIM=$(RELATED_IMAGE_WASMSHIM)\\n\
RELATED_IMAGE_CONSOLEPLUGIN=$(RELATED_IMAGE_CONSOLEPLUGIN)\\n\
IMG=$(IMG)\\n\
BUNDLE_VERSION=$(BUNDLE_VERSION)\\n\
BUNDLE_IMG=$(BUNDLE_IMG)\\n\
CATALOG_IMG=$(CATALOG_IMG)\\n\
CHANNELS=$(CHANNELS)\\n\
BUNDLE_CHANNELS=--channels=$(CHANNELS)\\n\
VERSION=$(VERSION)" > $(RELEASE_FILE)
$(MAKE) bundle VERSION=$(VERSION) \
AUTHORINO_OPERATOR_VERSION=$(AUTHORINO_OPERATOR_VERSION) \
LIMITADOR_OPERATOR_VERSION=$(LIMITADOR_OPERATOR_VERSION) \
Expand All @@ -454,7 +474,17 @@ prepare-release: ## Prepare the manifests for OLM and Helm Chart for a release.
DNS_OPERATOR_VERSION=$(DNS_OPERATOR_VERSION) \
WASM_SHIM_VERSION=$(WASM_SHIM_VERSION) \
RELATED_IMAGE_CONSOLEPLUGIN=$(RELATED_IMAGE_CONSOLEPLUGIN)
sed -i -e 's/Version = ".*"/Version = "$(VERSION)"/' $(PROJECT_PATH)/version/version.go

.PHONY: bundle-operator-image-url
bundle-operator-image-url: $(YQ) ## Read operator image reference URL from the manifest bundle.
@$(YQ) '.metadata.annotations.containerImage' bundle/manifests/kuadrant-operator.clusterserviceversion.yaml

.PHONY: read-release-version
read-release-version: ## Reads release version
@echo "v$(VERSION)"

print-bundle-image: ## Pring bundle images.
@echo $(BUNDLE_IMG)

##@ Code Style

Expand Down
Loading

0 comments on commit fe39f7f

Please sign in to comment.