#!/bin/bash

set -euo pipefail

SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# get date/time in local timezone, format YYYY.MMDD.HHMMSS
DATETIME=$(date +%Y.%m%d.%H%M%S)

"${SCRIPTDIR}/build.sh"

# iterate through the docker files in format Dockerfile.IMAGE_NAME
for dockerfile in Dockerfile.*
do
    # get the image name from the dockerfile
    image_name="${dockerfile//Dockerfile./}"
    # tag the image with the latest tag
    docker tag "$image_name:latest" "gitea.jde.nz/public/$image_name:latest"
    docker tag "$image_name:latest" "gitea.jde.nz/public/$image_name:$DATETIME"
    # push the image to the local docker registry
    docker push -a "gitea.jde.nz/public/$image_name"
done