added build image with java version selection

This commit is contained in:
lucio 2024-03-12 11:49:06 +01:00
parent c91ac3810b
commit feaac84e80
3 changed files with 30 additions and 17 deletions

View File

@ -1,4 +1,5 @@
FROM d4science/smartgears-distribution:4.0.0-SNAPSHOT-java11-tomcat10.1.19 ARG JAVA_VERSION=11
FROM d4science/smartgears-distribution:4.0.0-SNAPSHOT-java$JAVA_VERSION-tomcat10.1.19
COPY ./docker/logback.xml /etc/ COPY ./docker/logback.xml /etc/
COPY ./docker/container.ini /etc/ COPY ./docker/container.ini /etc/

View File

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

View File

@ -7,7 +7,7 @@
<logger name="org.gcube.service.helloworld" level="DEBUG" /> <logger name="org.gcube.service.helloworld" level="DEBUG" />
<logger name="org.gcube.smartgears" level="DEBUG" /> <logger name="org.gcube.smartgears" level="INFO" />
<root level="WARN"> <root level="WARN">
<appender-ref ref="STDOUT" /> <appender-ref ref="STDOUT" />