70 lines
2.5 KiB
Bash
Executable File
70 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
accepted_java_versions=(11 17)
|
|
|
|
################################################################################
|
|
# Help #
|
|
################################################################################
|
|
Help()
|
|
{
|
|
# Display Help
|
|
echo "build and create docker image form smartgears distribution"
|
|
echo
|
|
echo "Syntax: buildDistribution [-g arg] [-j arg] [-p|u|h]"
|
|
echo "options:"
|
|
echo "-g arg specifies the maven goal {package, install, deploy etc} default is package."
|
|
echo "-j arg specify java version (default is 11)"
|
|
echo " accepted version are: ${accepted_java_versions[@]}"
|
|
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
|
|
}
|
|
|
|
################################################################################
|
|
################################################################################
|
|
# Main program #
|
|
################################################################################
|
|
################################################################################
|
|
|
|
|
|
set -e
|
|
|
|
smartgears_version=4.0.0-SNAPSHOT
|
|
java_version=11
|
|
tomcat_version=10.1.19
|
|
push=false
|
|
|
|
while getopts g:j:puh flag
|
|
do
|
|
case "${flag}" in
|
|
g) goal=${OPTARG};;
|
|
p) platform=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
|
|
exit 0;;
|
|
*) echo "Invalid option"
|
|
exit 1;;
|
|
esac
|
|
done
|
|
|
|
image_version=${smartgears_version}-java${java_version}-tomcat${tomcat_version}
|
|
|
|
if [ -z $goal ]; then mvn clean package; else mvn clean ${goal}; fi
|
|
|
|
if [ -z $platform ];
|
|
then docker build -t smartgears-distribution:$image_version --build-arg JAVA_VERSION=${java_version} .;
|
|
else docker build -t smartgears-distribution:$image_version --build-arg JAVA_VERSION=${java_version} --platform=linux/amd64,linux/arm64,linux/arm/v7 . ;
|
|
fi
|
|
|
|
docker tag smartgears-distribution:$image_version d4science/smartgears-distribution:$image_version
|
|
|
|
if [ ${push} = true ]; then
|
|
docker push d4science/smartgears-distribution:$image_version;
|
|
fi
|
|
|
|
echo "generated docker image ${image_version}" |