2018-11-08 10:56:11 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-08-05 18:17:59 +02:00
|
|
|
set -e
|
2021-08-05 18:06:43 +02:00
|
|
|
|
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
|
|
|
|
|
2022-02-15 18:23:59 +01:00
|
|
|
if [[ -z $1 ]] || [[ -z $2 ]]; then
|
2022-02-17 13:45:43 +01:00
|
|
|
echo "Usage: scripts/docker/build.sh [name] [tag] [/subimage]" 1>&2
|
2022-02-15 18:23:59 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-12-10 12:27:35 +01:00
|
|
|
NUMERIC='^[0-9]+$'
|
2021-12-12 20:34:57 +01:00
|
|
|
GOPROXY=${GOPROXY:-'https://proxy.golang.org,direct'}
|
2022-02-15 20:05:18 +01:00
|
|
|
DOCKER_TAG=$(date -u +%Y%m%d)
|
2021-12-09 18:48:44 +01:00
|
|
|
|
2022-02-17 13:45:43 +01:00
|
|
|
echo "docker/build: building photoprism/$1 from docker/${1/-//}$3/Dockerfile...";
|
|
|
|
|
2022-02-16 14:29:42 +01:00
|
|
|
if [[ $1 ]] && [[ -z $2 || $2 == "preview" ]]; then
|
2022-02-17 13:45:43 +01:00
|
|
|
echo "build tags: preview"
|
|
|
|
|
2021-12-09 18:48:44 +01:00
|
|
|
docker build \
|
2021-12-10 16:33:32 +01:00
|
|
|
--pull \
|
2022-02-16 16:24:45 +01:00
|
|
|
--no-cache \
|
2021-12-10 16:33:32 +01:00
|
|
|
--build-arg BUILD_TAG=$DOCKER_TAG \
|
2021-12-09 18:48:44 +01:00
|
|
|
--build-arg GOPROXY \
|
2021-12-10 09:09:21 +01:00
|
|
|
--build-arg GODEBUG \
|
2021-12-09 18:48:44 +01:00
|
|
|
-t photoprism/$1:preview \
|
2022-02-16 14:29:42 +01:00
|
|
|
-f docker/${1/-//}$3/Dockerfile .
|
2021-12-10 12:27:35 +01:00
|
|
|
elif [[ $2 =~ $NUMERIC ]]; then
|
2022-02-17 13:45:43 +01:00
|
|
|
echo "build tags: $2, latest"
|
2022-02-16 16:07:05 +01:00
|
|
|
|
|
|
|
if [[ $4 ]]; then
|
2022-02-17 13:45:43 +01:00
|
|
|
echo "build params: $4"
|
2022-02-16 16:07:05 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
docker build $4\
|
2021-12-10 16:33:32 +01:00
|
|
|
--pull \
|
2022-02-16 16:24:45 +01:00
|
|
|
--no-cache \
|
2021-12-09 18:48:44 +01:00
|
|
|
--build-arg BUILD_TAG=$2 \
|
|
|
|
--build-arg GOPROXY \
|
2021-12-10 09:09:21 +01:00
|
|
|
--build-arg GODEBUG \
|
2021-12-09 18:48:44 +01:00
|
|
|
-t photoprism/$1:latest \
|
|
|
|
-t photoprism/$1:$2 \
|
2022-02-16 14:29:42 +01:00
|
|
|
-f docker/${1/-//}$3/Dockerfile .
|
2022-02-15 20:05:18 +01:00
|
|
|
elif [[ $2 == *"preview"* ]]; then
|
2022-02-17 13:45:43 +01:00
|
|
|
echo "build tags: $2"
|
2022-02-16 16:07:05 +01:00
|
|
|
|
|
|
|
if [[ $4 ]]; then
|
2022-02-17 13:45:43 +01:00
|
|
|
echo "build params: $4"
|
2022-02-16 16:07:05 +01:00
|
|
|
fi
|
|
|
|
|
2022-02-15 20:05:18 +01:00
|
|
|
docker build $4\
|
|
|
|
--pull \
|
2022-02-16 16:24:45 +01:00
|
|
|
--no-cache \
|
2022-02-15 20:05:18 +01:00
|
|
|
--build-arg BUILD_TAG=$DOCKER_TAG \
|
|
|
|
--build-arg GOPROXY \
|
|
|
|
--build-arg GODEBUG \
|
|
|
|
-t photoprism/$1:$2 \
|
|
|
|
-f docker/${1/-//}$3/Dockerfile .
|
2021-12-10 12:27:35 +01:00
|
|
|
else
|
2022-02-17 13:45:43 +01:00
|
|
|
echo "build tags: $DOCKER_TAG-$2, $2"
|
2022-02-16 15:41:58 +01:00
|
|
|
|
2022-02-16 16:07:05 +01:00
|
|
|
if [[ $4 ]]; then
|
2022-02-17 13:45:43 +01:00
|
|
|
echo "build params: $4"
|
2022-02-16 15:41:58 +01:00
|
|
|
fi
|
|
|
|
|
2021-12-10 17:01:45 +01:00
|
|
|
docker build $4\
|
2021-12-10 16:33:32 +01:00
|
|
|
--pull \
|
2022-02-16 16:24:45 +01:00
|
|
|
--no-cache \
|
2021-12-10 16:33:32 +01:00
|
|
|
--build-arg BUILD_TAG=$DOCKER_TAG \
|
2021-12-10 12:27:35 +01:00
|
|
|
--build-arg GOPROXY \
|
|
|
|
--build-arg GODEBUG \
|
|
|
|
-t photoprism/$1:$2 \
|
2022-02-17 13:45:43 +01:00
|
|
|
-t photoprism/$1:$DOCKER_TAG-$2 \
|
2021-12-10 16:33:32 +01:00
|
|
|
-f docker/${1/-//}$3/Dockerfile .
|
2019-05-16 08:41:16 +02:00
|
|
|
fi
|
2022-02-15 18:23:59 +01:00
|
|
|
|
|
|
|
echo "docker/build: done"
|