#!/bin/bash -e if ! docker info &>/dev/null; then if [ -z "$DOCKER_HOST" ] && [ "$KUBERNETES_PORT" ]; then export DOCKER_HOST='tcp://localhost:2375' fi fi if [[ -n "$CI_REGISTRY" && -n "$CI_REGISTRY_USER" ]]; then echo "Logging to GitLab Container Registry with CI credentials..." echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin "$CI_REGISTRY" fi image_previous="$CI_APPLICATION_REPOSITORY:$CI_COMMIT_BEFORE_SHA" image_tagged="$CI_APPLICATION_REPOSITORY:$CI_APPLICATION_TAG" image_latest="$CI_APPLICATION_REPOSITORY:latest" # pull images for cache - this is required, otherwise --cache-from will not work docker image pull "$image_previous" || \ docker image pull "$image_latest" || \ true docker build \ --cache-from "$image_previous" \ --cache-from "$image_latest" \ --build-arg BUILDPACK_URL="$BUILDPACK_URL" \ --build-arg HTTP_PROXY="$HTTP_PROXY" \ --build-arg HTTPS_PROXY="$HTTPS_PROXY" \ --build-arg FTP_PROXY="$FTP_PROXY" \ --build-arg NO_PROXY="$NO_PROXY" \ --tag "$CI_APPLICATION_REPOSITORY:$CI_APPLICATION_TAG" \ --tag "$image_latest" . docker push "$image_tagged" docker push "$image_latest"