diff --git a/build-multi-arch-image.sh b/build-multi-arch-image.sh new file mode 100755 index 000000000..72dc64888 --- /dev/null +++ b/build-multi-arch-image.sh @@ -0,0 +1,31 @@ +#!/bin/bash +set -xe +# "docker manifest" requires experimental feature enabled +export DOCKER_CLI_EXPERIMENTAL=enabled + +# ceph base image used for building multi architecture images +dockerfile="deploy/cephcsi/image/Dockerfile" +baseimg=$(awk -F = '/^ARG BASE_IMAGE=/ {print $NF}' "${dockerfile}") + +# get image digest per architecture +# { +# "arch": "amd64", +# "digest": "sha256:XXX" +# } +# { +# "arch": "arm64", +# "digest": "sha256:YYY" +# } +manifests=$(docker manifest inspect "${baseimg}" | jq '.manifests[] | {arch: .platform.architecture, digest: .digest}') +# qemu-user-static is to enable an execution of different multi-architecture containers by QEMU +# more info at https://github.com/multiarch/qemu-user-static +docker run --rm --privileged multiarch/qemu-user-static --reset -p yes +# build and push per arch images +for ARCH in amd64 arm64; do + ifs=$IFS + IFS= + digest=$(awk -v ARCH=${ARCH} '{if (archfound) {print $NF; exit 0}}; {archfound=($0 ~ "arch.*"ARCH)}' <<<"${manifests}") + IFS=$ifs + sed -i "s|\(^FROM.*\)${baseimg}.*$|\1${baseimg}@${digest}|" "${dockerfile}" + GOARCH=${ARCH} make image-cephcsi +done diff --git a/deploy.sh b/deploy.sh index 144bf90d4..1965dc332 100755 --- a/deploy.sh +++ b/deploy.sh @@ -45,9 +45,8 @@ build_push_images() { # "docker manifest" requires experimental feature enabled export DOCKER_CLI_EXPERIMENTAL=enabled - # get baseimg (ceph/ceph:tag) dockerfile="deploy/cephcsi/image/Dockerfile" - baseimg=$(awk 'NR==1{print $2}' "${dockerfile}") + baseimg=$(awk -F = '/^ARG BASE_IMAGE=/ {print $NF}' "${dockerfile}") # get image digest per architecture # { @@ -58,7 +57,9 @@ build_push_images() { # "arch": "arm64", # "digest": "sha256:YYY" # } - manifests=$("${CONTAINER_CMD:-docker}" manifest inspect "${baseimg}" | jq '.manifests[] | {arch: .platform.architecture, digest: .digest}') + manifests=$(docker manifest inspect "${baseimg}" | jq '.manifests[] | {arch: .platform.architecture, digest: .digest}') + # qemu-user-static is to enable an execution of different multi-architecture containers by QEMU + # more info at https://github.com/multiarch/qemu-user-static docker run --rm --privileged multiarch/qemu-user-static --reset -p yes # build and push per arch images for ARCH in amd64 arm64; do diff --git a/deploy/cephcsi/image/Dockerfile b/deploy/cephcsi/image/Dockerfile index 0d1fd8745..f73e85542 100644 --- a/deploy/cephcsi/image/Dockerfile +++ b/deploy/cephcsi/image/Dockerfile @@ -11,13 +11,13 @@ ARG GO_ARCH ARG SRC_DIR ARG GIT_COMMIT ARG GOROOT=/usr/local/go -RUN dnf install libcephfs-devel librados-devel librbd-devel /usr/bin/cc make -y RUN mkdir -p ${GOROOT} && \ curl https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-${GO_ARCH}.tar.gz | tar xzf - -C ${GOROOT} --strip-components=1 +RUN dnf install libcephfs-devel librados-devel librbd-devel /usr/bin/cc make -y -ENV GOROOT=$GOROOT \ +ENV GOROOT=${GOROOT} \ GOPATH=/go \ CGO_ENABLED=1 \ GIT_COMMIT="${GIT_COMMIT}" \ @@ -40,8 +40,8 @@ FROM ceph/ceph:v15 ARG SRC_DIR LABEL maintainers="Ceph-CSI Authors" \ - version=$CSI_IMAGE_VERSION \ - architecture=$GO_ARCH \ + version=${CSI_IMAGE_VERSION} \ + architecture=${GO_ARCH} \ description="Ceph-CSI Plugin" COPY --from=0 ${SRC_DIR}/_output/cephcsi /usr/local/bin/cephcsi