-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_docker_compose.sh
executable file
·68 lines (58 loc) · 1.91 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
#!/bin/bash
FOUND_PREBUILT_IMAGE=false
for SERVICE in $(docker compose config --services); do
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
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} $@
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} "$@"
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