build with different java version

This commit is contained in:
lucio 2024-03-12 11:50:13 +01:00
parent f7d4877e5c
commit e185fdde66
3 changed files with 43 additions and 14 deletions

View File

@ -1,4 +1,5 @@
FROM tomcat:10.1.19-jdk11-temurin-jammy ARG JAVA_VERSION=11
FROM tomcat:10.1.19-jdk$JAVA_VERSION-temurin-jammy
ARG filename=smartgears-distribution-4.0.0-SNAPSHOT ARG filename=smartgears-distribution-4.0.0-SNAPSHOT
ARG version=4.0.0-SNAPSHOT ARG version=4.0.0-SNAPSHOT
COPY ./target/$filename.tar.gz /smartgears-distro.tar.gz COPY ./target/$filename.tar.gz /smartgears-distro.tar.gz
@ -10,7 +11,7 @@ FROM tomcat:10.1.19-jdk11-temurin-jammy
RUN mv smartgears-distribution-$version smartgears-distribution RUN mv smartgears-distribution-$version smartgears-distribution
ENV GHN_HOME=./smartgears-distribution ENV GHN_HOME=./smartgears-distribution
RUN ./smartgears-distribution/install -s tomcat RUN ./smartgears-distribution/install -s tomcat
COPY exec/startContainer.sh /startContainer.sh COPY tomcat_files/startContainer.sh /startContainer.sh
RUN chmod +x /startContainer.sh RUN chmod +x /startContainer.sh
ENTRYPOINT ["/startContainer.sh"] ENTRYPOINT ["/startContainer.sh"]
CMD ["catalina.sh","run"] CMD ["catalina.sh","run"]

View File

@ -0,0 +1,16 @@
FROM tomcat:10.1.19-jdk11-temurin-jammy
ARG filename=smartgears-distribution-4.0.0-SNAPSHOT
ARG version=4.0.0-SNAPSHOT
COPY ./target/$filename.tar.gz /smartgears-distro.tar.gz
WORKDIR /
RUN tar zxvf /smartgears-distro.tar.gz
RUN rm /smartgears-distro.tar.gz
RUN export CATALINA_HOME=/usr/local/tomcat
RUN ln -s /usr/local/tomcat tomcat
RUN mv smartgears-distribution-$version smartgears-distribution
ENV GHN_HOME=./smartgears-distribution
RUN ./smartgears-distribution/install -s tomcat
COPY exec/startContainer.sh /startContainer.sh
RUN chmod +x /startContainer.sh
ENTRYPOINT ["/startContainer.sh"]
CMD ["catalina.sh","run"]

View File

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
accepted_java_versions=(11 17)
################################################################################ ################################################################################
# Help # # Help #
################################################################################ ################################################################################
@ -8,12 +10,14 @@ Help()
# Display Help # Display Help
echo "build and create docker image form smartgears distribution" echo "build and create docker image form smartgears distribution"
echo echo
echo "Syntax: buildDistribution [-g arg] [-p|u|h]" echo "Syntax: buildDistribution [-g arg] [-j arg] [-p|u|h]"
echo "options:" echo "options:"
echo "g arg specifies the maven goal {package, install, deploy etc} default is package." echo "-g arg specifies the maven goal {package, install, deploy etc} default is package."
echo "p build docker image for multiple platform (must be suppported by local docker agent)" echo "-j arg specify java version (default is 11)"
echo "u push image to dockerhub (with docker login already done)" echo " accepted version are: ${accepted_java_versions[@]}"
echo "h Print this Help." echo "-p build docker image for multiple platform (must be suppported by local docker agent)"
echo "-u push image to dockerhub (with docker login already done)"
echo "-h Print this Help."
echo echo
} }
@ -26,29 +30,35 @@ Help()
set -e set -e
image_version=4.0.0-SNAPSHOT-java11-tomcat10.1.19 smartgears_version=4.0.0-SNAPSHOT
java_version=11
tomcat_version=10.1.19
push=false push=false
while getopts g:puh flag while getopts g:j:puh flag
do do
case "${flag}" in case "${flag}" in
g) goal=${OPTARG};; g) goal=${OPTARG};;
p) platform=true ;; p) platform=true ;;
u) push=true ;; u) push=true ;;
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 h) Help
exit 0;; exit 0;;
*) echo "Invalid option" *) echo "Invalid option"
exit 1;; exit 1;;
esac esac
done done
echo "goal: $goal";
echo "platform: $platform"; image_version=${smartgears_version}-java${java_version}-tomcat${tomcat_version}
if [ -z $goal ]; then mvn clean package; else mvn clean ${goal}; fi if [ -z $goal ]; then mvn clean package; else mvn clean ${goal}; fi
if [ -z $platform ]; if [ -z $platform ];
then docker build -t smartgears-distribution:$image_version .; then docker build -t smartgears-distribution:$image_version --build-arg JAVA_VERSION=${java_version} .;
else docker build -t smartgears-distribution:$image_version --platform=linux/amd64,linux/arm64,linux/arm/v7 . ; else docker build -t smartgears-distribution:$image_version --build-arg JAVA_VERSION=${java_version} --platform=linux/amd64,linux/arm64,linux/arm/v7 . ;
fi fi
docker tag smartgears-distribution:$image_version d4science/smartgears-distribution:$image_version docker tag smartgears-distribution:$image_version d4science/smartgears-distribution:$image_version
@ -56,3 +66,5 @@ docker tag smartgears-distribution:$image_version d4science/smartgears-distribut
if [ ${push} = true ]; then if [ ${push} = true ]; then
docker push d4science/smartgears-distribution:$image_version; docker push d4science/smartgears-distribution:$image_version;
fi fi
echo "generated docker image ${image_version}"