From 57584a0a269b232008051403a6215b6e447d1fad Mon Sep 17 00:00:00 2001 From: Alfredo Oliviero Date: Thu, 23 May 2024 16:59:48 +0200 Subject: [PATCH] config docker e builder --- Dockerfile | 22 +++++++++--- Instructions.md | 7 ++-- buildImageAndStart.sh | 78 ++++++++++++++++++++----------------------- build_conf | 41 +++++++++++++++++++++++ docker/container.ini | 1 - loginHarborHub.sh | 13 ++++++++ pom.xml | 14 ++++---- 7 files changed, 119 insertions(+), 57 deletions(-) create mode 100644 build_conf delete mode 120000 docker/container.ini create mode 100755 loginHarborHub.sh diff --git a/Dockerfile b/Dockerfile index 9ab11e6..e647908 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,28 @@ -ARG JAVA_VERSION=11 -ARG SMARTGEARS_VERSION=4.0.1-SNAPSHOT +# docker build -t $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}" \ +# $PLATFORMS . + +ARG JAVA_VERSION +ARG SMARTGEARS_VERSION #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 smartgears-distribution:${SMARTGEARS_VERSION}-java${JAVA_VERSION}-tomcat10.1.19 ARG CONTAINER_INI="./docker/container.ini" + ARG MVN_FINALNAME + ARG MVN_NAME + + RUN apt-get update + RUN apt-get install unzip + #FROM smartgears-distribution:${SMARTGEARS_VERSION}-java${JAVA_VERSION}-tomcat10.1.19 COPY ./docker/logback.xml /etc/ COPY ./docker/*.gcubekey /tomcat/lib - COPY ./target/helloworld.war /tomcat/webapps/ + COPY ./target/${MVN_FINALNAME}.war /tmp + RUN unzip /tmp/${MVN_FINALNAME}.war -d /tomcat/webapps/${MVN_NAME} COPY ${CONTAINER_INI} /etc/container.ini EXPOSE 8080 diff --git a/Instructions.md b/Instructions.md index b1fb64b..1658944 100644 --- a/Instructions.md +++ b/Instructions.md @@ -65,9 +65,9 @@ connect the JAVA debugger to port 5005 # maven configuration for the project ├── pom.xml │ -# the files in the gcube folder are processed by mvn parent and -# the variables ${VAR} resolved using the values found in pom.xml -# and the generated file +# the files in the gcube folder are processed by mvn parent during the packing fase +# the variables ${VAR} are resolved using the values found in pom.xml +# and the generated file are copied (respecting the gcube folder structure) inside the folder generated in ./target and so in the corrisponding war file ├── gcube │   └── extra-resources │   └── WEB-INF @@ -120,6 +120,7 @@ connect the JAVA debugger to port 5005 │   ├── container.ini -> container.dev.ini │   ├── devsec.gcubekey │   └── logback.xml +├── build_conf ├── buildImageAndStart.sh ├── Dockerfile │ diff --git a/buildImageAndStart.sh b/buildImageAndStart.sh index dc98927..c817a57 100755 --- a/buildImageAndStart.sh +++ b/buildImageAndStart.sh @@ -1,9 +1,9 @@ #!/bin/bash # set -x # uncomment to debug script - -BUILD_VERSION=0.0.1-SNAPSHOT -SMARTGEARS_VERSION=4.0.1-SNAPSHOT +set -a +. ./build_conf +set +a ACCEPTED_JAVA_VERSIONs=(11 17) PORT=8080 @@ -13,24 +13,10 @@ EXECUTE=false TEST=false COMPILE=true -JAVA_VERSION=11 -NAME=helloword -CONTAINER_INI="./docker/container.ini" -IMAGE_VERSION=${BUILD_VERSION}-java${JAVA_VERSION}-smartgears${SMARTGEARS_VERSION} - PUSH_DOCKER=false PUSH_HARBOR=false LOGIN_HARBOR=false -BUILD_NAME=$NAME:$IMAGE_VERSION - -SMARTGEAR_IMAGE=hub.dev.d4science.org/gcube/smartgears-distribution:${SMARTGEARS_VERSION}-java${JAVA_VERSION}-tomcat10.1.19 -DOCKER_IMAGE_NAME=d4science/$BUILD_NAME -HARBOR_IMAGE_NAME=hub.dev.d4science.org/gcube/$BUILD_NAME - - -echo "BUILD_NAME=$BUILD_NAME" - ################################################################################ # Help # ################################################################################ @@ -38,21 +24,29 @@ Help() { # Display Help echo "build, create and run in docker the identity manager service" echo - echo "Syntax: buildDistribution [-n arg] [-p arg] [-j arg] [-d arg?] [-h]" + echo "Syntax: buildDistribution " echo "options:" - echo "-s skip maven package" - echo "-t exec also maven tests" - echo "-n arg specifies the docker image name (default is identity-manager)." + + echo "-e execute the docker image" + echo "-d arg? enable java debug mode for execution" + + 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 "-j arg specify java version (default is $JAVA_VERSION)" echo " accepted version are: ${ACCEPTED_JAVA_VERSIONs[@]}" - echo "-e execute the image" - 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 "-s skip maven package" + echo "-t exec also maven tests" + + echo "-n arg specifies the docker image name (default is $MVN_NAME)." + echo "-l [l]ogin to d4science harbor" - echo "-u p[u]sh image to dockerhub (with docker login already done)" - echo "-c arg path of the file to deploy as container.ini (default ./docker/container.ini)" echo "-h Print this Help." echo echo "to compile and push to harbor registry with a custom container.ini file: " @@ -134,25 +128,25 @@ else echo "skipping mvn package" fi +echo "SMARTGEAR IMAGE: $SMARTGEAR_IMAGE" docker pull $SMARTGEAR_IMAGE if [ $MULTI_PLATFORM ]; then - - echo "build multiplatform" - - docker build -t $BUILD_NAME --build-arg="CONTAINER_INI=$CONTAINER_INI" --build-arg="JAVA_VERSION=${JAVA_VERSION}" --build-arg="SMARTGEARS_VERSION=${SMARTGEARS_VERSION}" --platform=linux/amd64,linux/arm64,linux/arm/v7 . -else - echo "build single platform" - docker build -t $BUILD_NAME --build-arg="CONTAINER_INI=$CONTAINER_INI" --build-arg="JAVA_VERSION=${JAVA_VERSION}" --build-arg="SMARTGEARS_VERSION=${SMARTGEARS_VERSION}" . - - # docker manifest create hub.dev.d4science.org/gcube/$BUILD_NAME \ - # hub.dev.d4science.org/gcube/$NAME-amd64-linux:$IMAGE_VERSION \ - # hub.dev.d4science.org/gcube/$NAME-arm-linux:$IMAGE_VERSION \ - # hub.dev.d4science.org/gcube/$NAME-arm-linux:$IMAGE_VERSION + PLATFORMS="--platform=linux/amd64,linux/arm64,linux/arm/v7" + echo "build multiple platform $PLATFORMS" fi +echo "DOCKER_BUILD_NAME: $DOCKER_BUILD_NAME" +docker build -t $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}" \ + $PLATFORMS . + if [ ${PUSH_DOCKER} = true ]; then - docker tag $BUILD_NAME $DOCKER_IMAGE_NAME + docker tag $DOCKER_BUILD_NAME $DOCKER_IMAGE_NAME docker push $DOCKER_IMAGE_NAME echo ">>> pushed on dockerhub the image $DOCKER_IMAGE_NAME" fi @@ -164,7 +158,7 @@ fi if [ $PUSH_HARBOR = true ]; then echo ">>> PUSHING on hub.dev.d4science.org the image $HARBOR_IMAGE_NAME" - docker tag $BUILD_NAME $HARBOR_IMAGE_NAME + docker tag $DOCKER_BUILD_NAME $HARBOR_IMAGE_NAME echo ">>> docker push $HARBOR_IMAGE_NAME" docker push $HARBOR_IMAGE_NAME echo ">>> pushed on hub.dev.d4science.org the image $HARBOR_IMAGE_NAME" @@ -172,8 +166,8 @@ fi if [ ${EXECUTE} = true ]; then if [ $DEBUG = true ]; then - docker run -p $PORT:8080 -p $DEBUG_PORT:5005 -e JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,address=*:5005,server=y,suspend=y" $BUILD_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" $DOCKER_BUILD_NAME else - docker run -p $PORT:8080 $BUILD_NAME + docker run -p $PORT:8080 $DOCKER_BUILD_NAME fi fi diff --git a/build_conf b/build_conf new file mode 100644 index 0000000..c8a9401 --- /dev/null +++ b/build_conf @@ -0,0 +1,41 @@ +MVN_VERSION=$(mvn -q \ + -Dexec.executable=echo \ + -Dexec.args='${project.version}' \ + --non-recursive \ + exec:exec) + + +MVN_NAME=$(mvn -q \ + -Dexec.executable=echo \ + -Dexec.args='${project.artifactId}' \ + --non-recursive \ + exec:exec) + +MVN_FINALNAME=$(mvn -q \ + -Dexec.executable=echo \ + -Dexec.args='${project.build.finalName}' \ + --non-recursive \ + exec:exec) + +JAVA_VERSION=$(mvn -q \ + -Dexec.executable=echo \ + -Dexec.args='${maven.compiler.target}' \ + --non-recursive \ + exec:exec) + +TOMCAT_VERSION=tomcat10.1.19 +SMARTGEARS_VERSION=$(mvn -q \ + -Dexec.executable=echo \ + -Dexec.args='${docker.smartgear.version}' \ + --non-recursive \ + exec:exec) + +CONTAINER_INI="./docker/container.ini" + +IMAGE_VERSION=${MVN_VERSION}-java${JAVA_VERSION}-smartgears${SMARTGEARS_VERSION} +DOCKER_BUILD_NAME=$MVN_NAME:$IMAGE_VERSION + +SMARTGEAR_IMAGE=hub.dev.d4science.org/gcube/smartgears-distribution:${SMARTGEARS_VERSION}-java${JAVA_VERSION}-${TOMCAT_VERSION} + +DOCKER_IMAGE_NAME=d4science/$DOCKER_BUILD_NAME +HARBOR_IMAGE_NAME=hub.dev.d4science.org/gcube/$DOCKER_BUILD_NAME diff --git a/docker/container.ini b/docker/container.ini deleted file mode 120000 index 9ca9d2c..0000000 --- a/docker/container.ini +++ /dev/null @@ -1 +0,0 @@ -container.alf.ini \ No newline at end of file diff --git a/loginHarborHub.sh b/loginHarborHub.sh new file mode 100755 index 0000000..48a84cd --- /dev/null +++ b/loginHarborHub.sh @@ -0,0 +1,13 @@ +#!/bin/bash +REGISTRY_URL="hub.dev.d4science.org" +#USERNAME="alfredo.oliviero" +echo "to obtain Harbor username and CLI secret:" +echo "https://hub.dev.d4science.org/ -> user profile -> CLI secret" + +read -p "username:" USERNAME + +echo "" + +read -s -p "CLI secret:" ACCESS_TOKEN +echo "$ACCESS_TOKEN" | docker login $REGISTRY_URL -u $USERNAME --password-stdin +unset ACCESS_TOKEN diff --git a/pom.xml b/pom.xml index d23e92e..9b831a7 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,6 @@ Smartgears HelloWorld Service war - org.gcube.tools maven-parent @@ -18,14 +17,17 @@ 11 + UTF-8 ${java.version} ${java.version} 1.14.0 - + 2.16.1 + + 4.0.1-SNAPSHOT @@ -47,8 +49,6 @@ - - org.gcube.core @@ -73,7 +73,6 @@ jersey-container-servlet - @@ -102,7 +101,6 @@ - ${project.artifactId} + file:/opt/homebrew/opt/sphinx-doc/bin/sphinx-build