funky-framadate-front/kaniko-build.gitlab-ci.yml

61 lines
2.3 KiB
YAML
Raw Normal View History

# FROM https://gitlab.cern.ch/ci-tools/container-image-ci-templates/
# Defining the variables which can be overridden while using the template file in .gitlab-ci.yml
# REGISTRY_IMAGE_PATH: Defines where the image should be pushed to.
# CONTEXT_DIR: Defines the context dir for the image build
# DOCKER_FILE_NAME: Defines the name of the Dockerfile
# PUSH_IMAGE: If the gitlab step should push the built image
# BUILD_ARGS: The build-time variables
variables:
CONTEXT_DIR: ""
DOCKER_FILE_NAME: "Dockerfile"
GIT_SUBMODULE_STRATEGY: recursive
PUSH_IMAGE: "false"
BUILD_ARGS: ""
.kaniko_build:
stage: build
tags:
- docker
image:
# Using the official kaniko v1.6 image for the builds
name: gcr.io/kaniko-project/executor:v1.6.0-debug
entrypoint: [""]
script:
- |
if [ -z "${REGISTRY_IMAGE_PATH}" ]; then
echo "ERROR: CI variable REGISTRY_IMAGE_PATH is mandatory."
exit 1
fi
- REGISTRY=$(echo ${REGISTRY_IMAGE_PATH} | cut -d / -f 1)
- >
if [ -z "${CONTEXT_DIR}" ]; then
KANIKO_CONTEXT_DIR=${CI_PROJECT_DIR}
else
KANIKO_CONTEXT_DIR=${CI_PROJECT_DIR}/${CONTEXT_DIR}
fi
- mkdir -p /kaniko/.docker
- |
if [ -z "$DOCKER_AUTH_CONFIG" ]; then
# build the DOCKER_AUTH_CONFIG from user parameters as per https://docs.gitlab.com/ee/ci/docker/using_kaniko.html and internal docs
echo "{\"auths\":{\"${HARBOR_HOST}\":{\"auth\":\"$(printf "%s:%s" "${HARBOR_USERNAME}" "${HARBOR_PASSWORD}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json
else
echo "${DOCKER_AUTH_CONFIG}" > /kaniko/.docker/config.json
fi
# build and push the image to the path set in $REGISTRY_IMAGE_PATH variable.
- |
if [ "$(echo ${PUSH_IMAGE} | tr '[:upper:]' '[:lower:]')" = "true" ]; then
PUSH_IMAGE=""
else
echo "Info: defer pushing image to remote as PUSH_IMAGE is false"
PUSH_IMAGE="--no-push"
fi
- |
if [ -n "$BUILD_ARGS" ]; then
for arg in $BUILD_ARGS; do
KANIKO_BUILD_ARGS="${KANIKO_BUILD_ARGS} --build-arg ${arg}"
done
fi
- /kaniko/executor --context "${KANIKO_CONTEXT_DIR}" --dockerfile "${KANIKO_CONTEXT_DIR}/${DOCKER_FILE_NAME}" ${KANIKO_BUILD_ARGS} --destination "${REGISTRY_IMAGE_PATH}" "${PUSH_IMAGE}"