#!/bin/bash
#
# read required env variables
BASEDIR="$PWD"
source $BASEDIR/.env/ipdp-shared.properties
source $BASEDIR/.env/ipdp-db.properties
#
# docker login
echo "attempting to login to $artifactoryUrl"
docker login $artifactoryUrl -u $artifactoryUser -p $artifactoryPassword
# docker pull db image
echo "attempting to pull $artifactoryUrl/ipdp-db:$dbVersion"
docker pull $artifactoryUrl/ipdp-db:$dbVersion
#
# create employee self service specific docker network for $entityId
echo "attempting to create $entityId-ipdp-net docker network"
docker network create $entityId-ipdp-net
# docker run ipdp-db (data mounted as volume) connected to $entityId-ipdp-net docker network
echo "attempting to execute docker run command"
docker run --name $entityId-ipdp-db \
           --restart=unlipdp-stopped \
           --mount source=$entityId-ipdp-db,target=/var/lib/postgresql/data \
           --network $entityId-ipdp-net \
           -e POSTGRES_DB=ipdpdb \
           -e POSTGRES_PASSWORD=$dbPassword \
           -d $artifactUrl/ipdp-db:$dbVersion