Skip to content

Commit

Permalink
update GH actions and makefile to support multi arch
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <[email protected]>
  • Loading branch information
msherif1234 committed May 6, 2024
1 parent 566b7a1 commit 1a24c41
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build-push-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
REGISTRY_USERNAME: netobserv+github_ci
REGISTRY_PASSWORD: ${{ secrets.QUAY_SECRET }}
REGISTRY_NAMESPACE: netobserv
MULTIARCH_TARGETS: amd64 arm64 ppc64le
steps:
- name: Checkout the latest code
uses: actions/checkout@v2
Expand All @@ -24,7 +25,7 @@ jobs:
make lint MUST_GATHER_IMAGE=$REGISTRY_NAMESPACE/must-gather
- name: Build image
run: |
make image-build MUST_GATHER_IMAGE=$REGISTRY_NAMESPACE/must-gather
MULTIARCH_TARGETS="${{ env.MULTIARCH_TARGETS }}" make image-build MUST_GATHER_IMAGE=$REGISTRY_NAMESPACE/must-gather
- name: podman login to quay.io
uses: redhat-actions/podman-login@v1
with:
Expand All @@ -37,4 +38,4 @@ jobs:
- name: Push image
run: |
IMAGE_TAG=${{ env.short_sha }}
make build MUST_GATHER_IMAGE=$REGISTRY_NAMESPACE/must-gather
MULTIARCH_TARGETS="${{ env.MULTIARCH_TARGETS }}" make build MUST_GATHER_IMAGE=$REGISTRY_NAMESPACE/must-gather
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

FROM quay.io/centos/centos:stream8

RUN set -x; \
Expand Down
29 changes: 19 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true)
BUILD_VERSION := $(TAG:v%=%)

# Image building tool (docker / podman)
ifndef OCI_BIN
ifeq (,$(shell which podman 2>/dev/null))
OCI_BIN=docker
else
OCI_BIN=podman
endif
endif
# Image building tool (docker / podman) - docker is preferred in CI
OCI_BIN_PATH := $(shell which podman 2>/dev/null || which docker)
OCI_BIN ?= $(shell basename ${OCI_BIN_PATH})

# build a single arch target provided as argument
define build_target
echo 'building image for arch $(1)'; \
DOCKER_BUILDKIT=1 $(OCI_BIN) buildx build --load --platform "$(1)" --output plain -t ${IMAGE_REGISTRY}/${MUST_GATHER_IMAGE}-$(1):${IMAGE_TAG} -f Dockerfile .;
endef

# push a single arch target image
define push_target
echo 'pushing image ${IMAGE}-$(1)'; \
DOCKER_BUILDKIT=1 $(OCI_BIN) push ${IMAGE_REGISTRY}/${MUST_GATHER_IMAGE}-$(1):${IMAGE_TAG};
endef

# MUST_GATHER_IMAGE needs to be passed explicitly to avoid accidentally pushing to netobserv/must-gather
check-image-env: ## Check MUST_GATHER_IMAGE make sure its set.
Expand All @@ -34,12 +42,13 @@ endif

.PHONY: image-build
image-build: check-image-env ## Build NetObserv collection image.
$(OCI_BIN) build --build-arg BUILD_VERSION="${BUILD_VERSION}" -t ${IMAGE_REGISTRY}/${MUST_GATHER_IMAGE}:${IMAGE_TAG} .
trap 'exit' INT; \
$(foreach target,$(MULTIARCH_TARGETS),$(call build_target,$(target)))

.PHONY: image-push
image-push: check-image-env ## Push NetObserv collection image.
$(OCI_BIN) push ${IMAGE_REGISTRY}/${MUST_GATHER_IMAGE}:${IMAGE_TAG}

trap 'exit' INT; \
$(foreach target,$(MULTIARCH_TARGETS),$(call push_target,$(target)))

.PHONY: help
help: ## Display this help.
Expand Down

0 comments on commit 1a24c41

Please sign in to comment.