1
0
Fork 0
deploy-lock/scripts/image-build.sh

24 lines
672 B
Bash
Raw Normal View History

2023-01-01 04:13:14 +00:00
#! /bin/bash
IMAGE_PUSH="${1:---skip}"
IMAGE_NAME="${IMAGE_DEST}/${CI_PROJECT_PATH}"
IMAGE_TAG="$(echo "${CI_COMMIT_TAG:-${CI_COMMIT_REF_SLUG}}" | sed -r 's/[^-_a-zA-Z0-9\\.]/-/g')"
IMAGE_SHORT="${IMAGE_NAME}:${IMAGE_TAG}"
IMAGE_FULL="${IMAGE_NAME}:${IMAGE_TAG}"
echo "Loading last image: ${IMAGE_FULL}"
docker pull "${IMAGE_FULL}" || echo "Failed to load last image."
echo "Building image: ${IMAGE_FULL}"
docker build -f "${IMAGE_FILE}" -t "${IMAGE_FULL}" . || { echo "Failed to build image!"; exit 1; }
if [[ "${IMAGE_PUSH}" == "--push" ]];
then
echo "Pushing image: ${IMAGE_FULL}"
docker push "${IMAGE_FULL}" || { echo "Failed to push image!"; exit 1; }
fi