From 175fa4f6ad23ca11ccb92d23093cad1a42605734 Mon Sep 17 00:00:00 2001 From: Navid Yaghoobi Date: Sat, 23 Sep 2023 16:36:43 +1000 Subject: [PATCH] multiarch container image build Signed-off-by: Navid Yaghoobi --- .github/workflows/build-and-publish.yaml | 6 +++++- Containerfile | 12 +++++++----- Makefile | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-and-publish.yaml b/.github/workflows/build-and-publish.yaml index 51844421..ad1a8a12 100644 --- a/.github/workflows/build-and-publish.yaml +++ b/.github/workflows/build-and-publish.yaml @@ -28,7 +28,10 @@ jobs: - name: Build binary run: | - make binary-remote + make binary-remote-amd64 + make binary-remote-s390x + make binary-remote-ppc64le + make binary-remote-arm64 - name: Get image tags id: image_tag @@ -48,6 +51,7 @@ jobs: with: image: ${{ env.IMAGE_NAMESPACE }} tags: "${{ steps.image_tag.outputs.IMAGE_TAG }}" + platforms: linux/amd64,linux/s390x,linux/ppc64le,linux/arm64 containerfiles: | ./Containerfile diff --git a/Containerfile b/Containerfile index 5c60c6cd..b6c7bae5 100644 --- a/Containerfile +++ b/Containerfile @@ -1,10 +1,12 @@ -ARG ARCH="amd64" -ARG OS="linux" -FROM quay.io/prometheus/busybox-${OS}-${ARCH}:latest - +FROM --platform=${BUILDPLATFORM:-linux/amd64} quay.io/prometheus/busybox:latest LABEL maintainer="Navid Yaghoobi " -COPY ./bin/remote/prometheus-podman-exporter /bin/podman_exporter +ARG TARGETPLATFORM +ARG BUILDPLATFORM +ARG TARGETOS +ARG TARGETARCH + +COPY ./bin/remote/prometheus-podman-exporter-${TARGETARCH} /bin/podman_exporter EXPOSE 9882 USER nobody diff --git a/Makefile b/Makefile index ee07f87a..afe003fa 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,29 @@ binary-remote: ## Build prometheus-podman-exporter for remote connection @mkdir -p $(BIN)/remote @export CGO_ENABLED=0 && $(GO) build $(BUILDFLAGS) --tags "remote containers_image_openpgp" -ldflags="-X '$(PKG_PATH)/cmd.buildVersion=$(VERSION)' -X '$(PKG_PATH)/cmd.buildRevision=$(REVISION)' -X '$(PKG_PATH)/cmd.buildBranch=$(BRANCH)'" -o $(BIN)/remote/$(TARGET) +.PHONY: binary-remote-amd64 +binary-remote-amd64: ## Build amd64 prometheus-podman-exporter for remote connection + @mkdir -p $(BIN)/remote + @echo "building amd64" + @export CGO_ENABLED=0 && GOARCH=amd64 $(GO) build $(BUILDFLAGS) --tags "remote containers_image_openpgp" -ldflags="-X '$(PKG_PATH)/cmd.buildVersion=$(VERSION)' -X '$(PKG_PATH)/cmd.buildRevision=$(REVISION)' -X '$(PKG_PATH)/cmd.buildBranch=$(BRANCH)'" -o $(BIN)/remote/$(TARGET)-amd64 + +.PHONY: binary-remote-s390x +binary-remote-s390x: ## Build s390x prometheus-podman-exporter for remote connection + @mkdir -p $(BIN)/remote + @echo "building s390x" + @export CGO_ENABLED=0 && GOARCH=s390x $(GO) build $(BUILDFLAGS) --tags "remote containers_image_openpgp" -ldflags="-X '$(PKG_PATH)/cmd.buildVersion=$(VERSION)' -X '$(PKG_PATH)/cmd.buildRevision=$(REVISION)' -X '$(PKG_PATH)/cmd.buildBranch=$(BRANCH)'" -o $(BIN)/remote/$(TARGET)-s390x +.PHONY: binary-remote-ppc64le +binary-remote-ppc64le: ## Build ppc64le prometheus-podman-exporter for remote connection + @mkdir -p $(BIN)/remote + @echo "building ppc64le" + @export CGO_ENABLED=0 && GOARCH=ppc64le $(GO) build $(BUILDFLAGS) --tags "remote containers_image_openpgp" -ldflags="-X '$(PKG_PATH)/cmd.buildVersion=$(VERSION)' -X '$(PKG_PATH)/cmd.buildRevision=$(REVISION)' -X '$(PKG_PATH)/cmd.buildBranch=$(BRANCH)'" -o $(BIN)/remote/$(TARGET)-ppc64le + +.PHONY: binary-remote-arm64 +binary-remote-arm64: ## Build arm64 prometheus-podman-exporter for remote connection + @mkdir -p $(BIN)/remote + @echo "building arm64" + @export CGO_ENABLED=0 && GOARCH=arm64 $(GO) build $(BUILDFLAGS) --tags "remote containers_image_openpgp" -ldflags="-X '$(PKG_PATH)/cmd.buildVersion=$(VERSION)' -X '$(PKG_PATH)/cmd.buildRevision=$(REVISION)' -X '$(PKG_PATH)/cmd.buildBranch=$(BRANCH)'" -o $(BIN)/remote/$(TARGET)-arm64 .PHONY: $(TARGET) $(TARGET): $(SRC)