#! /bin/bash

WORK_DIR="$(mktemp -d)"
ORGNAME="kontr2"
BASE_REPO="git@gitlab.fi.muni.cz:grp-kontr2"


function build_one()
{
    name=$1
    repo=$2
    path="$WORK_DIR/$name"
    echo "[BUILD] \"$name\": ${repo}"

    echo "[CLONE] \"$repo\" to \"$path\" "
    git clone --depth 1 "$repo" "$path"

    tag="$ORGNAME/$name"

    echo "[DOCKER] Building $tag"
    docker build "$path" --tag "$tag"

    echo "[DOCKER] Pushing $tag"
    docker push "$tag"
}


function build_portal_all()
{
    echo "[BUILD] All portal related images"
    build_one "portal"      "$BASE_REPO/portal.git"
    build_one "frontend"    "$BASE_REPO/portal-frontend.git"
}

function build_all()
{
    echo "[BUILD] All docker images"
    build_portal_all
}


build_all
