-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·74 lines (59 loc) · 1.73 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/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
echo "Usage: ${0##*/} [name] [linux/amd64|linux/arm64|linux/arm] [tag]" 1>&2
exit 1
fi
NUMERIC='^[0-9]+$'
BUILD_DATE=$(/bin/date -u +%y%m%d)
# Kill old builder if still alive.
echo "build: removing existing vision-docker-multibuilder..."
docker buildx rm vision-docker-multibuilder 2>/dev/null
# Wait for 3s.
sleep 3
# Create builder.
docker buildx create --name vision-docker-multibuilder --use || { echo 'failed'; exit 1; }
echo "Starting 'photoprism/vision-$1' multi-arch build based on $1/Dockerfile..."
echo "Build Arch: $2"
if [[ $1 ]] && [[ $2 ]] && [[ -z $3 ]]; then
echo "Build Tags: preview"
docker buildx build \
--platform $2 \
--pull \
--no-cache \
--build-arg BUILD_TAG=$BUILD_DATE \
-f $1/Dockerfile \
-t photoprism/vision-$1:preview \
--push $1
elif [[ $3 =~ $NUMERIC ]]; then
echo "Build Tags: $3, latest"
if [[ $4 ]]; then
echo "Build Params: $4"
fi
docker buildx build \
--platform $2 \
--pull \
--no-cache \
--build-arg BUILD_TAG=$3 \
-f $1/Dockerfile \
-t photoprism/vision-$1:latest \
-t photoprism/vision-$1:$3 $4 \
--push $1
else
echo "Build Tags: $3"
if [[ $4 ]]; then
echo "Build Params: $4"
fi
docker buildx build \
--platform $2 \
--pull \
--no-cache \
--build-arg BUILD_TAG=$BUILD_DATE \
-f $1/Dockerfile \
-t photoprism/vision-$1:$3 $4 \
--push $1
fi
echo "Removing vision-docker-multibuilder..."
docker buildx rm vision-docker-multibuilder
echo "Done."