#!/bin/bash
set -e

VERSION=${1:-latest}
TYPE=${2:-staging}

# export DOCKER_BUILDKIT=1
docker build \
    --build-arg LABEL_VERSION="$VERSION" \
    --build-arg LABEL_BUILD_DATE="$(date -R)" \
    -t "gitlab.inf.unibz.it:4567/commul/docker/clarin-dspace/$TYPE/dspace:$VERSION" . -f Dockerfile.dspace
docker build \
    --build-arg LABEL_VERSION="$VERSION" \
    --build-arg LABEL_BUILD_DATE="$(date -R)" \
    -t "gitlab.inf.unibz.it:4567/commul/docker/clarin-dspace/$TYPE/nginx:$VERSION" . -f Dockerfile.nginx
docker build \
    --build-arg LABEL_VERSION="$VERSION" \
    --build-arg LABEL_BUILD_DATE="$(date -R)" \
    -t "gitlab.inf.unibz.it:4567/commul/docker/clarin-dspace/$TYPE/postgres:$VERSION" . -f Dockerfile.postgres

docker push "gitlab.inf.unibz.it:4567/commul/docker/clarin-dspace/$TYPE/dspace:$VERSION"
docker push "gitlab.inf.unibz.it:4567/commul/docker/clarin-dspace/$TYPE/nginx:$VERSION"
docker push "gitlab.inf.unibz.it:4567/commul/docker/clarin-dspace/$TYPE/postgres:$VERSION"

echo sed ../kubernetes/*-deployment.yaml -e \"'s#\(.*image: gitlab.inf.unibz.it:4567/.*:\).*#\1'"${VERSION}#"\"
