Fix Docker tox-bootstrapd hash update failing when using BuildKit

Docker is defaulting to using BuildKit for building images since version
23.0 (2023-02-01), which is not compatible with this script. The script
was fishing the hash of the intermediate build container in which the
build has failed, in order to run the sha256sum in that image, however
with BuildKit there are no longer any intermediate build containers,
which breaks the script.

The legacy builder is supposedly getting removed in a future version of
Docker, which is why we embrace BuildKit instead of reverting to the
legacy builder via DOCKER_BUILDKIT=0:

  $ DOCKER_BUILDKIT=0 docker build ...
  DEPRECATED: The legacy builder is deprecated and will be removed in a
              future release. BuildKit is currently disabled; enable it
              by removing the DOCKER_BUILDKIT=0 environment-variable.

While DOCKER_BUILDKIT=1 is unnecessary on Docker >= 23.0, it's needed
for anyone running older Docker, so it makes sense to have it in for
now, while everyone transitions.
This commit is contained in:
Maxim Biro 2023-12-01 22:42:20 -05:00
parent 7cfe35dff2
commit a030cdee5c
No known key found for this signature in database
GPG Key ID: AB3AD9896472BFA4

View File

@ -3,7 +3,7 @@
set -eux
docker_build() {
docker build -f other/bootstrap_daemon/docker/Dockerfile -t toxchat/bootstrap-node .
DOCKER_BUILDKIT=1 docker build --progress=plain -f other/bootstrap_daemon/docker/Dockerfile -t toxchat/bootstrap-node .
}
# Run Docker build once. If it succeeds, we're good.
@ -12,12 +12,11 @@ if docker_build; then
fi
# We're not good. Run it again, but now capture the output.
OUTPUT=$(docker_build || true 2>&1)
OUTPUT=$(docker_build 2>&1 || true)
if echo "$OUTPUT" | grep '/usr/local/bin/tox-bootstrapd: FAILED'; then
# This is a checksum warning, so we need to update it.
IMAGE=$(echo "$OUTPUT" | grep '^ ---> [0-9a-f]*$' | grep -o '[0-9a-f]*$' | tail -n1)
docker run --rm "$IMAGE" sha256sum /usr/local/bin/tox-bootstrapd >other/bootstrap_daemon/docker/tox-bootstrapd.sha256
echo "$OUTPUT" | grep -Eo '[0-9a-f]{64} /usr/local/bin/tox-bootstrapd' | tail -n1 >other/bootstrap_daemon/docker/tox-bootstrapd.sha256
fi
# Run once last time to complete the build.