From 0ad5c91ebe673e793196e85867a361440f358b9c Mon Sep 17 00:00:00 2001 From: t-akervik-ericsson <22633193+tobiasake@users.noreply.github.com> Date: Mon, 18 Feb 2019 16:45:11 +0100 Subject: [PATCH] Change artifact type to war file, add Tomcat support and add Dockerfile (#36) * Change artifact type to war webapps for Tomcat support and adding Dockerfile. * Added Dockerfile. * Adapted Eiffel-ViCi application for external Tomcat webapp application. * Updated Readme txt file how to run Eiffel-ViCi Docker container. * Some more Docker run documentation in readme file. * Fixed indentation in pom file. * Fix indentations in pom file. --- pom.xml | 36 ++++++++++------ src/main/docker/Dockerfile | 21 ++++++--- src/main/docker/README.txt | 19 ++++++++ src/main/docker/health-check.sh | 43 +++++++++++++++++++ src/main/docker/start-service.sh | 21 +++++++++ .../com/ericsson/vici/ViciApplication.java | 4 +- src/main/resources/application.properties | 8 +++- 7 files changed, 130 insertions(+), 22 deletions(-) create mode 100644 src/main/docker/README.txt create mode 100755 src/main/docker/health-check.sh create mode 100755 src/main/docker/start-service.sh diff --git a/pom.xml b/pom.xml index 6f844c3..753ae54 100644 --- a/pom.xml +++ b/pom.xml @@ -1,23 +1,20 @@ - + 4.0.0 com.ericsson.vici - vici-eiffel - 0.0.1-SNAPSHOT - jar - - Vici - https://github.com/eiffel-community/eiffel-vici + eiffel-vici + 0.0.1 + war org.springframework.boot spring-boot-starter-parent - 2.0.2.RELEASE - + 2.0.8.RELEASE + - UTF-8 UTF-8 @@ -34,6 +31,12 @@ spring-boot-starter-web 2.1.3.RELEASE + + org.springframework.boot + spring-boot-starter-tomcat + provided + 2.1.3.RELEASE + junit junit @@ -43,11 +46,13 @@ org.springframework.boot spring-boot-starter-test + 2.0.8.RELEASE test org.springframework.boot spring-boot-test + 2.0.8.RELEASE test @@ -101,9 +106,16 @@ - + + org.apache.maven.plugins + maven-war-plugin + 3.2.0 + + false + + com.github.eirslett frontend-maven-plugin diff --git a/src/main/docker/Dockerfile b/src/main/docker/Dockerfile index f3145da..17f0c7b 100644 --- a/src/main/docker/Dockerfile +++ b/src/main/docker/Dockerfile @@ -1,7 +1,14 @@ -FROM frolvlad/alpine-oraclejdk8:slim -VOLUME /tmp -ADD maven/vici-eiffel-0.0.1-SNAPSHOT.jar app.jar -RUN sh -c 'touch /app.jar' -ENV JAVA_OPTS="" -EXPOSE 8080 -ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ] +FROM tomcat:8.0-jre8 +MAINTAINER Eiffel-Community + +ARG URL +RUN echo Building Eiffel-Image image based on artifact url: ${URL} + +# Create image with existing war file. User need to execute 'mvn package -DskipTest' before 'docker build' +RUN ["rm", "-fr", "/usr/local/tomcat/webapps/ROOT"] +ADD ./src/main/docker/health-check.sh /eiffel/health-check.sh +ADD ./src/main/docker/start-service.sh /eiffel/start-service.sh +ADD ${URL} /usr/local/tomcat/webapps/ROOT.war + + +CMD ["/eiffel/start-service.sh"] diff --git a/src/main/docker/README.txt b/src/main/docker/README.txt new file mode 100644 index 0000000..c0c1d29 --- /dev/null +++ b/src/main/docker/README.txt @@ -0,0 +1,19 @@ +A: Build Eiffel-ViCi Docker image based on Eiffel-ViCi from an Artifactory, e.g. Jitpack: +cd (git root dir) +docker build -t eiffel-intelligence:0.0.19 --build-arg URL=https://jitpack.io/com/github/eiffel-community/eiffel-vici/0.0.1/eiffel-vici-0.0.1.war -f src/main/docker/Dockerfile . + + + +B: Build Eiffel-ViCi based on local Eiffel-ViCi source code changes +1. Build Eiffel-ViCi service artifact war file: +cd (git root dir) +mvn package -DskipTests + +2. Build Eiffel-ViCi Docker image: +cd (git root dir)/ +docker build -t eiffel-vici:0.0.1 --build-arg URL=./target/eiffel-vici-0.0.1.war -f src/main/docker/Dockerfile . + + +# Run Eiffel-ViCi in Docker: +docker run -p 8080:8080 --expose 8080 -e server.port=8080 -e logging.level.root=DEBUG -e logging.level.org.springframework.web=INFO eiffel-vici:0.0.1 + diff --git a/src/main/docker/health-check.sh b/src/main/docker/health-check.sh new file mode 100755 index 0000000..cd668ba --- /dev/null +++ b/src/main/docker/health-check.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +#NC_BIN=nc.traditional +#NC_BIN=nc +SLEEP_LENGTH=8 + +WAIT_HOSTS="${@}" + +echo "Will wait for fallowing hosts getting started:" +echo "${WAIT_HOSTS}" + +wait_for_service() { + echo Waiting for $1 to listen on $2... + LOOP=1 + while [ "$LOOP" != "0" ]; + do + echo "Waiting on host: ${1}:${2}" + sleep $SLEEP_LENGTH + curl $1:$2 + RESULT=$? + echo "Service check result: $RESULT" + if [ $RESULT == 0 ] + then + LOOP=0 + fi + done +} + +echo +echo "Waiting for components to start" +echo + +for URL in `echo "${WAIT_HOSTS}"` +do + wait_for_service `echo $URL | sed s/\:/\ /` + echo "Host $URL detected started." +done + +echo +echo "All services detected as started." +echo + +exit 0 diff --git a/src/main/docker/start-service.sh b/src/main/docker/start-service.sh new file mode 100755 index 0000000..e1a65fa --- /dev/null +++ b/src/main/docker/start-service.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# These two varibales need to be set from Docker-compose or K8S at startup if MB and/or DB healthcheck should be used. +#WAIT_MB_HOSTS="localhost:15672 localhost:15672" + +if [ ! -z "$WAIT_MB_HOSTS" ] +then + /eiffel/health-check.sh "$WAIT_MB_HOSTS" +fi + +if [ ! -z "$WAIT_DB_HOSTS" ] +then + /eiffel/health-check.sh "$WAIT_DB_HOSTS" +fi + + +echo +echo "Starting Eiffel-ViCi" +echo + +catalina.sh run diff --git a/src/main/java/com/ericsson/vici/ViciApplication.java b/src/main/java/com/ericsson/vici/ViciApplication.java index 8cb7a60..6ce2486 100644 --- a/src/main/java/com/ericsson/vici/ViciApplication.java +++ b/src/main/java/com/ericsson/vici/ViciApplication.java @@ -21,9 +21,11 @@ import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import com.ericsson.vici.api.SettingsHandler; @SpringBootApplication -public class ViciApplication { +public class ViciApplication extends SpringBootServletInitializer { public static final Logger log = LoggerFactory.getLogger(ViciApplication.class); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 117fa0e..b726147 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,4 +1,4 @@ -spring.application.name=vici-eiffel +spring.application.name=eiffel-vici server.port=8080 # REST api returns json in pretty format with jackson @@ -9,4 +9,8 @@ spring.jackson.default-property-inclusion=non_null # Enables debug log #debug=true # Logging file, will not put out to a file if not defined. -#logging.file=vici.log \ No newline at end of file +#logging.file=vici.log + +# Logging +logging.level.root=INFO +logging.level.org.springframework.web=INFO \ No newline at end of file