2022-08-20 23:39:36 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2022-08-21 00:17:57 +02:00
|
|
|
base_tag=$REGISTRY/$SERVICE
|
|
|
|
tag="$base_tag:${COMMIT_SHA:0:10}"
|
|
|
|
latest_tag="$base_tag:latest"
|
2022-08-20 23:39:36 +02:00
|
|
|
|
|
|
|
if [[ -n $DEBUG ]]
|
|
|
|
then
|
|
|
|
echo "debug:"
|
|
|
|
echo " REGISTRY: $REGISTRY"
|
|
|
|
echo " SERVICE: $SERVICE"
|
|
|
|
echo " COMMIT_SHA: $COMMIT_SHA"
|
|
|
|
echo " TMP: $TMP"
|
|
|
|
fi
|
|
|
|
|
2022-08-21 00:05:10 +02:00
|
|
|
echo "docker: logging in"
|
|
|
|
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
|
|
|
|
|
2022-08-21 00:17:57 +02:00
|
|
|
export DOCKER_BUILDKIT=1
|
|
|
|
|
|
|
|
function build_target {
|
|
|
|
target=$1
|
|
|
|
echo "building $target"
|
|
|
|
latest_target_tag="$base_tag-$target:latest"
|
2022-08-21 00:34:55 +02:00
|
|
|
docker pull $latest_target_tag
|
2022-08-21 00:17:57 +02:00
|
|
|
docker build \
|
|
|
|
--target "$target" \
|
2022-08-21 00:26:37 +02:00
|
|
|
--tag "$latest_target_tag" \
|
2022-08-21 00:17:57 +02:00
|
|
|
--build-arg BUILDKIT_INLINE_CACHE=1 \
|
2022-08-21 00:25:26 +02:00
|
|
|
--cache-from $latest_target_tag \
|
2022-08-21 00:17:57 +02:00
|
|
|
--file "$TMP/build_release.Dockerfile" .
|
|
|
|
}
|
|
|
|
|
|
|
|
build_target "deps"
|
|
|
|
build_target "builder"
|
|
|
|
|
2022-08-21 00:25:26 +02:00
|
|
|
docker build \
|
|
|
|
-t "$tag" \
|
2022-08-21 00:28:50 +02:00
|
|
|
--cache-from "$base_tag-deps:latest" \
|
|
|
|
--cache-from "$base_tag-builder:latest" \
|
2022-08-21 00:25:26 +02:00
|
|
|
--build-arg BUILDKIT_INLINE_CACHE=1 \
|
|
|
|
--cache-from $latest_tag \
|
|
|
|
-f "$TMP/build_release.Dockerfile" .
|
2022-08-21 00:05:10 +02:00
|
|
|
docker tag "$tag" "$latest_tag"
|
2022-08-20 23:39:36 +02:00
|
|
|
|