#!/bin/bash
printf "> \e[1;37mBuilding docker-oracle-server-jre\e[0m\n\n"

PACKAGE="oracle-server-jre"

JAVA_MAJOR="8"
JAVA_VERSION="8u102"
JAVA_BUILD="8u102-b14"
JAVA_FULL_VERSION="1.8.0_102"
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
JAVA_TGZ_URL="http://download.oracle.com/otn-pub/java/jdk/$JAVA_BUILD/server-jre-$JAVA_VERSION-linux-x64.tar.gz"

set -e

printf "\n> 1. Building Debian-based Docker image\n\n"

docker build -t donbeave/$PACKAGE:$JAVA_VERSION \
    --build-arg java_major=$JAVA_MAJOR \
    --build-arg java_version=$JAVA_VERSION \
    --build-arg java_build=$JAVA_BUILD \
    --build-arg java_full_version=$JAVA_FULL_VERSION \
    --build-arg java_home=$JAVA_HOME \
    --build-arg java_tgz_url=$JAVA_TGZ_URL \
    .
docker tag donbeave/$PACKAGE:$JAVA_VERSION donbeave/$PACKAGE:latest

printf "\n> 2. Building Alpine-based Docker image\n\n"

docker build -t donbeave/${PACKAGE}:${JAVA_VERSION}-alpine \
    --build-arg java_major=$JAVA_MAJOR \
    --build-arg java_version=$JAVA_VERSION \
    --build-arg java_build=$JAVA_BUILD \
    --build-arg java_full_version=$JAVA_FULL_VERSION \
    --build-arg java_home=$JAVA_HOME \
    --build-arg java_tgz_url=$JAVA_TGZ_URL \
    -f Dockerfile-alpine .
docker tag donbeave/${PACKAGE}:${JAVA_VERSION}-alpine donbeave/$PACKAGE:alpine

printf "\n# Initializing Docker\n"

docker login --username=$DOCKER_USERNAME --password=$DOCKER_PASSWORD --email=$DOCKER_EMAIL

printf "> \e[1;37mPushing Docker images\e[0m\n"

docker push donbeave/$PACKAGE:$JAVA_VERSION
docker push donbeave/$PACKAGE:latest
docker push donbeave/${PACKAGE}:${JAVA_VERSION}-alpine
docker push donbeave/$PACKAGE:alpine
