#!/bin/sh

script="$( readlink -f "${0}" )"
script_dir="$( dirname "${script}" )"
repo_dir="$( readlink -f "${script_dir}/../.." )"

# get hugo feature version from devcontainer.json
dc_json_file="${repo_dir}/.devcontainer.json"
HUGO_VERSION=$( grep -A3 'features/hugo' "${dc_json_file}" | grep 'version' | sed -r 's/^.*"([^"]+)",?\s*$/\1/' )

# TODO add --push to publish to registry
# TODO change --tag value
docker buildx build \
    --pull \
    --file "${script_dir}/.publish/Dockerfile" \
    --build-arg "HUGO_VERSION=${HUGO_VERSION}" \
    --tag "localhost/hugo-site:latest" \
    --platform "linux/amd64" \
    "${repo_dir}"