diff --git a/.circleci/config.yml b/.circleci/config.yml index e07d67bd2f..c31da9f61f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -75,7 +75,7 @@ orbs: - build/_output - vendor - # Build job, which build operator docker image (with operator-sdk build) + # Build job, which builds the cross-platform operator docker image (with operator-sdk build) build-operator: <<: *params_operator <<: *job_operator @@ -97,13 +97,13 @@ orbs: - << parameters.operatorDir >>/build/_output - << parameters.operatorDir >>/vendor - deploy: - name: Push image to Docker Hub + name: Build & Push Operator Image to Github Container Registry command: | if [[ $(echo "$CIRCLE_BRANCH" | grep -c "pull") -gt 0 ]]; then - echo "This is a PR, we don't push to Hub." + echo "This is a PR, we don't push to GitHub." else docker login ghcr.io -u $GH_NAME --password $GH_TOKEN - make docker-push + make docker-buildx fi - save_cache: name: Save build artifacts in cache diff --git a/CHANGELOG.md b/CHANGELOG.md index a43a99e5e3..3149bb783f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Added +- [PR #218](https://github.com/konpyutaika/nifikop/pull/218) - **[Operator]** Add cross-platform support to nifikop docker image. - [PR #220](https://github.com/konpyutaika/nifikop/pull/220) - **[Operator/NifiCluster]** Made `Pod` readiness and liveness checks configurable. ### Changed diff --git a/Dockerfile b/Dockerfile index 546ab52635..5ea69f7a97 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,8 +17,12 @@ COPY controllers/ controllers/ COPY pkg/ pkg/ COPY version/ version/ -# Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go +# Build the operator +# TARGETARCH, TARGETOS are automatically set by docker. +# see: https://sdk.operatorframework.io/docs/advanced-topics/multi-arch/#manifest-lists +# see: https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/ +ARG TARGETOS TARGETARCH +RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -a -o manager main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/Makefile b/Makefile index 3f541da83c..8e3ea5ee96 100644 --- a/Makefile +++ b/Makefile @@ -137,14 +137,13 @@ docker-build: docker build -t $(REPOSITORY):$(VERSION) . .PHONY: build -build: manager manifests docker-build +build: manager manifests .PHONY: controller-gen controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. $(CONTROLLER_GEN): $(LOCALBIN) test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) - # Run go fmt against code .PHONY: fmt fmt: @@ -256,7 +255,11 @@ 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 project-v3-builder docker buildx use project-v3-builder - - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross +ifdef PUSHLATEST + - docker buildx build --push --platform=$(PLATFORMS) --tag $(REPOSITORY):$(VERSION) --tag $(REPOSITORY):latest -f Dockerfile.cross . +else + - docker buildx build --push --platform=$(PLATFORMS) --tag $(REPOSITORY):$(VERSION) -f Dockerfile.cross . +endif - docker buildx rm project-v3-builder rm Dockerfile.cross