2024-03-19 13:59:24 +01:00
|
|
|
#!/bin/bash
|
2024-02-26 18:02:00 +01:00
|
|
|
|
2024-03-19 13:59:24 +01:00
|
|
|
accepted_java_versions=(11 17)
|
|
|
|
|
|
|
|
NAME=identity-manager
|
|
|
|
PORT=8080
|
|
|
|
DEBUG_PORT=5005
|
|
|
|
DEBUG=false
|
|
|
|
COMPILE=true
|
|
|
|
java_version=11
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Help #
|
|
|
|
################################################################################
|
|
|
|
Help() {
|
|
|
|
# Display Help
|
|
|
|
echo "build, create and run in docker the identity manager service"
|
|
|
|
echo
|
|
|
|
echo "Syntax: buildDistribution [-n arg] [-p arg] [-j arg] [-d arg?] [-h]"
|
|
|
|
echo "options:"
|
|
|
|
echo "-s skip maven package"
|
|
|
|
echo "-n arg specifies the docker image name (default is identity-manager)."
|
|
|
|
echo "-p arg specifies the port to be exposed for the docker container to access the service (default $PORT)"
|
|
|
|
echo "-j arg specify java version (default is $java_version)"
|
|
|
|
echo " accepted version are: ${accepted_java_versions[@]}"
|
|
|
|
echo "-d arg? enable java debug mode"
|
|
|
|
echo " arg is the debug port (default is $DEBUG_PORT)"
|
|
|
|
echo "-h Print this Help."
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
# Main program #
|
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
OPTSTRING=":sn:p:d:j:?h"
|
|
|
|
|
|
|
|
while getopts $OPTSTRING opt; do
|
|
|
|
# echo "Option -${opt} was triggered, Argument: ${OPTARG}"
|
|
|
|
case "${opt}" in
|
2024-03-28 15:40:09 +01:00
|
|
|
s) COMPILE=false && echo "compile $COMPILE" ;;
|
|
|
|
n) NAME=${OPTARG} ;;
|
|
|
|
p) PORT=${OPTARG} ;;
|
|
|
|
d)
|
|
|
|
DEBUG=true
|
2024-03-19 13:59:24 +01:00
|
|
|
DEBUG_PORT=${OPTARG}
|
|
|
|
echo "debug enabled, port $DEBUG_PORT"
|
|
|
|
;;
|
2024-03-28 15:40:09 +01:00
|
|
|
j)
|
|
|
|
if [[ ${accepted_java_versions[@]} =~ ${OPTARG} ]]; then
|
2024-03-19 13:59:24 +01:00
|
|
|
java_version=${OPTARG}
|
|
|
|
else
|
|
|
|
echo "Invalid java version" && echo "accepted version are: ${accepted_java_versions[@]}" && exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
h) Help && exit 0 ;;
|
|
|
|
:) # matched when an option that is expected to have an argument is passed without one
|
2024-03-28 15:40:09 +01:00
|
|
|
if [ ${OPTARG} = "d" ]; then
|
2024-03-19 13:59:24 +01:00
|
|
|
DEBUG=true
|
|
|
|
echo "debug enabled, port $DEBUG_PORT"
|
2024-03-28 15:40:09 +01:00
|
|
|
else
|
2024-03-19 13:59:24 +01:00
|
|
|
# matched when an option that is expected to have an argument is passed without one
|
|
|
|
echo "Option -${OPTARG} requires an argument."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
?) # match any invalid option that is passed
|
|
|
|
echo "Invalid option: -${OPTARG}."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2024-03-28 15:40:09 +01:00
|
|
|
if [ $COMPILE = true ]; then
|
2024-03-19 13:59:24 +01:00
|
|
|
mvn clean package
|
|
|
|
else
|
|
|
|
echo "skipping mvn package"
|
|
|
|
fi
|
|
|
|
|
|
|
|
docker build -t $NAME --build-arg JAVA_VERSION=${java_version} .
|
|
|
|
|
|
|
|
if [ $DEBUG = false ]; then
|
|
|
|
docker run -p $PORT:8080 $NAME
|
|
|
|
else
|
|
|
|
docker run -p $PORT:8080 -p $DEBUG_PORT:5005 -e JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,address=*:5005,server=y,suspend=y" $NAME
|
|
|
|
fi
|