Skip to content

Commit a3f293e

Browse files
authored
Merge pull request #7 from AustrianDataLAB/dev
fix: build multiple architectures; use toTag and fromTag
2 parents 220397b + 65ab8bb commit a3f293e

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed

.github/workflows/main.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# main.yml
22
name: Build and Release operator
3-
run-name: Build/Release operator triggerd by ${{ github.actor }} - ${{ github.event.head_commit.message }}${{ github.event.pull_request.title }}
3+
run-name: ${{ github.actor }} triggerd -> ${{ github.event.head_commit.message }}${{ github.event.pull_request.title }}
44

55
on:
66
push:
@@ -32,7 +32,7 @@ jobs:
3232
if: ${{ github.event_name == 'push' || github.event.pull_request.merged == true }}
3333
runs-on: ubuntu-latest
3434
outputs:
35-
IMAGE_REPO: ${{ steps.SET_IMAGE_REPO.outputs.IMAGE_REPO }}
35+
IMAGE_TAG_BASE: ${{ steps.SET_IMAGE_TAG_BASE.outputs.IMAGE_TAG_BASE }}
3636
OPERATOR_VERSION: ${{ steps.SET_OPERATOR_VERSION.outputs.OPERATOR_VERSION }}
3737
IS_RELEASE: ${{ steps.SET_OPERATOR_VERSION.outputs.IS_RELEASE }}
3838
current: ${{ steps.semver.outputs.current }}
@@ -43,9 +43,9 @@ jobs:
4343

4444
- name: Export Repo Name lowercase
4545
run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
46-
- name: Set IMAGE_REPO
47-
id: SET_IMAGE_REPO
48-
run: echo "IMAGE_REPO=${{ env.IMAGE_REGISTRY }}/${{ env.REPO }}" >>${GITHUB_OUTPUT}
46+
- name: Set IMAGE_TAG_BASE
47+
id: SET_IMAGE_TAG_BASE
48+
run: echo "IMAGE_TAG_BASE=${{ env.IMAGE_REGISTRY }}/${{ env.REPO }}" >>${GITHUB_OUTPUT}
4949

5050
- name: Get Next Version
5151
id: semver
@@ -91,7 +91,7 @@ jobs:
9191
docker:
9292
image: docker:dind
9393
env:
94-
IMAGE_REPO: ${{ needs.prepare.outputs.IMAGE_REPO }}
94+
IMAGE_TAG_BASE: ${{ needs.prepare.outputs.IMAGE_TAG_BASE }}
9595
OPERATOR_VERSION: ${{ needs.prepare.outputs.OPERATOR_VERSION }}
9696
steps:
9797
- name: Set up QEMU
@@ -111,7 +111,7 @@ jobs:
111111
platforms: linux/amd64,linux/arm64
112112
file: "Dockerfile.buildah.k8s.rootless"
113113
push: true
114-
tags: ${{ env.IMAGE_REPO }}-buildah:${{ env.OPERATOR_VERSION }}
114+
tags: ${{ env.IMAGE_TAG_BASE }}-buildah:${{ env.OPERATOR_VERSION }}
115115

116116
operator:
117117
needs: prepare
@@ -121,8 +121,10 @@ jobs:
121121
docker:
122122
image: docker:dind
123123
env:
124-
IMAGE_REPO: ${{ needs.prepare.outputs.IMAGE_REPO }}
125124
OPERATOR_VERSION: ${{ needs.prepare.outputs.OPERATOR_VERSION }}
125+
IMAGE_TAG_BASE: ${{ needs.prepare.outputs.IMAGE_TAG_BASE }}
126+
IMG: "${{ needs.prepare.outputs.IMAGE_TAG_BASE }}:${{ needs.prepare.outputs.OPERATOR_VERSION }}"
127+
BUNDLE_IMG: "${{ needs.prepare.outputs.IMAGE_TAG_BASE }}-bundle:${{ needs.prepare.outputs.OPERATOR_VERSION }}"
126128
steps:
127129
- name: Checkout code
128130
uses: actions/checkout@v3
@@ -144,13 +146,11 @@ jobs:
144146
shell: bash
145147
env:
146148
DOCKER_BUILDKIT: "1" # Enable Docker Buildkit
149+
PLATFORMS: linux/amd64,linux/arm64
147150
run: |
148151
echo "Building bundle"
149-
export IMG="${{ env.IMAGE_REPO }}:${{ env.OPERATOR_VERSION }}"
150-
export BUNDLE_IMG="${{ env.IMAGE_REPO }}-bundle:${{ env.OPERATOR_VERSION }}"
151-
make docker-build docker-push
152-
make bundle
153-
make bundle-build bundle-push
152+
make docker-buildx
153+
make bundle bundle-buildx
154154
155155
release:
156156
needs: [prepare, buildah, operator]
@@ -168,7 +168,8 @@ jobs:
168168
uses: requarks/changelog-action@v1.8.0
169169
with:
170170
token: ${{ github.token }}
171-
fromTag: ${{ env.current }}
171+
fromTag: ${{ github.ref_name }}
172+
toTag: ${{ env.current }}
172173
# Create a new release on GitHub with the semantic version number
173174
- name: Create Release
174175
uses: ncipollo/release-action@v1.12.0

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
bin
99
testbin/*
1010
Dockerfile.cross
11+
*.Dockerfile.cross
1112

1213
# Test binary, build with `go test -c`
1314
*.test

Makefile

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,10 @@ docker-push: ## Push docker image with the manager.
134134
# To properly provided solutions that supports more than one platform you should use this option.
135135
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
136136
.PHONY: docker-buildx
137-
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
137+
docker-buildx: test create-buildx ## Build and push docker image for the manager for cross-platform support
138138
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
139139
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
140-
- docker buildx create --name project-v3-builder
141-
docker buildx use project-v3-builder
142-
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross
143-
- docker buildx rm project-v3-builder
140+
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} --cache-to type=registry,ref=${IMAGE_TAG_BASE}:cache,oci-mediatypes=true,compression=zstd,mode=max --cache-from type=registry,ref=${IMAGE_TAG_BASE}:cache -f Dockerfile.cross .
144141
rm Dockerfile.cross
145142

146143
##@ Deployment
@@ -213,6 +210,22 @@ bundle-build: ## Build the bundle image.
213210
bundle-push: ## Push the bundle image.
214211
$(MAKE) docker-push IMG=$(BUNDLE_IMG)
215212

213+
.PHONY: bundle-buildx
214+
bundle-buildx: test create-buildx ## Build and push docker image for the manager for cross-platform support
215+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
216+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' bundle.Dockerfile > bundle.Dockerfile.cross
217+
- docker buildx build --push --platform=$(PLATFORMS) --tag ${BUNDLE_IMG} --cache-to type=registry,ref=${IMAGE_TAG_BASE}-bundle:cache,oci-mediatypes=true,compression=zstd,mode=max --cache-from type=registry,ref=${IMAGE_TAG_BASE}-bundle:cache -f bundle.Dockerfile.cross .
218+
rm bundle.Dockerfile.cross
219+
220+
.PHONY: create-buildx
221+
create-buildx: ## Create a buildx builder
222+
- docker buildx create --name project-v3-builder
223+
docker buildx use project-v3-builder
224+
225+
.PHONY: cleanup-buildx
226+
cleanup-buildx: ## Cleanup a buildx builder
227+
- docker buildx rm project-v3-builder
228+
216229
.PHONY: opm
217230
OPM = ./bin/opm
218231
opm: ## Download opm locally if necessary.

bundle.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
66
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
77
LABEL operators.operatorframework.io.bundle.package.v1=execdat-operator
88
LABEL operators.operatorframework.io.bundle.channels.v1=alpha
9-
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.28.1
9+
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.29.0
1010
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
1111
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v4-alpha
1212

bundle/metadata/annotations.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ annotations:
55
operators.operatorframework.io.bundle.metadata.v1: metadata/
66
operators.operatorframework.io.bundle.package.v1: execdat-operator
77
operators.operatorframework.io.bundle.channels.v1: alpha
8-
operators.operatorframework.io.metrics.builder: operator-sdk-v1.28.1
8+
operators.operatorframework.io.metrics.builder: operator-sdk-v1.29.0
99
operators.operatorframework.io.metrics.mediatype.v1: metrics+v1
1010
operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v4-alpha
1111

0 commit comments

Comments
 (0)