From 4df7bfa51e15c601cf81ab03ebb7efd8bcf74d4c Mon Sep 17 00:00:00 2001 From: Alfredo Oliviero Date: Mon, 27 May 2024 16:04:24 +0200 Subject: [PATCH] scripts dockerize --- Dockerfile | 10 +++++++--- dockerize/buildImageAndStart.sh | 31 +++++++++++++++---------------- dockerize/build_conf | 4 ++-- dockerize/push_docker.sh | 12 ++++++++++++ 4 files changed, 36 insertions(+), 21 deletions(-) create mode 100755 dockerize/push_docker.sh diff --git a/Dockerfile b/Dockerfile index f53cebc..2e9e8a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,11 +7,15 @@ # -f Dockerfile \ # $PLATFORMS . -ARG JAVA_VERSION -ARG SMARTGEARS_VERSION +# ARG JAVA_VERSION +# ARG SMARTGEARS_VERSION +# ARG TOMCAT_VERSION + +ARG SMARTGEAR_IMAGE #FROM d4science/smartgears-distribution:${SMARTGEARS_VERSION}-java${JAVA_VERSION}-tomcat10.1.19 -FROM hub.dev.d4science.org/gcube/smartgears-distribution:${SMARTGEARS_VERSION}-java${JAVA_VERSION}-tomcat10.1.19 +# FROM hub.dev.d4science.org/gcube/smartgears-distribution:${SMARTGEARS_VERSION}-java${JAVA_VERSION}-tomcat{TOMCAT_VERSION} +FROM ${SMARTGEAR_IMAGE} ARG CONTAINER_INI="./dockerize/configuration/container.ini" ARG MVN_FINALNAME ARG MVN_NAME diff --git a/dockerize/buildImageAndStart.sh b/dockerize/buildImageAndStart.sh index 3a06d1d..6a435f1 100755 --- a/dockerize/buildImageAndStart.sh +++ b/dockerize/buildImageAndStart.sh @@ -32,19 +32,19 @@ Help() { echo "-e execute the docker image" echo "-g arg specifies the maven [g]oals {package, install, deploy etc} default is $GOAL." echo "-d arg? enable java debug mode for execution" + echo " arg is the debug port (default is $DEBUG_PORT)" echo "-r push image to d4science harbo[r] (with login already done, or -l to login)" echo "-u p[u]sh image to dockerhub (with docker login already done)" echo "-p arg specifies the port to be exposed for the docker container to access the service (default $PORT)" - echo "-c arg path of the file to deploy as container.ini (default ./docker/container.ini)" + echo "-c arg path of the file to deploy as container.ini (default ./docker/container.ini)" - echo "-j arg specify java version (default is $JAVA_VERSION)" - echo " accepted version are: ${ACCEPTED_JAVA_VERSIONs[@]}" - echo " arg is the debug port (default is $DEBUG_PORT)" + # echo "-j arg specify java version (default is $JAVA_VERSION)" + # echo " accepted version are: ${ACCEPTED_JAVA_VERSIONs[@]}" - echo "-s skip maven package" + echo "-s skip maven execution" echo "-t exec also maven tests" echo "-n arg specifies the docker image name (default is $MVN_NAME)." @@ -67,8 +67,8 @@ Help() { set -e -#OPTSTRING=":sn:p:d:j:?h" -OPTSTRING=":c:n:p:g:d:?jsmulrteh" +#OPTSTRING=":c:n:p:g:d:?jsmulrteh" +OPTSTRING=":c:n:p:g:d:?smulrteh" while getopts $OPTSTRING opt; do # echo "Option -${opt} was triggered, Argument: ${OPTARG}" @@ -94,13 +94,13 @@ while getopts $OPTSTRING opt; do DEBUG_PORT=${OPTARG} echo "debug enabled, port $DEBUG_PORT, execute $EXECUTE" ;; - 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 - ;; + # 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 ;; :) @@ -147,8 +147,7 @@ echo "DOCKER_BUILD_NAME: $DOCKER_BUILD_NAME" --build-arg="MVN_FINALNAME=$MVN_FINALNAME" \ --build-arg="MVN_NAME=${MVN_NAME}" \ --build-arg="CONTAINER_INI=${CONTAINER_INI}" \ - --build-arg="JAVA_VERSION=${JAVA_VERSION}" \ - --build-arg="SMARTGEARS_VERSION=${SMARTGEARS_VERSION}" \ + --build-arg="SMARTGEAR_IMAGE=${SMARTGEAR_IMAGE}" \ -f Dockerfile \ $PLATFORMS . ); diff --git a/dockerize/build_conf b/dockerize/build_conf index 5d16972..92b7469 100644 --- a/dockerize/build_conf +++ b/dockerize/build_conf @@ -26,7 +26,7 @@ JAVA_VERSION=$(cd .. && mvn -q \ exec:exec) echo "JAVA_VERSION: ${JAVA_VERSION}" -TOMCAT_VERSION=tomcat10.1.19 +TOMCAT_VERSION=10.1.19 echo "TOMCAT_VERSION: ${TOMCAT_VERSION}" SMARTGEARS_VERSION=$(cd .. && mvn -q \ @@ -45,7 +45,7 @@ echo "IMAGE_VERSION: ${IMAGE_VERSION}" DOCKER_BUILD_NAME=$MVN_NAME:$IMAGE_VERSION echo "DOCKER_BUILD_NAME: ${DOCKER_BUILD_NAME}" -SMARTGEAR_IMAGE=hub.dev.d4science.org/gcube/smartgears-distribution:${SMARTGEARS_VERSION}-java${JAVA_VERSION}-${TOMCAT_VERSION} +SMARTGEAR_IMAGE=hub.dev.d4science.org/gcube/smartgears-distribution:${SMARTGEARS_VERSION}-java${JAVA_VERSION}-tomcat${TOMCAT_VERSION} echo "SMARTGEAR_IMAGE: ${SMARTGEAR_IMAGE}" DOCKER_IMAGE_NAME=d4science/$DOCKER_BUILD_NAME diff --git a/dockerize/push_docker.sh b/dockerize/push_docker.sh new file mode 100755 index 0000000..4d8502d --- /dev/null +++ b/dockerize/push_docker.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +set -a +# source build_conf > docker.conf # generate current conf +# source docker.conf +source build_conf + +echo "Docker image $HARBOR_IMAGE_NAME" + +docker push $HARBOR_IMAGE_NAME + +set +a