Skip to content

Commit

Permalink
Merge pull request #12 from msherif1234/update-base-image
Browse files Browse the repository at this point in the history
NETOBSERV-1618: use mutli arch base image for oc tool
  • Loading branch information
msherif1234 authored May 6, 2024
2 parents 0c77f07 + ef9f6b6 commit cbeea6a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 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 s390x
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
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
FROM quay.io/openshift/origin-must-gather:4.12.0 as builder

FROM quay.io/centos/centos:stream8
FROM quay.io/centos/centos:stream9

COPY --from=builder /usr/bin/oc /usr/bin/oc
RUN set -x; \
OC_TAR_URL="https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/clients/ocp/latest/openshift-client-linux.tar.gz" && \
curl -L -q -o /tmp/oc.tar.gz "$OC_TAR_URL" && \
tar -C /usr/bin/ -xvf /tmp/oc.tar.gz oc && \
ln -sf /usr/bin/oc /usr/bin/kubectl && \
rm -f /tmp/oc.tar.gz

# Copy all collection scripts to /usr/bin
COPY collection-scripts/* /usr/bin/
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 cbeea6a

Please sign in to comment.