diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 70b8fed..5f6e238 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/.github/workflows/dockerimage-push.yaml b/.github/workflows/dockerimage-push.yaml index 7c3a054..fcbf1e9 100644 --- a/.github/workflows/dockerimage-push.yaml +++ b/.github/workflows/dockerimage-push.yaml @@ -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" diff --git a/Makefile b/Makefile index ea4ef84..e40ec5b 100644 --- a/Makefile +++ b/Makefile @@ -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. @@ -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: diff --git a/README.md b/README.md index 5233994..08c2873 100644 --- a/README.md +++ b/README.md @@ -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| @@ -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 |