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

Publishing multiarch manifests for provider related container images #1

Open
wants to merge 9 commits into
base: k8s-1.28-provider-minimal
Choose a base branch
from
7 changes: 4 additions & 3 deletions cluster-provision/gocli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SHELL := /bin/bash
IMAGES_FILE ?= images.json
KUBEVIRTCI_IMAGE_REPO ?= quay.io/kubevirtci
GOARCH ?= $$(uname -m | grep -q s390x && echo s390x || echo amd64)
ARCH := $(shell uname -m | grep -q s390x && echo s390x || echo amd64)

export GO111MODULE=on
export GOPROXY=direct
Expand All @@ -28,11 +29,11 @@ fmt:

.PHONY: container
container: cli
docker build -t ${KUBEVIRTCI_IMAGE_REPO}/gocli build/
docker build -t ${KUBEVIRTCI_IMAGE_REPO}/gocli-${ARCH} build/

.PHONY: container-run
container-run: container
docker run ${KUBEVIRTCI_IMAGE_REPO}/gocli
docker run ${KUBEVIRTCI_IMAGE_REPO}/gocli-${ARCH}

.PHONY: vendor
vendor:
Expand All @@ -41,4 +42,4 @@ vendor:

.PHONY: push
push: container
docker push ${KUBEVIRTCI_IMAGE_REPO}/gocli
docker push ${KUBEVIRTCI_IMAGE_REPO}/gocli-${ARCH}
97 changes: 74 additions & 23 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#!/bin/bash

set -e
# Uncomment to run/debug in environment where docker is available instead of podman
#podman() {
# docker "$@"
#}

export KUBEVIRTCI_TAG=$(date +"%y%m%d%H%M")-$(git rev-parse --short HEAD)
archs=(amd64 s390x)
ARCH=$(uname -m | grep -q s390x && echo s390x || echo amd64)

export KUBEVIRTCI_TAG=${KUBEVIRTCI_TAG:-$(date +"%y%m%d%H%M")-$(git rev-parse --short HEAD)}
PREV_KUBEVIRTCI_TAG=$(curl -sL https://storage.googleapis.com/kubevirt-prow/release/kubevirt/kubevirtci/latest?ignoreCache=1)
BYPASS_PMAN=${BYPASS_PMAN:-false}
PHASES=${PHASES:-k8s}
Expand All @@ -27,7 +34,7 @@ function run_provision_manager() {
return
fi

json_result=$(${CRI_BIN} run --rm -v $(pwd):/workdir:Z quay.io/kubevirtci/gocli provision-manager)
json_result=$(${CRI_BIN} run --rm -v $(pwd):/workdir:Z quay.io/kubevirtci/gocli-${ARCH} provision-manager)
echo "INFO: Provision manager results: $json_result"

while IFS=":" read key value; do
Expand All @@ -44,7 +51,7 @@ function run_provision_manager() {

function build_gocli() {
(cd cluster-provision/gocli && make container)
${CRI_BIN} tag ${TARGET_REPO}/gocli ${TARGET_REPO}/gocli:${KUBEVIRTCI_TAG}
${CRI_BIN} tag ${TARGET_REPO}/gocli-${ARCH} ${TARGET_REPO}/gocli-${ARCH}:${KUBEVIRTCI_TAG}
}

function build_centos9_base_image_with_deps() {
Expand All @@ -54,45 +61,57 @@ function build_centos9_base_image_with_deps() {
}

function build_clusters() {
for i in ${IMAGES_TO_BUILD[@]}; do
echo "INFO: building $i"
cluster-provision/gocli/build/cli provision --phases k8s cluster-provision/k8s/$i
${CRI_BIN} tag ${TARGET_REPO}/k8s-$i ${TARGET_REPO}/k8s-$i:${KUBEVIRTCI_TAG}

cluster-provision/gocli/build/cli provision --phases k8s cluster-provision/k8s/$i --slim
${CRI_BIN} tag ${TARGET_REPO}/k8s-$i ${TARGET_REPO}/k8s-$i:${KUBEVIRTCI_TAG}-slim
for i in "${IMAGES_TO_BUILD[@]}"; do
if [ $ARCH != "s390x" ]; then
echo "INFO: building $i"
cluster-provision/gocli/build/cli provision --phases k8s cluster-provision/k8s/$i
${CRI_BIN} tag ${TARGET_REPO}/k8s-$i ${TARGET_REPO}/k8s-$i-${ARCH}:${KUBEVIRTCI_TAG}

cluster-provision/gocli/build/cli provision --phases k8s cluster-provision/k8s/$i --slim
${CRI_BIN} tag ${TARGET_REPO}/k8s-$i ${TARGET_REPO}/k8s-$i-${ARCH}:${KUBEVIRTCI_TAG}-slim
elif [ $ARCH == "s390x" ] && [ $i == "1.28" ]; then
echo "INFO: building $i slim"
cluster-provision/gocli/build/cli provision --phases k8s cluster-provision/k8s/$i --slim
${CRI_BIN} tag ${TARGET_REPO}/k8s-$i ${TARGET_REPO}/k8s-$i-${ARCH}:${KUBEVIRTCI_TAG}-slim
fi
done
}

function push_node_base_image() {
TARGET_IMAGE="${TARGET_REPO}/centos9:${KUBEVIRTCI_TAG}"
TARGET_IMAGE="${TARGET_REPO}/centos9-${ARCH}:${KUBEVIRTCI_TAG}"
podman tag ${TARGET_REPO}/centos9-base:latest ${TARGET_IMAGE}
echo "INFO: push $TARGET_IMAGE"
podman push ${TARGET_IMAGE}
echo ${TARGET_IMAGE} > cluster-provision/k8s/base-image
}

function push_cluster_images() {
for i in ${IMAGES_TO_BUILD[@]}; do
echo "INFO: push $i"
TARGET_IMAGE="${TARGET_REPO}/k8s-$i:${KUBEVIRTCI_TAG}"
podman push "$TARGET_IMAGE"

TARGET_IMAGE="${TARGET_REPO}/k8s-$i:${KUBEVIRTCI_TAG}-slim"
podman push "$TARGET_IMAGE"
for i in "${IMAGES_TO_BUILD[@]}"; do
if [ $ARCH != "s390x" ]; then
echo "INFO: push $i"
TARGET_IMAGE="${TARGET_REPO}/k8s-$i-${ARCH}:${KUBEVIRTCI_TAG}"
podman push "$TARGET_IMAGE"

TARGET_IMAGE="${TARGET_REPO}/k8s-$i-${ARCH}:${KUBEVIRTCI_TAG}-slim"
podman push "$TARGET_IMAGE"
elif [ $ARCH == "s390x" ] && [ $i == "1.28" ]; then
echo "INFO: push $i slim"
TARGET_IMAGE="${TARGET_REPO}/k8s-$i-${ARCH}:${KUBEVIRTCI_TAG}-slim"
podman push "$TARGET_IMAGE"
fi
done

# images that the change doesn't affect can be retagged from previous tag
for i in ${IMAGES_TO_RETAG[@]}; do
echo "INFO: retagging $i (previous tag $PREV_KUBEVIRTCI_TAG)"
skopeo copy "docker://${TARGET_REPO}/k8s-$i:${PREV_KUBEVIRTCI_TAG}" "docker://${TARGET_REPO}/k8s-$i:${KUBEVIRTCI_TAG}"
skopeo copy "docker://${TARGET_REPO}/k8s-$i:${PREV_KUBEVIRTCI_TAG}-slim" "docker://${TARGET_REPO}/k8s-$i:${KUBEVIRTCI_TAG}-slim"
skopeo copy "docker://${TARGET_REPO}/k8s-$i-${ARCH}:${PREV_KUBEVIRTCI_TAG}" "docker://${TARGET_REPO}/k8s-$i-${ARCH}:${KUBEVIRTCI_TAG}"
skopeo copy "docker://${TARGET_REPO}/k8s-$i-${ARCH}:${PREV_KUBEVIRTCI_TAG}-slim" "docker://${TARGET_REPO}/k8s-$i-${ARCH}:${KUBEVIRTCI_TAG}-slim"
done
}

function push_gocli() {
echo "INFO: push gocli"
TARGET_IMAGE="${TARGET_REPO}/gocli:${KUBEVIRTCI_TAG}"
echo "INFO: push gocli-${ARCH}"
TARGET_IMAGE="${TARGET_REPO}/gocli-${ARCH}:${KUBEVIRTCI_TAG}"
podman push "$TARGET_IMAGE"
}

Expand Down Expand Up @@ -137,16 +156,48 @@ function create_git_tag() {
git push ${TARGET_GIT_REMOTE} ${KUBEVIRTCI_TAG}
}

publish_manifest() {
local amend=""
local image_name="${1:?}"
local image_tag="${2:?}"
local full_image_name="${TARGET_REPO}/${image_name}:${image_tag}"
if [[ "$image_name" != "centos9" && "$image_name" != "gocli" && ! ( "$image_name" = "k8s-1.28" && "$image_tag" =~ "slim" ) ]]; then
unset 'archs[1]'
fi
for arch in ${archs[*]};do
amend+=" --amend ${TARGET_REPO}/${image_name}-${arch}:${image_tag}"
done
podman manifest create ${full_image_name} ${amend}
podman manifest push ${full_image_name} "docker://${full_image_name}"
}

function main() {
if [ "$PHASES" == "linux" ]; then
publish_node_base_image
if [ $ARCH != "s390x" ]; then
publish_manifest "centos9" $KUBEVIRTCI_TAG
echo "${TARGET_REPO}/centos9:${KUBEVIRTCI_TAG}" > cluster-provision/k8s/base-image
fi
exit 0
fi
build_gocli
run_provision_manager
publish_clusters
publish_alpine_container_disk
for i in "${IMAGES_TO_BUILD[@]}"; do
if [ $ARCH != "s390x" ]; then
echo "INFO: publish manifests of $i"
publish_manifest k8s-$i $KUBEVIRTCI_TAG
publish_manifest k8s-$i ${KUBEVIRTCI_TAG}-slim
fi
done
# Currently the underlying build tool alpine-make-vm-image supports only x86_64 and aarch64
if [ $ARCH != "s390x" ]; then
publish_alpine_container_disk
fi
push_gocli
if [ $ARCH != "s390x" ]; then
publish_manifest "gocli" $KUBEVIRTCI_TAG
fi
create_git_tag
}

Expand Down