2024-03-05 14:45:39 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-03-12 11:49:06 +01:00
|
|
|
|
|
|
|
accepted_java_versions=(11 17)
|
|
|
|
|
2024-03-05 14:45:39 +01:00
|
|
|
################################################################################
|
|
|
|
# Help #
|
|
|
|
################################################################################
|
|
|
|
Help()
|
|
|
|
{
|
|
|
|
# Display Help
|
|
|
|
echo "build, create and run in docker the helloworld service"
|
|
|
|
echo
|
2024-03-12 11:49:06 +01:00
|
|
|
echo "Syntax: buildDistribution [-n arg] [-p arg] [-j arg] [-d arg?] [-h]"
|
2024-03-05 14:45:39 +01:00
|
|
|
echo "options:"
|
2024-03-12 11:49:06 +01:00
|
|
|
echo "-n arg specifies the docker image name (default is smartgears-helloworld)."
|
|
|
|
echo "-p arg specifies the port to be exposed for the docker container to access the service (default 8081)"
|
|
|
|
echo "-j arg specify java version (default is 11)"
|
|
|
|
echo " accepted version are: ${accepted_java_versions[@]}"
|
|
|
|
echo "-d arg? enable java debug mode"
|
|
|
|
echo " arg is the debug port (default is 5005)"
|
|
|
|
echo "-h Print this Help."
|
2024-03-05 14:45:39 +01:00
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
# Main program #
|
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
set -e
|
2024-02-27 12:45:01 +01:00
|
|
|
|
2024-03-12 11:49:06 +01:00
|
|
|
|
2024-02-27 12:45:01 +01:00
|
|
|
NAME=smartgears-helloworld
|
|
|
|
PORT=8081
|
2024-03-12 11:49:06 +01:00
|
|
|
DEBUG_PORT=5005
|
2024-03-05 14:45:39 +01:00
|
|
|
debug=false
|
2024-03-12 11:49:06 +01:00
|
|
|
compile=false
|
|
|
|
java_version=11
|
2024-03-05 14:45:39 +01:00
|
|
|
|
2024-03-12 11:49:06 +01:00
|
|
|
while getopts n:p:j:d?h flag
|
2024-03-05 14:45:39 +01:00
|
|
|
do
|
2024-03-12 11:49:06 +01:00
|
|
|
echo ${flag};
|
2024-03-05 14:45:39 +01:00
|
|
|
case "${flag}" in
|
|
|
|
n) NAME=${OPTARG};;
|
|
|
|
p) PORT=${OPTARG};;
|
2024-03-12 11:49:06 +01:00
|
|
|
d) debug=true && DEBUG_PORT=${OPTARG:-5005};;
|
|
|
|
j) if [[ ${accepted_java_versions[@]} =~ ${OPTARG} ]]
|
|
|
|
then java_version=${OPTARG};
|
|
|
|
else echo "Invalid java version" && echo "accepted version are: ${accepted_java_versions[@]}" && exit 1;
|
|
|
|
fi;;
|
|
|
|
h) Help && exit 0 ;;
|
|
|
|
*) echo "Invalid option" && exit 1 ;;
|
2024-03-05 14:45:39 +01:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
mvn clean package
|
2024-02-27 12:45:01 +01:00
|
|
|
|
2024-03-12 11:49:06 +01:00
|
|
|
docker build -t $NAME --build-arg JAVA_VERSION=${java_version} .
|
2024-03-05 14:45:39 +01:00
|
|
|
|
|
|
|
if [ $debug = false ] ; then
|
2024-03-12 11:49:06 +01:00
|
|
|
docker run -p $PORT:8080 $NAME
|
2024-03-05 14:45:39 +01:00
|
|
|
else
|
2024-03-12 11:49:06 +01:00
|
|
|
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
|
2024-03-05 14:45:39 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|