Skip to content

Commit

Permalink
Multi Arch Support for Registry Operator (#90)
Browse files Browse the repository at this point in the history
* add qemu to ci

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>

* update documentation

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>

* add environment variable for build only to ci

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>

* implement multi arch building and pushing

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>

* update ci for buildx commands

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>

* separate podman buildx to have build and push commands

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>

* break buildx into build and push commands

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>

* update workflows with new build and push commands

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>

* update documentation with new commands

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>

---------

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
  • Loading branch information
Jdubrick authored Jun 10, 2024
1 parent 91b7165 commit 1e66505
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 31 deletions.
26 changes: 16 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,27 @@ jobs:
operator-build:
name: Check operator container image build
runs-on: ubuntu-latest

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-build

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

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-build
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: Build and push Operator with Docker Buildx
run: "make docker-buildx-push"

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: Build and push bundle with Docker Buildx
run: "make docker-bundle-buildx-push"
65 changes: 60 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ endif
# operator-sdk
OPERATOR_SDK_CLI ?= operator-sdk


# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
Expand Down Expand Up @@ -194,16 +193,72 @@ docker-push:
# To properly provided solutions that supports more than one platform you should use this option.
# **docker-buildx does not work with podman**
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
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile

.PHONY: docker-buildx-build
docker-buildx-build: test
$(MAKE) docker-buildx-setup
- docker buildx build --platform=$(PLATFORMS) --tag ${IMG} --provenance=false -f Dockerfile.cross $(shell pwd)
$(MAKE) docker-buildx-cleanup

.PHONY: docker-buildx-push
docker-buildx-push: test
$(MAKE) docker-buildx-setup
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} --provenance=false -f Dockerfile.cross $(shell pwd)
$(MAKE) docker-buildx-cleanup

# INTERNAL: Used to setup the docker-buildx command, not to be called by users
.PHONY: docker-buildx-setup
docker-buildx-setup:
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)

# INTERNAL: Used to cleanup the docker-buildx command, not to be called by users
.PHONY: docker-buildx-cleanup
docker-buildx-cleanup:
- docker buildx rm registry-operator-builder
rm Dockerfile.cross

# Build the bundle image.
.PHONY: docker-bundle-buildx-build
docker-bundle-buildx-build:
$(MAKE) docker-bundle-buildx-setup
- docker buildx build --platform=${PLATFORMS} --tag ${BUNDLE_IMG} --provenance=false -f bundle.Dockerfile $(shell pwd)
$(MAKE) docker-bundle-buildx-cleanup

.PHONY: docker-bundle-buildx-push
docker-bundle-buildx-push:
$(MAKE) docker-bundle-buildx-setup
- docker buildx build --push --platform=${PLATFORMS} --tag ${BUNDLE_IMG} --provenance=false -f bundle.Dockerfile $(shell pwd)
$(MAKE) docker-bundle-buildx-cleanup

# INTERNAL: Used to setup the docker-bundle-buildx command, not to be called by users
.PHONY: docker-bundle-buildx-setup
docker-bundle-buildx-setup:
- docker buildx create --name bundle-builder
docker buildx use bundle-builder

# INTERNAL: Used to cleanup the docker-bundle-buildx command, not to be called by users
.PHONY: docker-bundle-buildx-cleanup
docker-bundle-buildx-cleanup:
- docker buildx rm bundle-builder

# Clone of docker-buildx command but redesigned to work with podman's workflow
# Designed to build and push multi architecture images of the registry operator
# This utilizes a new Dockerfile to insert platform args to preserve the original Dockerfile
.PHONY: podman-buildx-build
podman-buildx-build: test
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)

# Contains cleanup steps to remove files and manifests created during build
.PHONY: podman-buildx-push
podman-buildx-push:
- podman manifest push ${IMG}
- podman manifest rm ${IMG}
rm Dockerfile.cross

# Build the podman image
.PHONY: podman-build
podman-build:
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ The repository contains a Makefile; building and deploying can be configured via
| `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 +109,12 @@ 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 | build registry operator docker image for all supported architectures using docker|
| docker-buildx-push | build & push registry operator docker image for all supported architectures using docker|
| docker-bundle-buildx-build | build registry operator bundle docker image for all supported architectures using docker|
| docker-bundle-buildx-push | build & push registry operator bundle docker image for all supported architectures using docker|
| podman-buildx-build | build registry operator docker image for all supported architectures using podman|
| podman-buildx-push | 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

0 comments on commit 1e66505

Please sign in to comment.