Skip to content

Commit a192bdd

Browse files
authored
Dockerfile for building images for Docker and Kubernetes (#229)
1 parent c2b9a31 commit a192bdd

File tree

6 files changed

+328
-14
lines changed

6 files changed

+328
-14
lines changed

src/main/docker/Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
FROM fabric8/java-jboss-openjdk8-jdk:1.2
1+
FROM tomcat:8.0-jre8
22
MAINTAINER Eiffel-Community
3-
USER root
4-
ENV JAVA_APP_DIR=/deployments
5-
ENV JAVA_APP_JAR=eiffel-intelligence.war
6-
EXPOSE 8091 8778 9779
73

8-
# Create image with existing war file. User need to execute 'mvn package -DskipTest' before 'docker build'
9-
COPY ./target/eiffel-intelligence-*.war /deployments/eiffel-intelligence.war
4+
ARG URL
5+
RUN echo Building Eiffel-Intelligence image based on artifact url: ${URL}
106

11-
CMD /deployments/run-java.sh
7+
# Create image with existing war file. User need to execute 'mvn package -DskipTest' before 'docker build'
8+
RUN ["rm", "-fr", "/usr/local/tomcat/webapps/ROOT"]
9+
ADD ./src/main/docker/health-check.sh /eiffel/health-check.sh
10+
ADD ./src/main/docker/start-service.sh /eiffel/start-service.sh
11+
ADD ${URL} /usr/local/tomcat/webapps/ROOT.war
1212

1313

14+
CMD ["/eiffel/start-service.sh"]

src/main/docker/README.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
A: Build Eiffel-Intelligence Docker image based on Eiffel-Intelligence from an Artifactory, e.g. Jitpack:
2+
cd (git root dir)
3+
docker build -t eiffel-intelligence:0.0.19 --build-arg URL=https://jitpack.io/com/github/eiffel-community/eiffel-intelligence/0.0.19/eiffel-intelligence-0.0.19.war -f src/main/docker/Dockerfile .
4+
5+
6+
7+
B: Build Eiffel-Intelligence based on local Eiffel-Intelligence source code changes
8+
1. Build Eiffel-Intelligence service artifact:
9+
cd (git root dir)
10+
mvn package -DskipTests
11+
12+
2. Build Eiffel-Intelligence Docker image:
13+
cd (git root dir)/
14+
docker build -t eiffel-intelligence:0.0.19 --build-arg URL=./target/eiffel-intelligence-0.0.19.war -f src/main/docker/Dockerfile .

src/main/docker/docker-compose.yml

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#################################################################################################
2+
#
3+
# Copyright 2019 Ericsson AB.
4+
# For a full list of individual contributors, please see the commit history.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
##################################################################################################
19+
# docker-compose commands
20+
#
21+
# run: docker-compose up
22+
# stop: docker-compose stop
23+
# stop/remove: docker-compose down --volumes
24+
#
25+
# Cleanup/Remove (if needed):
26+
# Dangling Volumes: docker volume rm `docker volume ls -q -f dangling=true`
27+
# Unused Images: docker images -q | xargs docker rmi
28+
# Stopped containers: docker rm `docker ps -a -q`
29+
#
30+
# Maintainer: Eiffel-Community
31+
##################################################################################################
32+
version: "2.1"
33+
services:
34+
mongodb:
35+
restart: always
36+
image: mongo:latest
37+
expose:
38+
- "27017"
39+
ports:
40+
- "27017:27017"
41+
healthcheck:
42+
test: ["CMD-SHELL","echo", "'db.stats().ok' | mongo localhost:27017/test", "--quiet"]
43+
interval: 30s
44+
timeout: 10s
45+
retries: 5
46+
networks:
47+
eiffel_2.0_1:
48+
aliases:
49+
- mongodb
50+
51+
rabbitmq:
52+
restart: always
53+
image: rabbitmq:3.6.2-management
54+
expose:
55+
- "15672"
56+
- "5672"
57+
ports:
58+
- "15672:15672"
59+
- "5672:5672"
60+
healthcheck:
61+
test: ["CMD-SHELL", "if rabbitmqctl status; then \nexit 0 \nfi \nexit 1"]
62+
interval: 30s
63+
timeout: 10s
64+
retries: 5
65+
networks:
66+
eiffel_2.0_1:
67+
aliases:
68+
- rabbitmq
69+
environment:
70+
- RABBITMQ_DEFAULT_PASS=myuser
71+
- RABBITMQ_DEFAULT_USER=myuser
72+
- RABBITMQ_DEFAULT_VHOST=/
73+
74+
eiffel-er:
75+
restart: always
76+
image: eiffelericsson/eiffel-er:0.0.60
77+
expose:
78+
- "8080"
79+
ports:
80+
- "8081:8080"
81+
depends_on:
82+
- rabbitmq
83+
- mongodb
84+
networks:
85+
eiffel_2.0_1:
86+
aliases:
87+
- eiffel-er
88+
environment: # Overrides settings in config file in catalina folder. OBS --> skip quotes for rabbitmq.bindingKey value
89+
# No config file copied to catalina folder in Dockerfile, only uses env vars below ;-)
90+
# /eventrepository removed in contextpath
91+
- server.contextPath=/
92+
- server.port=8080
93+
- rabbitmq.host=rabbitmq
94+
- rabbitmq.componentName=eventrepository
95+
- rabbitmq.port=5672
96+
- rabbitmq.domainId=ei-domain
97+
- rabbitmq.durable=true
98+
- rabbitmq.user=myuser
99+
- rabbitmq.password=myuser
100+
- rabbitmq.exchangeName=ei-exchange
101+
- rabbitmq.bindingKey=#
102+
- rabbitmq.autoDelete=false
103+
- rabbitmq.createExchangeIfNotExisting=true
104+
- rabbitmq.consumerName=messageConsumer
105+
- mongodb.host=mongodb
106+
- mongodb.port=27017
107+
- mongodb.database=eiffel
108+
- mongodb.collection=events
109+
- mongodb.user
110+
- mongodb.password
111+
- mongodb.indexes=meta.id,links.target,links.type,meta.time,data.gav.groupId,data.gav.artifactId
112+
- mongodb.externalERs
113+
- search.limit=100
114+
- search.levels=10
115+
- eventrepo2.URL=
116+
- index.staticIndex.indexOn=false
117+
- index.staticIndex.filePath=src/main/resources/static_indexes.json
118+
- index.dynamicIndex.indexOn=false
119+
- index.dynamicIndex.indexCreationDay=SUNDAY
120+
- index.dynamicIndex.indexCreationTime=11:50:00
121+
- index.dynamicIndex.maxIndexesCount=5
122+
- index.dynamicIndex.filePath=src/main/resources/dynamic_indexing.json
123+
- index.dynamicIndex.fileUpdatePeriod=30
124+
125+
ei_backend:
126+
restart: always
127+
image: eiffel-intelligence:0.0.19
128+
expose:
129+
- "8080"
130+
ports:
131+
- "8080:8080"
132+
depends_on:
133+
- mongodb
134+
- rabbitmq
135+
networks:
136+
eiffel_2.0_1:
137+
aliases:
138+
- ei_backend
139+
environment: # Overrides settings in application config file
140+
- SpringApplicationName=ei-backend
141+
- server.port=8080
142+
- rules.path=src/main/resources/ArtifactRules_new.json
143+
- rabbitmq.host=rabbitmq
144+
- rabbitmq.port=5672
145+
- rabbitmq.domainId=ei-domain
146+
- rabbitmq.componentName=ei-backend
147+
- rabbitmq.waitlist.queue.suffix=waitlist
148+
- rabbitmq.exchange.name=ei-exchange
149+
- rabbitmq.user=myuser
150+
- rabbitmq.password=myuser
151+
- spring.data.mongodb.host=mongodb
152+
- spring.data.mongodb.port=27017
153+
- spring.data.mongodb.database=eiffel2_intelligence
154+
- missedNotificationDataBaseName=eiffel2_intelligence_MissedNotification
155+
- search.query.prefix=object
156+
- aggregated.object.name=aggregatedObject
157+
- spring.mail.host=
158+
- spring.mail.port=
159+
- spring.mail.username=
160+
- spring.mail.password=
161+
- spring.mail.properties.mail.smtp.auth=false
162+
- spring.mail.properties.mail.smtp.starttls.enable=false
163+
- er.url=eiffel-er:8080
164+
- WAIT_MB_HOSTS=rabbitmq:15672
165+
- WAIT_DB_HOSTS=mongodb:27017
166+
167+
networks:
168+
eiffel_2.0_1:

src/main/docker/health-check.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
#NC_BIN=nc.traditional
4+
#NC_BIN=nc
5+
SLEEP_LENGTH=8
6+
7+
WAIT_HOSTS="${@}"
8+
9+
echo "Will wait for fallowing hosts getting started:"
10+
echo "${WAIT_HOSTS}"
11+
12+
wait_for_service() {
13+
echo Waiting for $1 to listen on $2...
14+
LOOP=1
15+
while [ "$LOOP" != "0" ];
16+
do
17+
echo "Waiting on host: ${1}:${2}"
18+
sleep $SLEEP_LENGTH
19+
curl $1:$2
20+
RESULT=$?
21+
echo "Service check result: $RESULT"
22+
if [ $RESULT == 0 ]
23+
then
24+
LOOP=0
25+
fi
26+
done
27+
}
28+
29+
echo
30+
echo "Waiting for components to start"
31+
echo
32+
33+
for URL in `echo "${WAIT_HOSTS}"`
34+
do
35+
wait_for_service `echo $URL | sed s/\:/\ /`
36+
echo "Host $URL detected started."
37+
done
38+
39+
echo
40+
echo "All services detected as started."
41+
echo
42+
43+
exit 0

src/main/docker/start-service.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
# These two varibales need to be set from Docker-compose or K8S at startup if MB and/or DB healthcheck should be used.
4+
#WAIT_MB_HOSTS="localhost:15672 localhost:15672"
5+
6+
if [ ! -z "$WAIT_MB_HOSTS" ]
7+
then
8+
/eiffel/health-check.sh "$WAIT_MB_HOSTS"
9+
fi
10+
11+
if [ ! -z "$WAIT_DB_HOSTS" ]
12+
then
13+
/eiffel/health-check.sh "$WAIT_DB_HOSTS"
14+
fi
15+
16+
17+
echo
18+
echo "Starting Eiffel-Intelligence"
19+
echo
20+
21+
catalina.sh run

wiki/markdown/docker.md

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ With the Docker image user can try-out the Eiffel-Intelligence on a Docker Host
1212

1313
Windows: https://docs.docker.com/docker-for-windows/install/
1414

15+
- Docker Compose
16+
17+
Linux and Windows: https://docs.docker.com/compose/install/
18+
1519
## Follow these step to build the Docker image.
1620

1721
1. Build the Eiffel-intelligence war file:
@@ -24,7 +28,7 @@ This will produce a war file in the "target" folder.
2428
2. Build the Docker image with the war file that was produced from previous step:
2529

2630

27-
`docker build -f src/main/docker/Dockerfile -t eiffel-intelligence-backend:0.1 .`
31+
`docker build -t eiffel-intelligence:0.0.19 --build-arg URL=./target/eiffel-intelligence-0.0.19.war -f src/main/docker/Dockerfile .`
2832

2933

3034
Now docker image has build with tag "eiffel-intelligence-backend:0.1"
@@ -33,15 +37,19 @@ Now docker image has build with tag "eiffel-intelligence-backend:0.1"
3337
To run the produced docker image on the local Docker host, execute this command:
3438

3539

36-
`docker run -p 8034:8091 --expose 8091 -e server.port=8091 -e logging.level.root=DEBUG -e logging.level.org.springframework.web=DEBUG -e logging.level.com.ericsson.ei=DEBUG eiffel-intelligence-backend:0.1`
40+
`docker run -p 8070:8080 --expose 8080 -e server.port=8080 -e logging.level.log.level.root=DEBUG -e logging.level.org.springframework.web=DEBUG -e logging.level.com.ericsson.ei=DEBUG -e spring.data.mongodb.host=eiffel2-mongodb -e spring.data.mongodb.port=27017 eiffel-intelligence:0.0.19`
41+
42+
MongoDB, RabbitMq and other Eiffel-Intelligence required components need to running and configured via these application properties that is provided to the docker command above. See the application.properties file for all available/required properties:
43+
[application.properties](https://github.com/Ericsson/eiffel-intelligence/blob/master/src/main/resources/application.properties)
44+
3745

3846
# Some info of all flags to this command
3947

4048

4149
## Eiffel Intelligence Spring Properties
4250

4351

44-
<B>"-e server.port=8091"</B> - Is the Spring property setting for Eiffel-Intelligence applications web port.
52+
<B>"-e server.port=8080"</B> - Is the Spring property setting for Eiffel-Intelligence applications web port.
4553

4654

4755
<B>"-e logging.level.root=DEBUG -e logging.level.org.springframework.web=DEBUG -e
@@ -57,10 +65,69 @@ It is possible to set all Spring available properties via docker envrionment "-e
5765
## Docker flags
5866

5967

60-
<B>"--expose 8091"</B> - this Docker flag tells that containers internal port shall be exposed to outside of the Docker Host. This flag do not set which port that should be allocated outside Docker Host on the actual server/machine.
68+
<B>"--expose 8080"</B> - this Docker flag tells that containers internal port shall be exposed to outside of the Docker Host. This flag do not set which port that should be allocated outside Docker Host on the actual server/machine.
69+
70+
71+
<B>"-p 8070:8080"</B> - this Docker flag is mapping the containers external port 8034 to the internal exposed port 8091. Port 8034 will be allocated outside Docker host and user will be able to access the containers service via port 8034.
72+
73+
74+
When Eiffel-Intelligence container is running on your local Docker host, Eiffel-Intelligence should be reachable with address "localhost:8070/\<Rest End-Point\>" or "\<docker host ip\>:8070/\<Rest End-Point\>"
75+
76+
77+
Another option to configure Eiffel-Intelligence is to provide the application properties file into the container, which can be made in two ways:
78+
1. Put application.properties file in Tomcat Catalina config folder in container and run Eiffe-Intelligence:
79+
80+
`docker run -p 8070:8080 --expose 8080 --volume /path/to/application.properties:/usr/local/tomcat/config/application.properties eiffel-intelligence:0.0.19`
81+
82+
2. Put application.properties file in a different folder in container and tell EI where the application.properties is located in the container:
83+
84+
`docker run -p 8070:8080 --expose 8080 --volume /path/to/application.properties:/tmp/application.properties -e spring.config.location=/tmp/application.properties eiffel-intelligence:0.0.19`
85+
86+
87+
# Run Docker image with provided docker-compose file
88+
This docker-compose file includes these components, [docker-compose.yml](https://github.com/Ericsson/eiffel-intelligence/blob/master/src/main/docker/docker-compose.yml):
89+
- MongoDb
90+
- RabbitMq
91+
- ER
92+
- EI-Backend (Using the local EI-Backend Docker image build from previous steps)
93+
94+
If you have used a different image tag when you build the EI Backend docker image,
95+
then you need to update docker-compose.yml file.
96+
97+
This line need to changed, in ei_backend service section:
98+
99+
"image: eiffel-intelligence:0.0.19"
100+
101+
To:
102+
103+
"image: \<your image tag\>"
104+
105+
Then run following docker-compose command to startup all components:
106+
107+
`docker-compose -f src/main/docker/docker-compose.yml up -d`
108+
109+
It will take some minutes until all components has started. When all components has loaded, you should be able to access EI-Backend Rest-interfaces with address:
110+
http://localhost:8080/\<EI rest-api endpoint\>
111+
112+
Curl command can be used to make request to EI-Back-end rest-api, example for getting all subscriptions:
113+
114+
115+
`curl -X GET http://localhost:8080/subscriptions`
116+
117+
It is also possible to access these Rest-Api addresses in web-browser and get result present in a Json view in web-browser.
118+
119+
Following command can be used to get the logs from the EI-Backend container/service:
120+
121+
`docker-compose -f src/main/docker/docker-compose.yml logs ei_backend`
122+
123+
All service names can be retreived with following command:
124+
125+
`docker-compose -f src/main/docker/docker-compose.yml config --services`
61126

127+
It is also possible to retrieve the logs by only using "docker logs <container_id or container_name>" command:
62128

63-
<B>"-p 8034:8091"</B> - this Docker flag is mapping the containers external port 8034 to the internal exposed port 8091. Port 8034 will be allocated outside Docker host and user will be able to access the containers service via port 8034.
129+
`docker logs <container_id or container_name>`
64130

131+
Container id can be retrieved with docker command:
65132

66-
When Eiffel-Intelligence container is running on your local Docker host, Eiffel-Intelligence should be reachable with address "localhost:8091/\<Rest End-Point\>" or "\<docker host ip\>:8091/\<Rest End-Point\>"
133+
`docker ps`

0 commit comments

Comments
 (0)