Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi Arch Support for Registry Operator #90

Merged
merged 9 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,33 @@ jobs:
operator-build:
name: Check operator container image build
runs-on: ubuntu-latest

env:
PUSH_IMAGE: false
johnmcollier marked this conversation as resolved.
Show resolved Hide resolved

steps:
-
name: Check out code into the Go module directory
- name: Check out code into the Go module directory
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
-
name: Check if operator docker build is working
run: docker build -f Dockerfile .

- name: Set up QEMU # Enables arm64 image building
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 #v3.0.0

- name: Check if operator docker build is working
run: make docker-buildx

operator-bundle-build:
name: Check operator bundle build
runs-on: ubuntu-latest

env:
PUSH_IMAGE: false

steps:
-
name: Check out code into the Go module directory
- name: Check out code into the Go module directory
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
-
name: Build the operator's bundle image
run: make bundle-build

- name: Set up QEMU # Enables arm64 image building
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 #v3.0.0

- name: Build the operator's bundle image
run: make docker-bundle-buildx
35 changes: 20 additions & 15 deletions .github/workflows/dockerimage-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,40 @@ on:
branches: [ main ]

jobs:

push-operator-image:
runs-on: ubuntu-latest
steps:
- name: Checkout registry-operator source code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Docker Build & Push - Registry Operator Image
uses: docker/build-push-action@3e7a4f6646880c6f63758d73ac32392d323eaf8f # v1.1.2

- name: Set up QEMU # Enables arm64 image building
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 #v3.0.0

- name: Login to Quay.io
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
registry: quay.io
repository: devfile/registry-operator
dockerfile: Dockerfile
tags: next
tag_with_sha: true

- name: Docker Buildx - Operator
run: "make docker-buildx"

push-operator-bundle:
runs-on: ubuntu-latest
steps:
- name: Checkout registry-operator source code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Build and push the Registry Operator Bundle to quay.io
uses: docker/build-push-action@3e7a4f6646880c6f63758d73ac32392d323eaf8f # v1.1.2

- name: Set up QEMU # Enables arm64 image building
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 #v3.0.0

- name: Login to Quay.io
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
registry: quay.io
repository: devfile/registry-operator-bundle
dockerfile: bundle.Dockerfile
tags: next
tag_with_sha: true

- name: Docker Buildx - Bundle
run: "make docker-bundle-buildx"
51 changes: 50 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ endif
# operator-sdk
OPERATOR_SDK_CLI ?= operator-sdk

# Controls whether the buildx command should include the push flag or not - Enables the testing of only the build portion without pushing
PUSH_IMAGE ?= true

# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
Expand Down Expand Up @@ -200,10 +202,57 @@ docker-buildx: test ## Build and push docker image for the manager for cross-pla
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- docker buildx create --name registry-operator-builder
docker buildx use registry-operator-builder
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross $(shell pwd)
$(MAKE) docker-buildx-helper
- docker buildx rm registry-operator-builder
rm Dockerfile.cross

# PRIVATE: Intended for internal use and is not meant to be called by a user
# This command helps control the flow for whether or not to push the multi-arch images or to only test the build
.PHONY: docker-buildx-helper
docker-buildx-helper:
ifeq ($(PUSH_IMAGE),true)
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} --provenance=false -f Dockerfile.cross $(shell pwd)
else
- docker buildx build --platform=$(PLATFORMS) --tag ${IMG} --provenance=false -f Dockerfile.cross $(shell pwd)
endif

# PRIVATE: Intended for internal use and is not meant to be called by a user
# This command helps control the flow for whether or not to push the multi-arch images or to only test the build
.PHONY: docker-bundle-buildx-helper
docker-bundle-buildx-helper:
ifeq ($(PUSH_IMAGE),true)
- docker buildx build --push --platform=${PLATFORMS} --tag ${BUNDLE_IMG} --provenance=false -f bundle.Dockerfile $(shell pwd)
else
- docker buildx build --platform=${PLATFORMS} --tag ${BUNDLE_IMG} --provenance=false -f bundle.Dockerfile $(shell pwd)
endif

# Build the bundle image.
.PHONY: docker-bundle-buildx
docker-bundle-buildx:
- docker buildx create --name bundle-builder
docker buildx use bundle-builder
$(MAKE) docker-bundle-buildx-helper
- docker buildx rm bundle-builder

# PRIVATE: Intended for internal use and is not meant to be called by a user
# This command helps control the flow for whether or not to push the multi-arch images or to only test the build
.PHONY: podman-buildx-helper
podman-buildx-helper:
ifeq ($(PUSH_IMAGE),true)
- podman manifest push ${IMG}
endif

# Clone of docker-buildx command but redesigned to work with podman's workflow
.PHONY: podman-buildx
podman-buildx: test ## Build and push podman 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
- podman manifest create ${IMG}
- podman build --platform=$(PLATFORMS) --manifest ${IMG} -f Dockerfile.cross $(shell pwd)
$(MAKE) podman-buildx-helper
- podman manifest rm ${IMG}
rm Dockerfile.cross

# Build the podman image
.PHONY: podman-build
podman-build:
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ The repository contains a Makefile; building and deploying can be configured via
| `ENVTEST` | Path to target `setup-envtest` binary | `${LOCALBIN}/setup-envtest` |
| `TARGET_ARCH` | Target architecture for operator manager builds, possible values: `amd64`, `arm64`, `s390x`, `ppc64le` | `amd64` |
| `TARGET_OS` | Target operating system for operator manager build, **only for `make manager`** | `linux` |
| `PUSH_IMAGE` | Controls whether or not `make docker-buildx`, `make docker-bundle-buildx` or `make podman-buildx` push to an external repository. If `false` they will only build. | `true` |
| `PLATFORMS` | Target architecture(s) for `make docker-buildx` | All supported: `linux/arm64,linux/amd64,linux/s390x,linux/ppc64le` |
| `KUSTOMIZE_INSTALL_SCRIPT` | URL of kustomize installation script, see [kustomize installation instructions](https://kubectl.docs.kubernetes.io/installation/kustomize/binaries/) | `https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh` |


Some of the rules supported by the makefile:

|rule|purpose|
Expand All @@ -108,7 +110,9 @@ Some of the rules supported by the makefile:
| kustomize | install the kustomize tool, used by other commands |
| docker-build | build registry operator container image using docker |
| docker-push | push registry operator container image using docker |
| docker-buildx | build & push registry operator docker image for all supported architectures |
| docker-buildx | build & push registry operator docker image for all supported architectures using docker|
| docker-bundle-buildx | build & push registry operator bundle docker image for all supported architectures using docker|
| podman-buildx | build & push registry operator docker image for all supported architectures using podman|
| podman-build | build registry operator container image using podman |
| podman-push | push registry operator container image using podman |
| deploy | deploy operator to cluster |
Expand Down
Loading