#!/usr/bin/env bash

set -euo pipefail

current_directory="$(pwd)"


cleanup() {
    # restore the working directory
    cd ${current_directory}
}

trap cleanup EXIT

function filter_container_id() {
    tail -1 | awk '{ print $3 }'
}

cd ${ZOOX_WORKSPACE_ROOT}/web_apps/hwsd/hwsd_component
image="$(docker build . --build-arg PACKAGE_NAME=hwsd-component | filter_container_id)"
echo -e "Component image\t${image}"

cd ${ZOOX_WORKSPACE_ROOT}/web_apps/hwsd/hwsd_gateway
image="$(docker build . --build-arg PACKAGE_NAME=hwsd-gateway | filter_container_id)"
echo -e "Gateway image\t${image}"

cd ${ZOOX_WORKSPACE_ROOT}/web_apps/hwsd/hwsd_run
image="$(docker build . --build-arg PACKAGE_NAME=hwsd-run | filter_container_id)"
echo -e "Run image\t${image}"

cd ${ZOOX_WORKSPACE_ROOT}/web_apps/hwsd/hwsd_station
image="$(docker build . --build-arg PACKAGE_NAME=hwsd-station | filter_container_id)"
echo -e "Station image\t${image}"

cd ${ZOOX_WORKSPACE_ROOT}/web_apps/hwsd/hwsd_test
image="$(docker build . --build-arg PACKAGE_NAME=hwsd-test | filter_container_id)"
echo -e "Test image\t${image}"

cd ${current_directory}
