-
Notifications
You must be signed in to change notification settings - Fork 10
/
build_docker_compose.sh
executable file
路125 lines (106 loc) 路 3.44 KB
/
build_docker_compose.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
if [ '!' -d "configs/" ]; then
echo Configs not initialized
echo Copy base/template_configs to ./configs and set up base/config/config.sh and base/config/auth_users.json
echo See the guide for help: https://www.supernetworks.org/pages/docs/setup_run_spr
exit 1
fi
shopt -s expand_aliases
if ! which docker-compose > /dev/null 2>&1; then
# Set an alias for docker-compose if it's missing
alias docker-compose='docker compose'
fi
# remove prebuilt images
FOUND_PREBUILT_IMAGE=false
for SERVICE in $(docker-compose config --services); do
if [[ -z "$DO_CLEAN" ]]
then
break
fi
IS_PREBUILT=$(docker inspect \
--format '{{ index .Config.Labels "org.supernetworks.ci" }}' \
"ghcr.io/spr-networks/super_${SERVICE}" \
2>/dev/null || echo "false" \
)
if [ "$IS_PREBUILT" = "true" ]; then
IMAGE="ghcr.io/spr-networks/super_${SERVICE}"
echo "Removing prebuilt image ${IMAGE}"
docker image rm -f "$IMAGE"
FOUND_PREBUILT_IMAGE=true
fi
done
if [ "$FOUND_PREBUILT_IMAGE" = "true" ]; then
echo "Pruning dangling container images"
docker image prune -f
fi
# gen configs
if [ ! -f configs/dhcp/coredhcp.yml ]; then
./configs/scripts/gen_coredhcp_yaml.sh > configs/dhcp/coredhcp.yml
./configs/scripts/gen_watchdog.sh > configs/watchdog/watchdog.conf
fi
# set version
# NOTE if we rebuild a single container could still be old version
#git tag -l --sort=-creatordate | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 > ./version.txt
# make sure state directories and files exist
mkdir -p state/api/
mkdir -p state/dhcp/
mkdir -p state/dns/
mkdir -p state/wifi/
touch state/dns/local_mappings state/dhcp/leases.txt
PLUGINS="dyndns ppp wifi_uplink"
BUILDARGS=""
if [ -f .github_creds ]; then
BUILDARGS="--set *.args.GITHUB_CREDS=`cat .github_creds`"
fi
docker --help | grep buildx
missing_buildx=$?
if [ "$missing_buildx" -eq "1" ];
then
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
docker-compose build ${BUILDARGS} $@ || exit 1
for plugin in $PLUGINS
do
docker-compose --file ${plugin}/docker-compose.yml build ${BUILDARGS} || exit 1
done
else
# We use docker buildx so we can build multi-platform images. Unfortunately,
# a limitation is that multi-platform images cannot be loaded from the builder
# into Docker.
docker buildx create --name super-builder --driver docker-container \
2>/dev/null || true
# Look for any images that would be built multi-platform
IS_MULTIPLATFORM=$(
docker buildx bake \
--builder super-builder \
--file docker-compose.yml \
${BUILDARGS} "$@" \
--print --progress none \
| jq 'any(.target[].platforms//[]|map(split(",";"")[])|unique; length >= 2)'
)
# If this is a single-platform build, then by default load it into Docker
echo Is this a multi-platform build? ${IS_MULTIPLATFORM}
if [ "$IS_MULTIPLATFORM" = "false" ]; then
BUILDARGS="$BUILDARGS --load"
fi
docker buildx bake \
--builder super-builder \
--file docker-compose.yml \
${BUILDARGS} "$@" || exit 1
for plugin in $PLUGINS
do
pushd ${plugin}
docker buildx bake \
--builder super-builder \
--file docker-compose.yml \
${BUILDARGS} "$@" || exit 1
popd
done
fi
ret=$?
if [ "$ret" -ne "0" ]; then
echo "Tip: if the build failed to resolve domain names,"
echo "consider running ./base/docker_nftables_setup.sh"
echo "since iptables has been disabled for docker in the"
echo "SPR installer"
fi