From b074a4987da50f8c03ad76b1a9eb59e4948fa62d Mon Sep 17 00:00:00 2001 From: Chaitanya Kandagatla Date: Mon, 8 Jul 2024 20:59:41 -0500 Subject: [PATCH] multi arch release images Signed-off-by: Chaitanya Kandagatla --- Makefile | 4 ++++ docker/Dockerfile | 19 +++++++++---------- hack/build_release_images.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 hack/build_release_images.sh diff --git a/Makefile b/Makefile index 658c37c0..ee1b77ac 100644 --- a/Makefile +++ b/Makefile @@ -63,3 +63,7 @@ clean: *-windows-amd64 \ *.sha256 \ $(NULL) + +.PHONY: build_release_images +build_release_images: + bash ./hack/build_release_images.sh diff --git a/docker/Dockerfile b/docker/Dockerfile index c8f9d112..c4e6357f 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,19 +1,18 @@ FROM registry.access.redhat.com/ubi9/go-toolset:latest AS builder - -WORKDIR /opt/app-root/src COPY . . - -#TODO Identify the full set of supported arch -#TODO Create a Make Target to build all supported release binaries -RUN go mod download -RUN go build -buildvcs=false -o ./releases/ocm ./cmd/ocm - +ENV GOFLAGS=-buildvcs=false +RUN git config --global --add safe.directory /opt/app-root/src && \ + make build_release_images FROM registry.access.redhat.com/ubi9/ubi-micro:latest -LABEL name="ocm-cli" LABEL description="OCM CLI" +LABEL io.k8s.description="OCM CLI" +LABEL com.redhat.component="ocm-cli" +LABEL distribution-scope="release" +LABEL name="ocm-cli" release="X.Y" url="https://github.com/openshift-online/ocm-cli" LABEL vendor="Red Hat, Inc." +LABEL version="X.Y" COPY LICENSE.txt /licenses -COPY --from=builder /opt/app-root/src/releases /releases \ No newline at end of file +COPY --from=builder /opt/app-root/src/releases /releases diff --git a/hack/build_release_images.sh b/hack/build_release_images.sh new file mode 100644 index 00000000..09d20cd7 --- /dev/null +++ b/hack/build_release_images.sh @@ -0,0 +1,30 @@ +#!/bin/bash +#This script invoked via a make target by the Dockerfile +#which builds a cli wrapper container that contains all release images + +#Keeping it similar to ROSA official releases which only publish amd64 to mirror +#This list can be modified as needed if additional os or arch support is needed +archs=(amd64) +oses=(darwin windows linux) + +REL_VER=$(git describe --tags --abbrev=0 | sed "s/v//") +mkdir -p releases + +build_release() { +for os in ${oses[@]} +do + for arch in ${archs[@]} + do + if [[ $os == "windows" ]]; then + extension=".exe" + fi + GOOS=${os} GOARCH=${arch} go build -o /tmp/ocm_${os}_${arch} ./cmd/ocm + mv /tmp/ocm_${os}_${arch} ocm_v${REL_VER}${extension} + zip releases/ocm_${REL_VER}_${os}_${arch}.zip ocm_v${REL_VER}${extension} + rm ocm_v${REL_VER}${extension} + done +done +cd releases && sha256sum *zip > ocm_${REL_VER}_SHA256SUMS +} + +build_release