#!/bin/bash -ex
# you must be logged into docker for the push to succeed.

#versuffix=${1:+_$1} # tag name must be lower case
versuffix=_qtio
tag=$(date -u +%Y%m%dT%H%M%SZ)

QT_VERSION=5.12.10
QT_VERSION_SHORT=${QT_VERSION//./}
QT_CI_PACKAGES="qt.qt5.${QT_VERSION_SHORT}.gcc_64,qt.qt5.${QT_VERSION_SHORT}.qtwebengine"
DOWNLOAD_URL=$(./qtci/find_qt_installer ${QT_VERSION})
INSTALLER=$(basename $DOWNLOAD_URL)
TMPDIR=$(mktemp -d)

cp Dockerfile${versuffix} $TMPDIR
cp ./qtci/extract-qt-installer ./qtci/qt-install.qs $TMPDIR
wget -nv -c -N -P $TMPDIR ${DOWNLOAD_URL}

docker build --pull --file Dockerfile${versuffix} \
             --target qt_install_prep \
             $TMPDIR
docker build --pull --file Dockerfile${versuffix} \
             --network none \
             --build-arg INSTALLER=${INSTALLER} \
             --build-arg QT_CI_PACKAGES=${QT_CI_PACKAGES} \
             --build-arg QT_VERSION=${QT_VERSION} \
             --target qt_install \
             $TMPDIR
docker build --pull --file Dockerfile${versuffix} \
             --build-arg INSTALLER=${INSTALLER} \
             --build-arg QT_CI_PACKAGES=${QT_CI_PACKAGES} \
             --build-arg QT_VERSION=${QT_VERSION} \
             --tag tsteven4/gpsbabel_build_environment${versuffix}:latest \
             --tag tsteven4/gpsbabel_build_environment${versuffix}:$tag \
             $TMPDIR
/bin/rm -fr $TMPDIR
docker push tsteven4/gpsbabel_build_environment${versuffix}:$tag
docker push tsteven4/gpsbabel_build_environment${versuffix}:latest
docker image ls
