Files
fdn2/scripts/generateComposeFolder.sh
T
2022-08-29 23:20:16 +02:00

94 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
######
# Generates dockerfiles
# It expects docker to be logged in to ECR (see aws-login)
set -e
VERBOSE=0
DIR=`dirname $(realpath "${BASH_SOURCE[0]}")`
OLDDIR=`pwd`
cd "$DIR"
source "$DIR/../config"
source "$DIR/libs.sh"
usage() {
echo "Usage: $0 [-h] [-v] [-dub] [-i: input, default] -o: output " 1>&2;
echo "This script builds framework docker images, the following options are available:" 1>&2;
echo " -h: This message" 1>&2;
echo " Environment" 1>&2;
echo " -l: Local" 1>&2;
echo " -L: Local Live" 1>&2;
echo " -s: Test" 1>&2;
echo " -p: Production" 1>&2;
echo " -i: Config Input File" 1>&2;
echo " -o: Output directory" 1>&2;
echo " -t: Project version, this will be used as base for the docker image tag (default: local)" 1>&2;
echo " -v: Verbose" 1>&2;
exit 1;
}
STARTING_FILE=""
CFGFILE="$DIR/../config"
OUT_DIRECTORY=""
SELECTED_MODES=0
while getopts "i:o:t:hvlLsp" o; do
case "${o}" in
l)
STARTING_FILE="$DIR/../cicd/docker-compose/local.yml"
SELECTED_MODES+=1
;;
L)
STARTING_FILE="$DIR/../cicd/docker-compose/local-live.yml"
SELECTED_MODES+=1
;;
s)
STARTING_FILE="$DIR/../cicd/docker-compose/test.yml"
SELECTED_MODES+=1
;;
p)
STARTING_FILE="$DIR/../cicd/docker-compose/production.yml"
SELECTED_MODES+=1
;;
i)
CFGFILE="${OLDDIR}/${OPTARG}"
;;
o)
OUT_DIRECTORY="${OPTARG}"
;;
t)
TAG=${OPTARG}
;;
v)
VERBOSE=1
;;
h)
usage
;;
*)
printerr "Unsupported option ${o}"
usage
;;
esac
done
if [[ $SELECTED_MODES -ne 1 ]]; then
printerr "Invalid mode"
usage
fi
if [[ $OUT_DIRECTORY == "" ]]; then
printerr "An output directory must be configured"
usage
fi
cp -r "$DIR/../cicd/environments" "$OUT_DIRECTORY/environments"
buildTemplate -f "$CFGFILE" -t "$STARTING_FILE" -o "$OUT_DIRECTORY/docker-compose.yml" --add TAG_NAME=$TAG