#!/bin/sh
# script/docker: build the Docker image tagged with the project name.
# Identical in all repos; the tag comes from script/projectname.
# Generic: needs no adaptation.
set -eu

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"

main() {
    cd "$ROOT"
    # Same CHECK_EPOCH contract as script/cibuild, for the same reason
    # and with the same bare-assignment and `$$` requirements -- see the
    # comments there. This script is not the CI gate, but a local build
    # is almost always warm, so without this it would report a green the
    # tree had not earned and the two entrypoints would disagree about
    # whether the tree is clean. The Dockerfile now refuses to build
    # without a non-empty value, so this is required, not optional.
    epoch="$(date +%s%N)$$"
    docker build --build-arg CHECK_EPOCH="$epoch" \
        -t "$("$SCRIPT_DIR/projectname")" .
}

main "$@"
