#!/usr/bin/env sh
set -e

: "${ARCHTAG:=latest}"

REVISION=$(git describe --long --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g')

RUNTIME_DEPS='bc bcprov curl decasify entr epubcheck fontconfig ghostscript git git-warp-time imagemagick inetutils sudo'\
' inkscape java-commons-lang jq kindlegen libertinus-font libgit2 m4 make mdbook moreutils nodejs'\
' pandoc-sile-git pcre pdftk podofo-tools poppler povray sassc sile sqlite'\
' texlive-binextra texlive-xetex texlive-formatsextra texlive-latexextra texlive-langenglish texlive-langother texlive-langcyrillic'\
' tex-gyre-fonts ttf-hack yq zint zola zsh'\
' lua lua-yaml lua-decasify'\
' luajit luarocks lua51-cldr lua51-colors-git lua51-cosmo lua51-decasify lua51-fluent lua51-lpeg lua51-luautf8 lua51-yaml'\
' perl perl-yaml perl-yaml-merge-simple'\
' python python-isbnlib python-deepl python-pandocfilters python-pantable python-ruamel-yaml python-usfm2osis-cw-git'\
' xcftools xorg-server-xvfb'
BUILD_DEPS='base-devel autoconf-archive cargo clang mold node-prune yarn'

: "${DOCKER_BUILDKIT:=1}"
export DOCKER_BUILDKIT

docker build \
	--build-arg ARCHTAG="$ARCHTAG" \
	--build-arg REVISION="$REVISION" \
	--build-arg VERSION="${1:-$REVISION}" \
	--build-arg RUNTIME_DEPS="$RUNTIME_DEPS" \
	--build-arg BUILD_DEPS="$BUILD_DEPS" \
	--tag $DOCKER_REPO:$DOCKER_TAG \
	./
