2020-08-11 23:11:29 +00:00
|
|
|
#! /bin/bash
|
|
|
|
|
2021-08-06 01:59:48 +00:00
|
|
|
set -euxo pipefail
|
2020-08-11 23:11:29 +00:00
|
|
|
|
2021-08-06 01:59:48 +00:00
|
|
|
cd ${IMAGE_ROOT}
|
2021-08-06 02:13:51 +00:00
|
|
|
|
|
|
|
export CLEAN_TAG="$(echo "${CI_COMMIT_TAG:-${CI_COMMIT_REF_SLUG}}" | sed -r 's/[^-_a-zA-Z0-9\\.]/-/g')"
|
|
|
|
export IMAGE_TAG="${IMAGE_NAME}:${IMAGE_VERSION}-${CLEAN_TAG}"
|
2020-08-11 23:11:29 +00:00
|
|
|
|
2021-08-06 01:59:48 +00:00
|
|
|
# pull the previous image from the same branch or master to leverage its layers
|
|
|
|
docker pull docker.artifacts.apextoaster.com/${IMAGE_TAG} || \
|
|
|
|
docker pull docker.artifacts.apextoaster.com/"${IMAGE_NAME}:${IMAGE_VERSION}-master" || \
|
|
|
|
true # no existing image is not an error
|
2020-08-11 23:11:29 +00:00
|
|
|
|
2021-08-06 01:59:48 +00:00
|
|
|
# build and test a new image
|
|
|
|
docker build -t ${IMAGE_TAG} .
|
2020-08-11 23:11:29 +00:00
|
|
|
|
2021-08-06 01:59:48 +00:00
|
|
|
# prepare to push
|
|
|
|
function push_image() {
|
|
|
|
local PUSH_TAG="${1:-${IMAGE_TAG}}"
|
2020-08-11 23:11:29 +00:00
|
|
|
|
2021-08-06 01:59:48 +00:00
|
|
|
docker push ${PUSH_TAG} || true
|
|
|
|
docker tag ${PUSH_TAG} docker-push.artifacts.apextoaster.com/${PUSH_TAG}
|
|
|
|
docker push docker-push.artifacts.apextoaster.com/${PUSH_TAG}
|
2020-08-11 23:11:29 +00:00
|
|
|
|
2021-08-06 01:59:48 +00:00
|
|
|
if [[ "${CI_COMMIT_REF_SLUG}" == "master" ]];
|
|
|
|
then
|
|
|
|
docker tag ${PUSH_TAG} ${IMAGE_NAME}:${IMAGE_VERSION}
|
|
|
|
docker push ${IMAGE_NAME}:${IMAGE_VERSION}
|
|
|
|
|
|
|
|
docker tag ${IMAGE_NAME}:${IMAGE_VERSION} docker-push.artifacts.apextoaster.com/${IMAGE_NAME}:${IMAGE_VERSION}
|
|
|
|
docker push docker-push.artifacts.apextoaster.com/${IMAGE_NAME}:${IMAGE_VERSION}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# push under the normal tag
|
|
|
|
push_image "${IMAGE_TAG}"
|
|
|
|
|
|
|
|
# push under each alt tag
|
|
|
|
for alt_name in "${IMAGE_ALT:-}";
|
|
|
|
do
|
|
|
|
[[ -z "${alt_name}" ]] && continue
|
|
|
|
|
2021-08-06 02:20:19 +00:00
|
|
|
ALT_TAG="${alt_name}:${IMAGE_VERSION}-${CLEAN_TAG}"
|
2021-08-06 01:59:48 +00:00
|
|
|
docker tag ${IMAGE_TAG} ${ALT_TAG}
|
|
|
|
push_image "${ALT_TAG}"
|
|
|
|
done
|