2018-03-09 16:00:53 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-06-08 05:53:35 +00:00
|
|
|
set -e
|
|
|
|
|
2020-04-24 07:56:24 +00:00
|
|
|
# shellcheck source=scripts/build_step.inc.sh
|
|
|
|
source "$(dirname "${0}")/scripts/build_step.inc.sh"
|
2021-06-08 08:44:32 +00:00
|
|
|
# shellcheck source=build.env
|
2020-12-09 12:12:14 +00:00
|
|
|
source "$(dirname "${0}")/build.env"
|
2020-04-24 07:56:24 +00:00
|
|
|
|
2021-06-08 05:53:35 +00:00
|
|
|
BRANCH_NAME=${BRANCH_NAME:-""}
|
|
|
|
GITHUB_TOKEN=${GITHUB_TOKEN:-""}
|
2021-06-10 10:49:54 +00:00
|
|
|
GITHUB_USER=${GITHUB_USER:-"autobuild-bot"}
|
|
|
|
GITHUB_EMAIL=${GITHUB_EMAIL:-"ceph-csi-bot@users.noreply.github.com"}
|
2019-02-21 04:30:57 +00:00
|
|
|
|
2019-11-07 09:55:12 +00:00
|
|
|
# Build and push images. Steps as below:
|
2020-06-22 13:54:18 +00:00
|
|
|
# 1. get base image from ./build.env (BASE_IMAGE=ceph/ceph:v14.2)
|
2023-11-03 09:17:23 +00:00
|
|
|
# 2. parse manifest to get image digest per arch (sha256:XYZ, sha256:ZYX)
|
|
|
|
# 3. patch Dockerfile with amd64 base image (FROM ceph/ceph:v14.2@sha256:XYZ)
|
2019-11-07 09:55:12 +00:00
|
|
|
# 4. build and push amd64 image
|
2023-11-03 09:17:23 +00:00
|
|
|
# 5. patch Dockerfile with arm64 base image (FROM ceph/ceph:v14.2@sha256:ZYX)
|
2019-11-07 09:55:12 +00:00
|
|
|
# 6. build and push arm64 image
|
|
|
|
build_push_images() {
|
|
|
|
# "docker manifest" requires experimental feature enabled
|
|
|
|
export DOCKER_CLI_EXPERIMENTAL=enabled
|
|
|
|
|
2020-06-22 13:54:18 +00:00
|
|
|
build_env="build.env"
|
|
|
|
baseimg=$(awk -F = '/^BASE_IMAGE=/ {print $NF}' "${build_env}")
|
2019-11-07 09:55:12 +00:00
|
|
|
|
|
|
|
# get image digest per architecture
|
|
|
|
# {
|
|
|
|
# "arch": "amd64",
|
2023-11-03 09:17:23 +00:00
|
|
|
# "digest": "sha256:XYZ"
|
2019-11-07 09:55:12 +00:00
|
|
|
# }
|
|
|
|
# {
|
|
|
|
# "arch": "arm64",
|
2023-11-03 09:17:23 +00:00
|
|
|
# "digest": "sha256:ZYX"
|
2019-11-07 09:55:12 +00:00
|
|
|
# }
|
2020-04-21 13:36:27 +00:00
|
|
|
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
|
2020-04-24 07:56:24 +00:00
|
|
|
build_step "docker run multiarch/qemu-user-static container"
|
2020-04-21 06:39:03 +00:00
|
|
|
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
|
2019-11-07 09:55:12 +00:00
|
|
|
# build and push per arch images
|
|
|
|
for ARCH in amd64 arm64; do
|
2020-01-20 11:28:30 +00:00
|
|
|
ifs=$IFS
|
|
|
|
IFS=
|
|
|
|
digest=$(awk -v ARCH=${ARCH} '{if (archfound) {print $NF; exit 0}}; {archfound=($0 ~ "arch.*"ARCH)}' <<<"${manifests}")
|
2019-11-07 09:55:12 +00:00
|
|
|
IFS=$ifs
|
2020-04-22 12:00:34 +00:00
|
|
|
base_image=${baseimg}@${digest}
|
2020-04-24 07:56:24 +00:00
|
|
|
build_step "make push-image-cephcsi for ${ARCH}"
|
2020-04-22 12:00:34 +00:00
|
|
|
GOARCH=${ARCH} BASE_IMAGE=${base_image} make push-image-cephcsi
|
2020-04-24 07:56:24 +00:00
|
|
|
build_step_log "done: make push-image-cephcsi for ${ARCH} (ret=${?})"
|
2020-07-16 06:03:06 +00:00
|
|
|
GOARCH=${ARCH} make create-manifest
|
2019-11-07 09:55:12 +00:00
|
|
|
done
|
2020-07-16 06:03:06 +00:00
|
|
|
make push-manifest
|
2019-11-07 09:55:12 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 05:53:35 +00:00
|
|
|
push_helm_charts() {
|
|
|
|
PACKAGE=$1
|
|
|
|
CHARTDIR=$2
|
|
|
|
VERSION=${CSI_IMAGE_VERSION//v/} # Set version (without v prefix)
|
2018-12-10 14:25:17 +00:00
|
|
|
|
2021-06-08 05:53:35 +00:00
|
|
|
# update information in Chart.yaml if the branch is not devel
|
|
|
|
if [ "${BRANCH_NAME}" != "devel" ]; then
|
|
|
|
# Replace appVersion: canary and version: *-canary with the actual version
|
2021-06-08 09:33:17 +00:00
|
|
|
sed -i "s/\(\s.*canary\)/ ${VERSION}/" "charts/ceph-csi-${PACKAGE}/Chart.yaml"
|
2020-07-16 11:30:10 +00:00
|
|
|
|
2021-06-08 09:33:17 +00:00
|
|
|
if [[ "${VERSION}" == *"canary"* ]]; then
|
2021-06-08 05:53:35 +00:00
|
|
|
# Replace devel with the version branch
|
2021-06-08 09:33:17 +00:00
|
|
|
sed -i "s/devel/${BRANCH_NAME}/" "charts/ceph-csi-${PACKAGE}/Chart.yaml"
|
2021-06-08 05:53:35 +00:00
|
|
|
else
|
|
|
|
# This is not a canary release, replace devel with the tagged branch
|
2021-06-08 09:33:17 +00:00
|
|
|
sed -i "s/devel/v${VERSION}/" "charts/ceph-csi-${PACKAGE}/templates/NOTES.txt"
|
|
|
|
sed -i "s/devel/v${VERSION}/" "charts/ceph-csi-${PACKAGE}/Chart.yaml"
|
2019-02-06 18:22:03 +00:00
|
|
|
|
2021-06-08 05:53:35 +00:00
|
|
|
fi
|
|
|
|
fi
|
2019-02-07 09:59:10 +00:00
|
|
|
|
2021-06-08 09:33:17 +00:00
|
|
|
mkdir -p "${CHARTDIR}/csi-charts/docs/${PACKAGE}"
|
2022-09-06 05:06:10 +00:00
|
|
|
# Use rsync to remove files from destination when source file is deleted.
|
|
|
|
rsync -avh "./charts/ceph-csi-${PACKAGE}" "${CHARTDIR}/csi-charts/docs/${PACKAGE}" --delete
|
2021-06-08 09:33:17 +00:00
|
|
|
pushd "${CHARTDIR}/csi-charts/docs/${PACKAGE}" >/dev/null
|
|
|
|
helm package "ceph-csi-${PACKAGE}"
|
2021-06-08 05:53:35 +00:00
|
|
|
popd >/dev/null
|
|
|
|
|
2021-06-08 09:33:17 +00:00
|
|
|
pushd "${CHARTDIR}/csi-charts/docs" >/dev/null
|
2021-06-08 05:53:35 +00:00
|
|
|
helm repo index .
|
2021-06-10 10:49:54 +00:00
|
|
|
git config user.name "${GITHUB_USER}"
|
|
|
|
git config user.email "${GITHUB_EMAIL}"
|
2021-06-08 09:33:17 +00:00
|
|
|
git add --all :/ && git commit -m "Update for helm charts ${PACKAGE}-${VERSION}"
|
|
|
|
git push https://"${GITHUB_TOKEN}"@github.com/ceph/csi-charts
|
2021-06-08 05:53:35 +00:00
|
|
|
popd >/dev/null
|
2019-11-07 09:55:12 +00:00
|
|
|
|
2021-06-08 05:53:35 +00:00
|
|
|
}
|
2020-04-24 08:59:09 +00:00
|
|
|
|
2021-06-08 05:53:35 +00:00
|
|
|
if [[ -z "${GITHUB_TOKEN}" ]]; then
|
|
|
|
echo "GITHUB_TOKEN is unset or set to the empty string"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-02-07 09:59:10 +00:00
|
|
|
|
2021-06-08 05:53:35 +00:00
|
|
|
build_push_images
|
2019-02-07 09:59:10 +00:00
|
|
|
|
2021-06-08 05:53:35 +00:00
|
|
|
CSI_CHARTS_DIR=$(mktemp -d)
|
2019-02-07 09:59:10 +00:00
|
|
|
|
2021-06-08 09:33:17 +00:00
|
|
|
pushd "${CSI_CHARTS_DIR}" >/dev/null
|
2019-02-06 18:22:03 +00:00
|
|
|
|
2023-05-22 07:30:40 +00:00
|
|
|
curl -L "${HELM_SCRIPT}" | bash -s -- --version "${HELM_VERSION}"
|
2020-04-24 08:59:09 +00:00
|
|
|
|
2021-06-08 05:53:35 +00:00
|
|
|
build_step "cloning ceph/csi-charts repository"
|
|
|
|
git clone https://github.com/ceph/csi-charts
|
|
|
|
|
|
|
|
mkdir -p csi-charts/docs
|
|
|
|
popd >/dev/null
|
|
|
|
|
|
|
|
build_step "pushing RBD helm charts"
|
2021-06-08 09:33:17 +00:00
|
|
|
push_helm_charts rbd "${CSI_CHARTS_DIR}"
|
2021-06-08 05:53:35 +00:00
|
|
|
build_step "pushing CephFS helm charts"
|
2021-06-08 09:33:17 +00:00
|
|
|
push_helm_charts cephfs "${CSI_CHARTS_DIR}"
|
2021-06-08 05:53:35 +00:00
|
|
|
build_step_log "finished deployment!"
|
|
|
|
|
|
|
|
[ -n "${CSI_CHARTS_DIR}" ] && rm -rf "${CSI_CHARTS_DIR}"
|