photoprism/scripts/docker/build.sh

71 lines
1.5 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -e
2021-04-20 06:55:52 +02:00
# see https://docs.docker.com/develop/develop-images/build_enhancements/#to-enable-buildkit-builds
export DOCKER_BUILDKIT=1
if [[ -z $1 ]] || [[ -z $2 ]]; then
echo "Usage: ${0##*/} [name] [tag] [/subimage]" 1>&2
exit 1
fi
NUMERIC='^[0-9]+$'
BUILD_DATE=$(/bin/date -u +%y%m%d)
2021-12-09 18:48:44 +01:00
2022-02-17 19:18:37 +01:00
echo "Building image 'photoprism/$1' from docker/${1/-//}$3/Dockerfile...";
if [[ $1 ]] && [[ -z $2 || $2 == "preview" ]]; then
2022-02-17 19:18:37 +01:00
echo "Build Tags: preview"
if [[ $4 ]]; then
echo "Build Params: $4"
fi
docker build $4\
--no-cache \
2022-02-17 19:18:37 +01:00
--build-arg BUILD_TAG=$BUILD_DATE \
2021-12-09 18:48:44 +01:00
-t photoprism/$1:preview \
-f docker/${1/-//}$3/Dockerfile .
elif [[ $2 =~ $NUMERIC ]]; then
2022-02-17 19:18:37 +01:00
echo "Build Tags: $2, latest"
if [[ $4 ]]; then
2022-02-17 19:18:37 +01:00
echo "Build Params: $4"
fi
docker build $4\
--no-cache \
2021-12-09 18:48:44 +01:00
--build-arg BUILD_TAG=$2 \
-t photoprism/$1:latest \
-t photoprism/$1:$2 \
-f docker/${1/-//}$3/Dockerfile .
2022-02-15 20:05:18 +01:00
elif [[ $2 == *"preview"* ]]; then
2022-02-17 19:18:37 +01:00
echo "Build Tags: $2"
if [[ $4 ]]; then
2022-02-17 19:18:37 +01:00
echo "Build Params: $4"
fi
2022-02-15 20:05:18 +01:00
docker build $4\
--no-cache \
2022-02-17 19:18:37 +01:00
--build-arg BUILD_TAG=$BUILD_DATE \
2022-02-15 20:05:18 +01:00
-t photoprism/$1:$2 \
-f docker/${1/-//}$3/Dockerfile .
else
2022-02-17 19:18:37 +01:00
echo "Build Tags: $BUILD_DATE-$2, $2"
if [[ $4 ]]; then
2022-02-17 19:18:37 +01:00
echo "Build Params: $4"
fi
docker build $4\
--no-cache \
--build-arg BUILD_TAG=$BUILD_DATE-$2 \
-t photoprism/$1:$2 \
2022-02-17 19:18:37 +01:00
-t photoprism/$1:$BUILD_DATE-$2 \
-f docker/${1/-//}$3/Dockerfile .
fi
2022-02-17 19:18:37 +01:00
echo "Done."