-
Notifications
You must be signed in to change notification settings - Fork 8
/
build
executable file
·86 lines (75 loc) · 2.1 KB
/
build
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
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
set -eu
# cd to location of script
cd "$(dirname "$(realpath "$0")")"
# Builds the docker images.
# Usage: ./build {COMPONENTS}, or just ./build to build all.
# The resulting images are named wubloader-COMPONENT.
# Pass PUSH=true to also push the resulting images, or PUSH=latest to push them as :latest tag
# The different images we can build
COMPONENTS=(
backfiller
bus_analyzer
buscribe
buscribe_api
chat_archiver
cutter
downloader
graphs
nginx
playlist_manager
postgres
restreamer
segment_coverage
sheetsync
thrimshim
)
# Define push if not already defined
PUSH=${PUSH:-}
# Base is the repository namespace information, not including the wubloader-component part.
BASE="ghcr.io/dbvideostriketeam"
# cache name is the name of the repository we store shared layer cache in
CACHE_NAME="$BASE/wubloader-cache"
# The docker image tag, derived from the git commit + whether working tree is clean
TAG=$(./get-build-tag)
if [ "$#" -gt 0 ]; then
COMPONENTS=("$@")
fi
# If CACHE is set, image layers will be pushed to the registry during the build,
# and re-use any layers from this cache instead of rebuilding them.
# You can set CACHE=readonly to only use the cache and not write to it (eg. due to permissions)
# Setting CACHE requires buildah be installed and configured, as this is used for the build instead of docker.
case "${CACHE:-}" in
"")
CACHE_ARGS=()
BUILD_CMD="docker"
;;
readonly)
CACHE_ARGS+=("--cache-from" "$CACHE_NAME")
BUILD_CMD="buildah"
;;
*)
CACHE_ARGS+=("--layers" "--cache-to" "$CACHE_NAME" "--cache-from" "$CACHE_NAME")
BUILD_CMD="buildah"
;;
esac
for component in "${COMPONENTS[@]}"; do
echo "Building image for $component"
latest="$BASE/wubloader-$component:latest"
specific="$BASE/wubloader-$component:$TAG"
"$BUILD_CMD" build \
-f "$component/Dockerfile" \
-t "$latest" \
-t "$specific" \
"${CACHE_ARGS[@]}" \
.
echo "Built image wubloader-$component:$TAG"
if [ -n "$PUSH" ]; then
echo "Pushing tag $specific"
"$BUILD_CMD" push "$specific"
fi
if [ "$PUSH" == "latest" ]; then
echo "Pushing tag $latest"
"$BUILD_CMD" push "$latest"
fi
done