#!/usr/bin/env bash # Build the match image. # # ./scripts/build.sh # tag from versions.env # IMAGE_TAG=dev ./scripts/build.sh # ./scripts/build.sh --no-cache # # Downloads land in a BuildKit cache mount, so the ~1.1GB of third-party # artifacts is fetched once per machine and reused by every later build. Note # --no-cache rebuilds every layer but does NOT empty the download cache. To drop # the downloads too: docker builder prune -f --filter type=exec.cachemount set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # shellcheck source=versions.env . "$ROOT/versions.env" cd "$ROOT" export DOCKER_BUILDKIT=1 # BUILD_REF comes from versions.env (it is part of the tag) and is also # recorded in an image label so a running task traces back to a commit. # # One tag, and it is the unique one. `latest` used to be applied here as a # `docker run` convenience, but this machine runs several agent sessions at # once and every build repointed `latest` under anyone else resolving it - # including scripts/arena.sh, whose --image selector accepts it. A moving tag # that several writers share is not a convenience. Use the printed tag, or # `scripts/image.sh` which resolves the newest local build by digest. IMAGE="${IMAGE_NAME}:${IMAGE_TAG}" echo "building $IMAGE (MegaMek $MEGAMEK_VERSION, Suramadu $SURAMADU_VERSION, ref $BUILD_REF)" docker build \ --build-arg "JDK_VERSION=$JDK_VERSION" \ --build-arg "JDK_URL_TAG=$JDK_URL_TAG" \ --build-arg "JDK_ARCHIVE=$JDK_ARCHIVE" \ --build-arg "JDK_SHA256=$JDK_SHA256" \ --build-arg "JDK_DIR=$JDK_DIR" \ --build-arg "JRE_MODULES=$JRE_MODULES" \ --build-arg "MEGAMEK_VERSION=$MEGAMEK_VERSION" \ --build-arg "MEGAMEK_RELEASE_DIR=$MEGAMEK_RELEASE_DIR" \ --build-arg "MEGAMEK_SRC_DIR=$MEGAMEK_SRC_DIR" \ --build-arg "MEGAMEK_RELEASE_SHA256=$MEGAMEK_RELEASE_SHA256" \ --build-arg "MEGAMEK_SRC_SHA256=$MEGAMEK_SRC_SHA256" \ --build-arg "SURAMADU_VERSION=$SURAMADU_VERSION" \ --build-arg "SURAMADU_WAR=$SURAMADU_WAR" \ --build-arg "SURAMADU_SHA256=$SURAMADU_SHA256" \ --build-arg "BUILD_REF=$BUILD_REF" \ --target runtime \ --tag "$IMAGE" \ "$@" \ . echo docker image inspect "$IMAGE" --format "built {{index .RepoTags 0}} {{.Size}} bytes"