Skip to content

Commit cb34778

Browse files
committed
Added Docker Compose for Person service with zipkin. We generated docker image by "Google Container Tools". We used github repository for our configuration by config-server.
1 parent 99ff9fc commit cb34778

File tree

6 files changed

+216
-24
lines changed

6 files changed

+216
-24
lines changed

person-service/.gitignore

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,13 @@
1-
HELP.md
1+
22
target/
3+
.vscode/
4+
35
!.mvn/wrapper/maven-wrapper.jar
46
!**/src/main/**/target/
57
!**/src/test/**/target/
68

7-
### STS ###
8-
.apt_generated
9-
.classpath
10-
.factorypath
11-
.project
12-
.settings
13-
.springBeans
14-
.sts4-cache
15-
169
### IntelliJ IDEA ###
17-
.idea
10+
.idea/
1811
*.iws
1912
*.iml
2013
*.ipr
21-
22-
### NetBeans ###
23-
/nbproject/private/
24-
/nbbuild/
25-
/dist/
26-
/nbdist/
27-
/.nb-gradle/
28-
build/
29-
!**/src/main/**/build/
30-
!**/src/test/**/build/
31-
32-
### VS Code ###
33-
.vscode/

person-service/README.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Java Microservices - Person 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+
person-service:
22+
image: cevheri/person-service
23+
environment:
24+
- _JAVA_OPTIONS=-Xmx512m -Xms256m
25+
- APP_SLEEP=10 # for zipkin
26+
ports:
27+
- 9002:9002
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/person-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 person-service ... done
73+
```
74+
---
75+
Visit : http://localhost:8761/eureka/apps/person-service
76+
```xml
77+
<application>
78+
<name>PERSON-SERVICE</name>
79+
<instance>
80+
<instanceId>192.168.1.57:person-service:9002</instanceId>
81+
<hostName>service-registry</hostName>
82+
<app>PERSON-SERVICE</app>
83+
<ipAddr>192.168.1.57</ipAddr>
84+
<status>UP</status>
85+
<overriddenstatus>UNKNOWN</overriddenstatus>
86+
<port enabled="true">9002</port>
87+
<securePort enabled="false">443</securePort>
88+
<countryId>1</countryId>
89+
<dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
90+
<name>MyOwn</name>
91+
</dataCenterInfo>
92+
<leaseInfo>
93+
<renewalIntervalInSecs>30</renewalIntervalInSecs>
94+
<durationInSecs>90</durationInSecs>
95+
<registrationTimestamp>1623793389087</registrationTimestamp>
96+
<lastRenewalTimestamp>1623793539062</lastRenewalTimestamp>
97+
<evictionTimestamp>0</evictionTimestamp>
98+
<serviceUpTimestamp>1623793388576</serviceUpTimestamp>
99+
</leaseInfo>
100+
<metadata>
101+
<management.port>9002</management.port>
102+
</metadata>
103+
<homePageUrl>http://service-registry:9002/</homePageUrl>
104+
<statusPageUrl>http://service-registry:9002/actuator/info</statusPageUrl>
105+
<healthCheckUrl>http://service-registry:9002/actuator/health</healthCheckUrl>
106+
<vipAddress>person-service</vipAddress>
107+
<secureVipAddress>person-service</secureVipAddress>
108+
<isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
109+
<lastUpdatedTimestamp>1623793389087</lastUpdatedTimestamp>
110+
<lastDirtyTimestamp>1623793388537</lastDirtyTimestamp>
111+
<actionType>ADDED</actionType>
112+
</instance>
113+
</application>
114+
```
115+
116+
---
117+
### View docker images:
118+
```shell
119+
$ docker images
120+
121+
REPOSITORY TAG IMAGE ID CREATED SIZE
122+
cevheri/person-service latest 57a100df8bcd 26 minutes ago 287MB
123+
124+
```
125+
126+
### View docker containers:
127+
````shell
128+
$ docker ps
129+
130+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
131+
2ca74578a26c cevheri/person-service "bash -c /entrypoint…" 8 seconds ago Up 6 seconds 0.0.0.0:9002->9002/tcp, :::9002->9002/tcp person-service
132+
133+
````
134+
135+
### Stop Docker Compose:
136+
```shell
137+
$ docker-compose -f src/main/docker/app.yml down
138+
139+
```
140+
141+
---
142+
### Screenshots
143+
144+
![](files/pictures/eureka-person-service.png)
67.9 KB
Loading

person-service/pom.xml

Lines changed: 52 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
<dependency>
@@ -84,6 +85,7 @@
8485
</dependencyManagement>
8586

8687
<build>
88+
8789
<plugins>
8890
<plugin>
8991
<groupId>org.springframework.boot</groupId>
@@ -97,7 +99,57 @@
9799
</excludes>
98100
</configuration>
99101
</plugin>
102+
103+
<plugin>
104+
<groupId>com.google.cloud.tools</groupId>
105+
<artifactId>jib-maven-plugin</artifactId>
106+
</plugin>
107+
100108
</plugins>
109+
110+
<pluginManagement>
111+
<plugins>
112+
<plugin>
113+
<groupId>com.google.cloud.tools</groupId>
114+
<artifactId>jib-maven-plugin</artifactId>
115+
<version>${jib-maven-plugin.version}</version>
116+
<configuration>
117+
<from>
118+
<image>adoptopenjdk:11-jre-hotspot</image>
119+
</from>
120+
<to>
121+
<image>cevheri/person-service:latest</image>
122+
</to>
123+
<container>
124+
<entrypoint>
125+
<shell>bash</shell>
126+
<option>-c</option>
127+
<arg>/entrypoint.sh</arg>
128+
</entrypoint>
129+
<ports>
130+
<port>9002</port>
131+
</ports>
132+
<environment>
133+
<SPRING_OUTPUT_ANSI_ENABLED>ALWAYS</SPRING_OUTPUT_ANSI_ENABLED>
134+
<APP_SLEEP>0</APP_SLEEP>
135+
</environment>
136+
<creationTime>USE_CURRENT_TIMESTAMP</creationTime>
137+
<user>1000</user>
138+
</container>
139+
<extraDirectories>
140+
<paths>src/main/docker/jib</paths>
141+
<permissions>
142+
<permission>
143+
<file>/entrypoint.sh</file>
144+
<mode>755</mode>
145+
</permission>
146+
</permissions>
147+
</extraDirectories>
148+
</configuration>
149+
</plugin>
150+
</plugins>
151+
</pluginManagement>
152+
101153
</build>
102154

103155
</project>
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+
person-service:
4+
image: cevheri/person-service
5+
environment:
6+
- _JAVA_OPTIONS=-Xmx512m -Xms256m
7+
- APP_SLEEP=10 # for zipkin
8+
ports:
9+
- 9002:9002
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.person.PersonServiceApplication" "$@"

0 commit comments

Comments
 (0)