beerday/scripts/build_release.sh
kjuulh 9cca1cfacc
Some checks failed
continuous-integration/drone/push Build is failing
added scripts
2022-08-26 08:20:37 +02:00

60 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
set -e
base_tag=$REGISTRY/$SERVICE
tag="$base_tag:${COMMIT_SHA:0:10}"
latest_tag="$base_tag:latest"
if [[ -n $DEBUG ]]
then
echo "debug:"
echo " REGISTRY: $REGISTRY"
echo " SERVICE: $SERVICE"
echo " COMMIT_SHA: $COMMIT_SHA"
echo " TMP: $TMP"
fi
echo "docker: logging in"
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
export DOCKER_BUILDKIT=1
function pull_target {
target=$1
echo "pulling $target"
latest_target_tag="$base_tag-$target:latest"
docker pull $latest_target_tag
}
function build_target {
target=$1
echo "building $target"
latest_target_tag="$base_tag-$target:latest"
docker build \
--target "$target" \
--tag "$latest_target_tag" \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from $latest_target_tag \
--file "$TMP/build_release.Dockerfile" .
}
pull_target "deps" &
pull_target "builder" &
wait
build_target "deps"
build_target "builder"
docker build \
-t "$tag" \
--cache-from "$base_tag-deps:latest" \
--cache-from "$base_tag-builder:latest" \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from $latest_tag \
-f "$TMP/build_release.Dockerfile" .
docker tag "$tag" "$latest_tag"