# Script to build the zrte docker image.

set -euo pipefail

if [[ $# != 2 ]]; then
    echo "Usage: $0 <Dockerfile> <name:tag>" >&2
    exit 1
fi

tmpdir=$(mktemp -d)

cleanup() {
    rm -rf "${tmpdir}"
}

trap "cleanup" EXIT

# Copy all the files in the build context to the temp dir because the bazel
# runfiles dir contains symlinks, which docker build ignores.
cp --dereference --recursive build/zrte/docker/context/* "${tmpdir}"

docker build -t $2 -f ${tmpdir}/$1 "${tmpdir}"
