Skip to content

Commit 38380ba

Browse files
committed
Added Docker Compose for Department service with zipkin. We generated docker image by "Google Container Tools". We used github repository for our configuration by config-server.
1 parent 9c9beb2 commit 38380ba

File tree

4 files changed

+181
-0
lines changed

4 files changed

+181
-0
lines changed

department-service/README.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Java Microservices - Department Service
2+
3+
4+
## Dependencies
5+
* Linux, VirtualBox or Docker Desktop
6+
* Java 11
7+
* Maven
8+
* Git Config Server Repository
9+
* Spring Boot : 2.5.0
10+
* Netflix Eureka Client
11+
* Google Container Tools
12+
* H2 Database
13+
* Lombok
14+
* Zipkin
15+
16+
## Configuration
17+
src/main/docker/app.yml
18+
```yaml
19+
version: '3.8'
20+
services:
21+
department-service:
22+
image: cevheri/department-service
23+
environment:
24+
- _JAVA_OPTIONS=-Xmx512m -Xms256m
25+
- APP_SLEEP=10 # for zipkin
26+
ports:
27+
- 9001:9001
28+
zipkin:
29+
image: openzipkin/zipkin
30+
ports:
31+
- 9411:9411
32+
```
33+
34+
We will use github public repository for our configuration:
35+
https://github.com/cevheri/microservices-config-server
36+
37+
38+
---
39+
## Development
40+
```shell
41+
$ ./mvnw package
42+
$ java -jar target/*.jar
43+
```
44+
Visit : http://localhost:8761/eureka/apps/department-service
45+
46+
---
47+
## Production With Docker
48+
We will create Docker Image using Google Container Tools and run this Docker Image with Docker Compose.
49+
50+
### Build docker image:
51+
```shell
52+
$ ./mvnw -Pprod clean verify jib:dockerBuild
53+
54+
...
55+
[INFO] Executing tasks:
56+
[INFO] [==============================] 100.0% complete
57+
[INFO]
58+
[INFO] ------------------------------------------------------------------------
59+
[INFO] BUILD SUCCESS
60+
[INFO] ------------------------------------------------------------------------
61+
[INFO] Total time: 17.728 s
62+
[INFO] Finished at: 21:45:11+03:00
63+
[INFO] ------------------------------------------------------------------------
64+
```
65+
66+
---
67+
68+
### Run:
69+
```shell
70+
$ docker-compose -f src/main/docker/app.yml up -d
71+
72+
Creating department-service ... done
73+
```
74+
---
75+
Visit : http://localhost:8761/eureka/apps/department-service
76+
```xml
77+
<application>
78+
<name>department-service</name>
79+
<instance>
80+
<instanceId>192.168.1.57:department-service:9001</instanceId>
81+
<hostName>service-registry</hostName>
82+
<app>department-service</app>
83+
<ipAddr>192.168.1.57</ipAddr>
84+
<status>UP</status>
85+
...
86+
...
87+
</instance>
88+
</application>
89+
```
90+
91+
---
92+
### View docker images:
93+
```shell
94+
$ docker images
95+
96+
REPOSITORY TAG IMAGE ID CREATED SIZE
97+
cevheri/department-service latest 57a100df8bcd 26 minutes ago 287MB
98+
99+
```
100+
101+
### View docker containers:
102+
````shell
103+
$ docker ps
104+
105+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
106+
2ca74578a26c cevheri/department-service "bash -c /entrypoint…" 8 seconds ago Up 6 seconds 0.0.0.0:9001->9001/tcp, :::9001->9001/tcp department-service
107+
108+
````
109+
110+
### Stop Docker Compose:
111+
```shell
112+
$ docker-compose -f src/main/docker/app.yml down
113+
114+
```

department-service/pom.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<properties>
1717
<java.version>11</java.version>
1818
<spring-cloud.version>2020.0.3</spring-cloud.version>
19+
<jib-maven-plugin.version>2.8.0</jib-maven-plugin.version>
1920
</properties>
2021
<dependencies>
2122

@@ -101,7 +102,57 @@
101102
</excludes>
102103
</configuration>
103104
</plugin>
105+
106+
<plugin>
107+
<groupId>com.google.cloud.tools</groupId>
108+
<artifactId>jib-maven-plugin</artifactId>
109+
</plugin>
110+
104111
</plugins>
112+
113+
<pluginManagement>
114+
<plugins>
115+
<plugin>
116+
<groupId>com.google.cloud.tools</groupId>
117+
<artifactId>jib-maven-plugin</artifactId>
118+
<version>${jib-maven-plugin.version}</version>
119+
<configuration>
120+
<from>
121+
<image>adoptopenjdk:11-jre-hotspot</image>
122+
</from>
123+
<to>
124+
<image>cevheri/department-service:latest</image>
125+
</to>
126+
<container>
127+
<entrypoint>
128+
<shell>bash</shell>
129+
<option>-c</option>
130+
<arg>/entrypoint.sh</arg>
131+
</entrypoint>
132+
<ports>
133+
<port>9001</port>
134+
</ports>
135+
<environment>
136+
<SPRING_OUTPUT_ANSI_ENABLED>ALWAYS</SPRING_OUTPUT_ANSI_ENABLED>
137+
<APP_SLEEP>0</APP_SLEEP>
138+
</environment>
139+
<creationTime>USE_CURRENT_TIMESTAMP</creationTime>
140+
<user>1000</user>
141+
</container>
142+
<extraDirectories>
143+
<paths>src/main/docker/jib</paths>
144+
<permissions>
145+
<permission>
146+
<file>/entrypoint.sh</file>
147+
<mode>755</mode>
148+
</permission>
149+
</permissions>
150+
</extraDirectories>
151+
</configuration>
152+
</plugin>
153+
</plugins>
154+
</pluginManagement>
155+
105156
</build>
106157

107158

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3.8'
2+
services:
3+
department-service:
4+
image: cevheri/department-service
5+
environment:
6+
- _JAVA_OPTIONS=-Xmx512m -Xms256m
7+
- APP_SLEEP=10 # for zipkin
8+
ports:
9+
- 9001:9001
10+
zipkin:
11+
image: openzipkin/zipkin
12+
ports:
13+
- 9411:9411
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
echo "The application will start in ${APP_SLEEP}s..." && sleep ${APP_SLEEP}
3+
exec java ${JAVA_OPTS} -noverify -XX:+AlwaysPreTouch -Djava.security.egd=file:/dev/./urandom -cp /app/resources/:/app/classes/:/app/libs/* "com.cevher.ms.department.DepartmentServiceApplication" "$@"

0 commit comments

Comments
 (0)