diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 9e7842f3..f0c45d82 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -26,6 +26,9 @@ jobs: with: version: v0.7.1 + - name: Set up QEMU (for multi platform build) + uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2.2.0 + - name: ci/docker-login uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0 with: diff --git a/Dockerfile b/Dockerfile index bfe8e0c4..e1db4485 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,9 @@ ARG BASE_IMAGE=gcr.io/distroless/static:nonroot FROM ${BUILD_IMAGE} as builder +ARG TARGETARCH +ARG TARGETOS + WORKDIR /workspace COPY . . @@ -11,7 +14,7 @@ RUN mkdir -p licenses COPY LICENSE /workspace/licenses # Build -RUN make build +RUN make build TARGET_OS=$TARGETOS TARGET_ARCH=$TARGETARCH FROM ${BASE_IMAGE} diff --git a/Makefile b/Makefile index b7088e70..27a82c10 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,8 @@ MACHINE = $(shell uname -m) GOFLAGS ?= $(GOFLAGS:) -mod=vendor BUILD_TIME := $(shell date -u +%Y%m%d.%H%M%S) BUILD_HASH := $(shell git rev-parse HEAD) +TARGET_OS ?= linux +TARGET_ARCH ?= amd64 BUNDLE_IMG ?= controller-bundle:$(VERSION) # Default bundle image tag CRD_OPTIONS ?= "crd" # Image URL to use all building/pushing image targets @@ -119,7 +121,7 @@ goverall: $(GOVERALLS_GEN) ## Runs goveralls build: ## Build the mattermost-operator @echo Building Mattermost-operator - GO111MODULE=on GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GO) build $(GOFLAGS) -gcflags all=-trimpath=$(GOPATH) -asmflags all=-trimpath=$(GOPATH) -a -installsuffix cgo -o build/_output/bin/mattermost-operator $(GO_LINKER_FLAGS) ./main.go + GO111MODULE=on GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) CGO_ENABLED=0 $(GO) build $(GOFLAGS) -gcflags all=-trimpath=$(GOPATH) -asmflags all=-trimpath=$(GOPATH) -a -installsuffix cgo -o build/_output/bin/mattermost-operator $(GO_LINKER_FLAGS) ./main.go .PHONE: buildx-image buildx-image: ## Builds and pushes the docker image for mattermost-operator