Skip to content

Commit

Permalink
multiarch container image build
Browse files Browse the repository at this point in the history
Signed-off-by: Navid Yaghoobi <[email protected]>
  • Loading branch information
navidys committed Sep 23, 2023
1 parent d838d98 commit bd994b4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/build-and-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
branches:
- main

pull_request:


jobs:
build-and-publish:
name: Publish container image
Expand All @@ -28,7 +31,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
Expand All @@ -48,6 +54,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
Expand Down
12 changes: 7 additions & 5 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"

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
Expand Down
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bd994b4

Please sign in to comment.