#!/bin/bash
# The Docker Cloud config must pass in the BUILDS env variable.
# See README.md (in this dir) and the screenshot for more info.
# This is part of Application Builder.
# https://github.com/golift/application-builder

set -e -o pipefail

# This always run local to the Dockerfile folder, so the path is ../..
pushd ../..

source settings.sh

# Build each configured image from Docker Cloud.
for build in $BUILDS; do
  # os:name:arch
  os=$(echo $build | cut -d: -f1)
  name=$(echo $build | cut -d: -f2)
  echo "Building Image ${IMAGE_NAME}_${os}_${name}"
  docker build \
    --build-arg "ARCH=${name}" \
    --build-arg "BUILD_DATE=${DATE}" \
    --build-arg "COMMIT=${COMMIT}" \
    --build-arg "VERSION=${VERSION}-${ITERATION}" \
    --build-arg "LICENSE=${LICENSE}" \
    --build-arg "DESC=${DESC}" \
    --build-arg "VENDOR=${VENDOR}" \
    --build-arg "AUTHOR=${MAINT}" \
    --build-arg "BINARY=${BINARY}" \
    --build-arg "SOURCE_URL=${SOURCE_URL}" \
    --build-arg "CONFIG_FILE=${CONFIG_FILE}" \
    --tag "${IMAGE_NAME}_${os}_${name}" \
    --file ${DOCKERFILE_PATH} .
done

popd
