Skip to content

Commit

Permalink
Change artifact type to war file, add Tomcat support and add Dockerfi…
Browse files Browse the repository at this point in the history
…le (#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.
  • Loading branch information
tobiasake authored and jonathanwahlund committed Feb 18, 2019
1 parent 48ec003 commit 0ad5c91
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 22 deletions.
36 changes: 24 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.ericsson.vici</groupId>
<artifactId>vici-eiffel</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Vici</name>
<description>https://github.com/eiffel-community/eiffel-vici</description>
<artifactId>eiffel-vici</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/> <!-- .. lookup parent from repository -->
<version>2.0.8.RELEASE</version>
<relativePath /> <!-- .. lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand All @@ -34,6 +31,12 @@
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
<version>2.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -43,11 +46,13 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.0.8.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>2.0.8.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -101,9 +106,16 @@
</image>
</images>
</configuration>

</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>

</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
Expand Down
21 changes: 14 additions & 7 deletions src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
19 changes: 19 additions & 0 deletions src/main/docker/README.txt
Original file line number Diff line number Diff line change
@@ -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

43 changes: 43 additions & 0 deletions src/main/docker/health-check.sh
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions src/main/docker/start-service.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion src/main/java/com/ericsson/vici/ViciApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
#logging.file=vici.log

# Logging
logging.level.root=INFO
logging.level.org.springframework.web=INFO

0 comments on commit 0ad5c91

Please sign in to comment.