Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NETOBSERV-1618: use mutli arch base image for oc tool #12

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does docker buildx now allow building for one architecture at time and composing the final manifest-list image? The last time I used it, it was only capable of building and pushing together via docker buildx build --push --platforms linux/arm64,linux/amd64,....

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we been using this pattern on all netobserv repo


.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
Loading