2021-12-10 17:18:58 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# https://docs.docker.com/develop/develop-images/build_enhancements/#to-enable-buildkit-builds
|
|
|
|
export DOCKER_BUILDKIT=1
|
|
|
|
|
|
|
|
if [[ -z $1 ]] || [[ -z $2 ]]; then
|
2022-02-15 20:05:18 +01:00
|
|
|
echo "usage: scripts/docker/buildx-multi.sh [image] [linux/amd64|linux/arm64|linux/arm] [tag] [/subimage]" 1>&2
|
2021-12-10 17:18:58 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
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-10 17:18:58 +01:00
|
|
|
|
2022-02-16 14:29:42 +01:00
|
|
|
# kill old multi builder if still alive.
|
2022-02-15 18:23:59 +01:00
|
|
|
echo "docker/buildx-multi: removing existing multibuilder..."
|
|
|
|
docker buildx rm multibuilder 2>/dev/null
|
|
|
|
|
2022-02-16 15:41:58 +01:00
|
|
|
# wait 3 seconds.
|
|
|
|
sleep 3
|
2022-02-15 18:23:59 +01:00
|
|
|
|
2022-02-16 14:29:42 +01:00
|
|
|
# create new multibuilder.
|
2022-02-15 18:23:59 +01:00
|
|
|
docker buildx create --name multibuilder --use || { echo 'failed'; exit 1; }
|
|
|
|
|
2022-02-16 14:29:42 +01:00
|
|
|
if [[ $1 ]] && [[ $2 ]] && [[ -z $3 || $3 == "preview" ]]; then
|
|
|
|
echo "docker/buildx-multi: building photoprism/$1:preview from docker/${1/-//}$4/Dockerfile..."
|
2021-12-10 17:18:58 +01:00
|
|
|
docker buildx build \
|
|
|
|
--platform $2 \
|
|
|
|
--pull \
|
2021-12-13 00:23:24 +01:00
|
|
|
--no-cache \
|
2021-12-10 17:18:58 +01:00
|
|
|
--build-arg BUILD_TAG=$DOCKER_TAG \
|
|
|
|
--build-arg GOPROXY \
|
|
|
|
--build-arg GODEBUG \
|
2022-02-16 14:29:42 +01:00
|
|
|
-f docker/${1/-//}$4/Dockerfile \
|
2021-12-10 17:18:58 +01:00
|
|
|
-t photoprism/$1:preview \
|
|
|
|
--push .
|
|
|
|
elif [[ $3 =~ $NUMERIC ]]; then
|
2022-02-16 14:29:42 +01:00
|
|
|
echo "docker/buildx-multi: building photoprism/$1:$3,$1:latest from docker/${1/-//}$4/Dockerfile..."
|
2022-02-16 16:07:05 +01:00
|
|
|
|
|
|
|
if [[ $5 ]]; then
|
|
|
|
echo "extra params: $5"
|
|
|
|
fi
|
|
|
|
|
2021-12-10 17:18:58 +01:00
|
|
|
docker buildx build \
|
|
|
|
--platform $2 \
|
|
|
|
--pull \
|
2021-12-13 00:23:24 +01:00
|
|
|
--no-cache \
|
2021-12-10 17:18:58 +01:00
|
|
|
--build-arg BUILD_TAG=$3 \
|
|
|
|
--build-arg GOPROXY \
|
|
|
|
--build-arg GODEBUG \
|
2022-02-16 14:29:42 +01:00
|
|
|
-f docker/${1/-//}$4/Dockerfile \
|
2021-12-10 17:18:58 +01:00
|
|
|
-t photoprism/$1:latest \
|
2022-02-16 16:07:05 +01:00
|
|
|
-t photoprism/$1:$3 $5 \
|
2021-12-10 17:18:58 +01:00
|
|
|
--push .
|
2022-02-15 20:05:18 +01:00
|
|
|
elif [[ $4 ]] && [[ $3 == *"preview"* ]]; then
|
|
|
|
echo "docker/buildx-multi: building photoprism/$1:$3 from docker/${1/-//}$4/Dockerfile..."
|
2022-02-16 16:07:05 +01:00
|
|
|
|
|
|
|
if [[ $5 ]]; then
|
|
|
|
echo "extra params: $5"
|
|
|
|
fi
|
|
|
|
|
2022-02-15 20:05:18 +01:00
|
|
|
docker buildx build \
|
|
|
|
--platform $2 \
|
|
|
|
--pull \
|
|
|
|
--no-cache \
|
|
|
|
--build-arg BUILD_TAG=$DOCKER_TAG \
|
|
|
|
--build-arg GOPROXY \
|
|
|
|
--build-arg GODEBUG \
|
|
|
|
-f docker/${1/-//}$4/Dockerfile \
|
2022-02-16 16:07:05 +01:00
|
|
|
-t photoprism/$1:$3 $5 \
|
2022-02-15 20:05:18 +01:00
|
|
|
--push .
|
2022-02-13 16:25:59 +01:00
|
|
|
elif [[ $4 ]]; then
|
2022-02-15 20:05:18 +01:00
|
|
|
echo "docker/buildx-multi: building photoprism/$1:$3,$1:$DOCKER_TAG-$3 from docker/${1/-//}$4/Dockerfile..."
|
2022-02-16 15:41:58 +01:00
|
|
|
|
|
|
|
if [[ $5 ]]; then
|
|
|
|
echo "extra params: $5"
|
|
|
|
fi
|
|
|
|
|
2021-12-10 17:18:58 +01:00
|
|
|
docker buildx build \
|
|
|
|
--platform $2 \
|
|
|
|
--pull \
|
2021-12-13 00:23:24 +01:00
|
|
|
--no-cache \
|
2021-12-10 17:18:58 +01:00
|
|
|
--build-arg BUILD_TAG=$DOCKER_TAG \
|
|
|
|
--build-arg GOPROXY \
|
|
|
|
--build-arg GODEBUG \
|
|
|
|
-f docker/${1/-//}$4/Dockerfile \
|
|
|
|
-t photoprism/$1:$3 \
|
2022-02-16 15:41:58 +01:00
|
|
|
-t photoprism/$1:$DOCKER_TAG-$3 $5 \
|
2021-12-10 17:18:58 +01:00
|
|
|
--push .
|
2022-02-13 16:25:59 +01:00
|
|
|
else
|
2022-02-15 20:05:18 +01:00
|
|
|
echo "docker/buildx-multi: building photoprism/$1:$3 from docker/${1/-//}/Dockerfile..."
|
2022-02-13 16:25:59 +01:00
|
|
|
docker buildx build \
|
|
|
|
--platform $2 \
|
|
|
|
--pull \
|
|
|
|
--no-cache \
|
|
|
|
--build-arg BUILD_TAG=$DOCKER_TAG \
|
|
|
|
--build-arg GOPROXY \
|
|
|
|
--build-arg GODEBUG \
|
|
|
|
-f docker/${1/-//}/Dockerfile \
|
|
|
|
-t photoprism/$1:$3 \
|
|
|
|
--push .
|
2021-12-10 17:18:58 +01:00
|
|
|
fi
|
|
|
|
|
2022-02-15 18:23:59 +01:00
|
|
|
echo "docker/buildx-multi: removing multibuilder..."
|
|
|
|
docker buildx rm multibuilder
|
|
|
|
|
|
|
|
echo "docker/buildx-multi: done"
|