Skip to content

Commit

Permalink
Merge pull request #141 from navidys/multiarch_container_image
Browse files Browse the repository at this point in the history
multiarch container image build
  • Loading branch information
navidys authored Sep 24, 2023
2 parents d838d98 + a23184c commit f0a0ce6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 23 deletions.
41 changes: 23 additions & 18 deletions .github/workflows/build-and-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,29 +40,31 @@ jobs:
VERSION=$(grep 'VERSION=' VERSION | awk -F= '{print $2'})
REVISION=$(grep 'REVISION=' VERSION | awk -F= '{print $2'})
if [[ "${REVISION}" =~ "dev." ]] ; then
echo "develop"
echo "${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAMESPACE }}:develop"
else
echo "v${VERSION} latest"
echo "${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAMESPACE }}:v${VERSION},${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAMESPACE }}:latest"
fi
- name: Build container image
uses: redhat-actions/buildah-build@v2
id: build_image
with:
image: ${{ env.IMAGE_NAMESPACE }}
tags: "${{ steps.image_tag.outputs.IMAGE_TAG }}"
containerfiles: |
./Containerfile
- name: Set up qemu
uses: docker/setup-qemu-action@v3

- name: Set up buildx
uses: docker/setup-buildx-action@v3

- name: Publish container image
id: push_to_quay
uses: redhat-actions/push-to-registry@v2
- name: Login to Quay.io
uses: docker/login-action@v3
with:
image: ${{ steps.build_image.outputs.image }}
tags: ${{ steps.build_image.outputs.tags }}
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}

- name: Print image url
run: echo "Image pushed to ${{ steps.push_to_quay.outputs.registry-paths }}"
- name: Build container image
uses: docker/build-push-action@v5
id: build_image
with:
context: .
platforms: linux/amd64,linux/s390x,linux/ppc64le,linux/arm64,
push: true
provenance: false
file: "Containerfile"
tags: ${{ steps.image_tag.outputs.IMAGE_TAG }}
11 changes: 6 additions & 5 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
ARG ARCH="amd64"
ARG OS="linux"
FROM quay.io/prometheus/busybox-${OS}-${ARCH}:latest

FROM --platform=${TARGETPLATFORM} quay.io/prometheus/busybox-${TARGETOS}-${TARGETARCH}:latest
LABEL maintainer="Navid Yaghoobi <[email protected]>"

COPY ./bin/remote/prometheus-podman-exporter /bin/podman_exporter
ARG TARGETPLATFORM
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 f0a0ce6

Please sign in to comment.