Skip to content

Commit 99ff9fc

Browse files
committed
I used github repository for our configuration, and "Docker image" with "Google container tools" done.
1 parent 1697262 commit 99ff9fc

File tree

8 files changed

+244
-125
lines changed

8 files changed

+244
-125
lines changed

config-server/.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/

config-server/README.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Java Microservice - Config Server
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+
* Spring Boot Starter
11+
* Spring Cloud Config Server
12+
* Netflix Eureka Client
13+
* Google Container Tools
14+
15+
## Configuration
16+
src/main/docker/app.yml
17+
```yaml
18+
version: '3.8'
19+
services:
20+
config-server:
21+
image: cevheri/config-server
22+
environment:
23+
- _JAVA_OPTIONS=-Xmx512m -Xms256m
24+
ports:
25+
- 9296:9296
26+
```
27+
28+
We will use github public repository for our configuration:
29+
https://github.com/cevheri/microservices-config-server
30+
31+
32+
---
33+
## Development
34+
```shell
35+
$ ./mvnw package
36+
$ java -jar target/*.jar
37+
```
38+
Visit : http://localhost:8761/eureka/apps/config-server
39+
40+
---
41+
## Production With Docker
42+
We will create Docker Image using Google Container Tools and run this Docker Image with Docker Compose.
43+
44+
### Build docker image:
45+
```shell
46+
$ ./mvnw -Pprod clean verify jib:dockerBuild
47+
48+
...
49+
[INFO] Executing tasks:
50+
[INFO] [==============================] 100.0% complete
51+
[INFO]
52+
[INFO] ------------------------------------------------------------------------
53+
[INFO] BUILD SUCCESS
54+
[INFO] ------------------------------------------------------------------------
55+
[INFO] Total time: 17.728 s
56+
[INFO] Finished at: 21:45:11+03:00
57+
[INFO] ------------------------------------------------------------------------
58+
```
59+
60+
---
61+
62+
### Run:
63+
```shell
64+
$ docker-compose -f src/main/docker/app.yml up -d
65+
66+
Creating config-server ... done
67+
```
68+
---
69+
Visit : http://localhost:8761/eureka/apps/config-server
70+
```xml
71+
<application>
72+
<name>CONFIG-SERVER</name>
73+
<instance>
74+
<instanceId>192.168.1.57:config-server:9296</instanceId>
75+
<hostName>service-registry</hostName>
76+
<app>CONFIG-SERVER</app>
77+
<ipAddr>192.168.1.57</ipAddr>
78+
<status>UP</status>
79+
<overriddenstatus>UNKNOWN</overriddenstatus>
80+
<port enabled="true">9296</port>
81+
<securePort enabled="false">443</securePort>
82+
<countryId>1</countryId>
83+
<dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
84+
<name>MyOwn</name>
85+
</dataCenterInfo>
86+
<leaseInfo>
87+
<renewalIntervalInSecs>30</renewalIntervalInSecs>
88+
<durationInSecs>90</durationInSecs>
89+
<registrationTimestamp>1623790359757</registrationTimestamp>
90+
<lastRenewalTimestamp>1623790569749</lastRenewalTimestamp>
91+
<evictionTimestamp>0</evictionTimestamp>
92+
<serviceUpTimestamp>1623790359239</serviceUpTimestamp>
93+
</leaseInfo>
94+
<metadata>
95+
<management.port>9296</management.port>
96+
</metadata>
97+
<homePageUrl>http://service-registry:9296/</homePageUrl>
98+
<statusPageUrl>http://service-registry:9296/actuator/info</statusPageUrl>
99+
<healthCheckUrl>http://service-registry:9296/actuator/health</healthCheckUrl>
100+
<vipAddress>config-server</vipAddress>
101+
<secureVipAddress>config-server</secureVipAddress>
102+
<isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
103+
<lastUpdatedTimestamp>1623790359757</lastUpdatedTimestamp>
104+
<lastDirtyTimestamp>1623790359191</lastDirtyTimestamp>
105+
<actionType>ADDED</actionType>
106+
</instance>
107+
</application>
108+
```
109+
110+
---
111+
### View docker images:
112+
```shell
113+
$ docker images
114+
115+
REPOSITORY TAG IMAGE ID CREATED SIZE
116+
cevheri/config-server latest 57a100df8bcd 26 minutes ago 287MB
117+
118+
```
119+
120+
### View docker containers:
121+
````shell
122+
$ docker ps
123+
124+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
125+
1ca74578a26b cevheri/config-server "bash -c /entrypoint…" 8 seconds ago Up 6 seconds 0.0.0.0:9296->9296/tcp, :::9296->9296/tcp docker_config-server_1
126+
127+
````
128+
129+
### Stop Docker Compose:
130+
```shell
131+
$ docker-compose -f src/main/docker/app.yml down
132+
133+
```
134+
---
135+
### Screenshots
136+
137+
![](files/pictures/spring-config-server-eureka-client.png)
45.5 KB
Loading

config-server/pom.xml

Lines changed: 100 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,106 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
5-
<parent>
6-
<groupId>org.springframework.boot</groupId>
7-
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>2.5.0</version>
9-
<relativePath/> <!-- lookup parent from repository -->
10-
</parent>
11-
<groupId>com.cevher.ms</groupId>
12-
<artifactId>config-server</artifactId>
13-
<version>0.0.1-SNAPSHOT</version>
14-
<name>config-server</name>
15-
<description>Config Server Application</description>
16-
<properties>
17-
<java.version>11</java.version>
18-
<spring-cloud.version>2020.0.3</spring-cloud.version>
19-
</properties>
20-
<dependencies>
21-
<dependency>
22-
<groupId>org.springframework.cloud</groupId>
23-
<artifactId>spring-cloud-config-server</artifactId>
24-
</dependency>
25-
<dependency>
26-
<groupId>org.springframework.cloud</groupId>
27-
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
28-
</dependency>
29-
<!-- https://mvnrepository.com/artifact/com.google.cloud.tools/jib-maven-plugin -->
30-
<dependency>
31-
<groupId>com.google.cloud.tools</groupId>
32-
<artifactId>jib-maven-plugin</artifactId>
33-
<version>3.1.1</version>
34-
</dependency>
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.5.0</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
3511

36-
<dependency>
37-
<groupId>org.springframework.boot</groupId>
38-
<artifactId>spring-boot-starter-test</artifactId>
39-
<scope>test</scope>
40-
</dependency>
41-
</dependencies>
42-
<dependencyManagement>
43-
<dependencies>
44-
<dependency>
45-
<groupId>org.springframework.cloud</groupId>
46-
<artifactId>spring-cloud-dependencies</artifactId>
47-
<version>${spring-cloud.version}</version>
48-
<type>pom</type>
49-
<scope>import</scope>
50-
</dependency>
51-
</dependencies>
52-
</dependencyManagement>
12+
<groupId>com.cevher.ms</groupId>
13+
<artifactId>config-server</artifactId>
14+
<version>1.0.0</version>
15+
<name>config-server</name>
16+
<description>Config Server Application</description>
17+
<properties>
18+
<java.version>11</java.version>
19+
<spring-cloud.version>2020.0.3</spring-cloud.version>
20+
<jib-maven-plugin.version>2.8.0</jib-maven-plugin.version>
21+
</properties>
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.springframework.cloud</groupId>
25+
<artifactId>spring-cloud-config-server</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.cloud</groupId>
29+
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-test</artifactId>
34+
<scope>test</scope>
35+
</dependency>
36+
</dependencies>
37+
<dependencyManagement>
38+
<dependencies>
39+
<dependency>
40+
<groupId>org.springframework.cloud</groupId>
41+
<artifactId>spring-cloud-dependencies</artifactId>
42+
<version>${spring-cloud.version}</version>
43+
<type>pom</type>
44+
<scope>import</scope>
45+
</dependency>
46+
</dependencies>
47+
</dependencyManagement>
5348

54-
<build>
55-
<plugins>
56-
<plugin>
57-
<groupId>org.springframework.boot</groupId>
58-
<artifactId>spring-boot-maven-plugin</artifactId>
59-
</plugin>
60-
<plugin>
61-
<groupId>com.google.cloud.tools</groupId>
62-
<artifactId>jib-maven-plugin</artifactId>
63-
<version>3.1.1</version>
64-
<configuration>
65-
<from>
66-
<image>adoptopenjdk:11-jre-hotspot</image>
67-
</from>
68-
<to>
69-
<image>config-server</image>
70-
</to>
71-
<container>
72-
<entrypoint>
73-
<shell>bash</shell>
74-
<option>-c</option>
75-
<arg>/entrypoint.sh</arg>
76-
</entrypoint>
77-
<ports>
78-
<port>9296</port>
79-
<port>9296/udp</port>
80-
</ports>
81-
<environment>
82-
<SPRING_OUTPUT_ANSI_ENABLED>ALWAYS</SPRING_OUTPUT_ANSI_ENABLED>
83-
<SLEEP>0</SLEEP>
84-
</environment>
85-
<creationTime>USE_CURRENT_TIMESTAMP</creationTime>
86-
<user>1000</user>
87-
</container>
88-
<extraDirectories>
89-
<paths>src/main/docker/jib</paths>
90-
<permissions>
91-
<permission>
92-
<file>/entrypoint.sh</file>
93-
<mode>755</mode>
94-
</permission>
95-
</permissions>
96-
</extraDirectories>
97-
</configuration>
98-
</plugin>
99-
</plugins>
100-
</build>
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-maven-plugin</artifactId>
54+
</plugin>
55+
<plugin>
56+
<groupId>com.google.cloud.tools</groupId>
57+
<artifactId>jib-maven-plugin</artifactId>
58+
</plugin>
59+
</plugins>
60+
61+
<pluginManagement>
62+
<plugins>
63+
<plugin>
64+
<groupId>com.google.cloud.tools</groupId>
65+
<artifactId>jib-maven-plugin</artifactId>
66+
<version>${jib-maven-plugin.version}</version>
67+
<configuration>
68+
<from>
69+
<image>adoptopenjdk:11-jre-hotspot</image>
70+
</from>
71+
<to>
72+
<image>cevheri/config-server:latest</image>
73+
</to>
74+
<container>
75+
<entrypoint>
76+
<shell>bash</shell>
77+
<option>-c</option>
78+
<arg>/entrypoint.sh</arg>
79+
</entrypoint>
80+
<ports>
81+
<port>9296</port>
82+
</ports>
83+
<environment>
84+
<SPRING_OUTPUT_ANSI_ENABLED>ALWAYS</SPRING_OUTPUT_ANSI_ENABLED>
85+
<APP_SLEEP>0</APP_SLEEP>
86+
</environment>
87+
<creationTime>USE_CURRENT_TIMESTAMP</creationTime>
88+
<user>1000</user>
89+
</container>
90+
<extraDirectories>
91+
<paths>src/main/docker/jib</paths>
92+
<permissions>
93+
<permission>
94+
<file>/entrypoint.sh</file>
95+
<mode>755</mode>
96+
</permission>
97+
</permissions>
98+
</extraDirectories>
99+
</configuration>
100+
</plugin>
101+
</plugins>
102+
</pluginManagement>
103+
104+
</build>
101105

102106
</project>

config-server/src/main/docker/app.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ services:
44
image: cevheri/config-server
55
environment:
66
- _JAVA_OPTIONS=-Xmx512m -Xms256m
7-
- LOGGING_FILE_NAME=/tmp/microservices-sr.log
87
ports:
9-
- 9296:9296
8+
- 9296:9296
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#!/bin/sh
22

3-
echo "The application will start in ..."
43
exec java ${JAVA_OPTS} -noverify -XX:+AlwaysPreTouch -Djava.security.egd=file:/dev/./urandom -cp /app/resources/:/app/classes/:/app/libs/* "com.cevher.ms.config.ConfigServerApplication" "$@"

0 commit comments

Comments
 (0)