Skip to content

Commit

Permalink
Merge pull request #7 from AustrianDataLAB/dev
Browse files Browse the repository at this point in the history
fix: build multiple architectures; use toTag and fromTag
  • Loading branch information
Sokadyn authored Jun 2, 2023
2 parents 220397b + 65ab8bb commit a3f293e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 21 deletions.
29 changes: 15 additions & 14 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# main.yml
name: Build and Release operator
run-name: Build/Release operator triggerd by ${{ github.actor }} - ${{ github.event.head_commit.message }}${{ github.event.pull_request.title }}
run-name: ${{ github.actor }} triggerd -> ${{ github.event.head_commit.message }}${{ github.event.pull_request.title }}

on:
push:
Expand Down Expand Up @@ -32,7 +32,7 @@ jobs:
if: ${{ github.event_name == 'push' || github.event.pull_request.merged == true }}
runs-on: ubuntu-latest
outputs:
IMAGE_REPO: ${{ steps.SET_IMAGE_REPO.outputs.IMAGE_REPO }}
IMAGE_TAG_BASE: ${{ steps.SET_IMAGE_TAG_BASE.outputs.IMAGE_TAG_BASE }}
OPERATOR_VERSION: ${{ steps.SET_OPERATOR_VERSION.outputs.OPERATOR_VERSION }}
IS_RELEASE: ${{ steps.SET_OPERATOR_VERSION.outputs.IS_RELEASE }}
current: ${{ steps.semver.outputs.current }}
Expand All @@ -43,9 +43,9 @@ jobs:

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

- name: Get Next Version
id: semver
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
docker:
image: docker:dind
env:
IMAGE_REPO: ${{ needs.prepare.outputs.IMAGE_REPO }}
IMAGE_TAG_BASE: ${{ needs.prepare.outputs.IMAGE_TAG_BASE }}
OPERATOR_VERSION: ${{ needs.prepare.outputs.OPERATOR_VERSION }}
steps:
- name: Set up QEMU
Expand All @@ -111,7 +111,7 @@ jobs:
platforms: linux/amd64,linux/arm64
file: "Dockerfile.buildah.k8s.rootless"
push: true
tags: ${{ env.IMAGE_REPO }}-buildah:${{ env.OPERATOR_VERSION }}
tags: ${{ env.IMAGE_TAG_BASE }}-buildah:${{ env.OPERATOR_VERSION }}

operator:
needs: prepare
Expand All @@ -121,8 +121,10 @@ jobs:
docker:
image: docker:dind
env:
IMAGE_REPO: ${{ needs.prepare.outputs.IMAGE_REPO }}
OPERATOR_VERSION: ${{ needs.prepare.outputs.OPERATOR_VERSION }}
IMAGE_TAG_BASE: ${{ needs.prepare.outputs.IMAGE_TAG_BASE }}
IMG: "${{ needs.prepare.outputs.IMAGE_TAG_BASE }}:${{ needs.prepare.outputs.OPERATOR_VERSION }}"
BUNDLE_IMG: "${{ needs.prepare.outputs.IMAGE_TAG_BASE }}-bundle:${{ needs.prepare.outputs.OPERATOR_VERSION }}"
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -144,13 +146,11 @@ jobs:
shell: bash
env:
DOCKER_BUILDKIT: "1" # Enable Docker Buildkit
PLATFORMS: linux/amd64,linux/arm64
run: |
echo "Building bundle"
export IMG="${{ env.IMAGE_REPO }}:${{ env.OPERATOR_VERSION }}"
export BUNDLE_IMG="${{ env.IMAGE_REPO }}-bundle:${{ env.OPERATOR_VERSION }}"
make docker-build docker-push
make bundle
make bundle-build bundle-push
make docker-buildx
make bundle bundle-buildx
release:
needs: [prepare, buildah, operator]
Expand All @@ -168,7 +168,8 @@ jobs:
uses: requarks/[email protected]
with:
token: ${{ github.token }}
fromTag: ${{ env.current }}
fromTag: ${{ github.ref_name }}
toTag: ${{ env.current }}
# Create a new release on GitHub with the semantic version number
- name: Create Release
uses: ncipollo/[email protected]
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
bin
testbin/*
Dockerfile.cross
*.Dockerfile.cross

# Test binary, build with `go test -c`
*.test
Expand Down
23 changes: 18 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,10 @@ docker-push: ## Push docker image with the manager.
# To properly provided solutions that supports more than one platform you should use this option.
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
.PHONY: docker-buildx
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
docker-buildx: test create-buildx ## Build and push docker image for the manager for cross-platform support
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- docker buildx create --name project-v3-builder
docker buildx use project-v3-builder
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross
- docker buildx rm project-v3-builder
- 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 .
rm Dockerfile.cross

##@ Deployment
Expand Down Expand Up @@ -213,6 +210,22 @@ bundle-build: ## Build the bundle image.
bundle-push: ## Push the bundle image.
$(MAKE) docker-push IMG=$(BUNDLE_IMG)

.PHONY: bundle-buildx
bundle-buildx: test create-buildx ## Build and push docker image for the manager for cross-platform support
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' bundle.Dockerfile > bundle.Dockerfile.cross
- 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 .
rm bundle.Dockerfile.cross

.PHONY: create-buildx
create-buildx: ## Create a buildx builder
- docker buildx create --name project-v3-builder
docker buildx use project-v3-builder

.PHONY: cleanup-buildx
cleanup-buildx: ## Cleanup a buildx builder
- docker buildx rm project-v3-builder

.PHONY: opm
OPM = ./bin/opm
opm: ## Download opm locally if necessary.
Expand Down
2 changes: 1 addition & 1 deletion bundle.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
LABEL operators.operatorframework.io.bundle.package.v1=execdat-operator
LABEL operators.operatorframework.io.bundle.channels.v1=alpha
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.28.1
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.29.0
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v4-alpha

Expand Down
2 changes: 1 addition & 1 deletion bundle/metadata/annotations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ annotations:
operators.operatorframework.io.bundle.metadata.v1: metadata/
operators.operatorframework.io.bundle.package.v1: execdat-operator
operators.operatorframework.io.bundle.channels.v1: alpha
operators.operatorframework.io.metrics.builder: operator-sdk-v1.28.1
operators.operatorframework.io.metrics.builder: operator-sdk-v1.29.0
operators.operatorframework.io.metrics.mediatype.v1: metrics+v1
operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v4-alpha

Expand Down

0 comments on commit a3f293e

Please sign in to comment.