#!/usr/bin/env bash

set -o errexit   # Fail script on errors
set -o nounset   # Fail on empty variables
set -o pipefail  # Error if error in pipe

# Directory of this file
__DIR__="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# St on Dockerhub but this and the CWD seem to be unreliable
DOCKERFILE_DIR="${__DIR__}/.."
# Set on DockerHub but set default value to use script locally
DOCKER_REPO="${DOCKER_REPO:-ecoleai/ci}"

for python_version in "3.6" "3.7" "3.8" "3.9" ; do

	# Default conda images
	docker build \
		--file "${DOCKERFILE_DIR}/Dockerfile.conda" \
		--build-arg python_version="${python_version}" \
		--tag "${DOCKER_REPO}-linux-conda-gcc-py${python_version}:${DOCKER_TAG:-latest}" "${DOCKERFILE_DIR}"

	# Source images with given compiler
	for compiler in "gcc9" "clang10" ; do
		docker build \
			--file "${DOCKERFILE_DIR}/Dockerfile.src" \
			--build-arg python_version="${python_version}" \
			--build-arg compiler="${compiler}" \
			--tag "${DOCKER_REPO}-linux-src-${compiler}-py${python_version}:${DOCKER_TAG:-latest}" "${DOCKERFILE_DIR}"
	done

done
