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

117 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
######
# This script builds the docker image locally
# 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] [-t: version] [image type, see below] " 1>&2;
echo "This script builds framework docker images, the following options are available:" 1>&2;
echo " -h: This message" 1>&2;
echo " Image types (at least one, otherwise the script does nothing)" 1>&2;
echo " -a: All, same as ub" 1>&2;
echo " -u: Unit" 1>&2;
echo " -b: Base" 1>&2;
echo " -d: Debug" 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;
}
BASE_MODE=0
UNIT_MODE=0
DEBUG_MODE=0
TAG="local"
while getopts "t:hvaubd" o; do
case "${o}" in
b)
BASE_MODE=1
;;
u)
UNIT_MODE=1
;;
d)
DEBUG_MODE=1
;;
a)
BASE_MODE=1
UNIT_MODE=1
;;
t)
TAG=${OPTARG}
;;
v)
VERBOSE=1
;;
h)
usage
;;
*)
printerr "Unsupported option ${o}"
usage
;;
esac
done
cd ".."
# STANDARD MODE
if [[ $BASE_MODE -gt 0 ]]; then
DOCKERFILE=`mktemp -t dockerfile.XXXXX`
msg "Generating base dockerfile '$DOCKERFILE'"
OPTS="b"
if [[ $VERBOSE -eq 1 ]]; then
OPTS+="v"
fi
$DIR/generateDockerfile.sh -$OPTS -o $DOCKERFILE
msg "Building project image $TAG"
docker build -t $PROJECT_REPOSITORY/$PROJECT_GROUP/$PROJECT_BUILDNAME:$TAG -f $DOCKERFILE .
fi
# UNIT MODE
if [[ $UNIT_MODE -gt 0 ]]; then
DOCKERFILE=`mktemp -t dockerfile.XXXXX`
msg "Generating unit dockerfile '$DOCKERFILE'"
OPTS="u"
if [[ $VERBOSE -eq 1 ]]; then
OPTS+="v"
fi
$DIR/generateDockerfile.sh -$OPTS -o $DOCKERFILE
msg "Building project image $TAG"
docker build -t $PROJECT_REPOSITORY/$PROJECT_GROUP/$PROJECT_BUILDNAME:$TAG-unit -f $DOCKERFILE .
fi
# DEBUG MODE
if [[ $DEBUG_MODE -gt 0 ]]; then
DOCKERFILE=`mktemp -t dockerfile.XXXXX`
msg "Generating debug dockerfile '$DOCKERFILE'"
OPTS="d"
if [[ $VERBOSE -eq 1 ]]; then
OPTS+="v"
fi
$DIR/generateDockerfile.sh -$OPTS -o $DOCKERFILE
msg "Building project image $TAG"
docker build -t $PROJECT_REPOSITORY/$PROJECT_GROUP/$PROJECT_BUILDNAME:$TAG-debug -f $DOCKERFILE .
fi