Skip to content

Commit aa6e289

Browse files
committed
I used docker image with Google container tools
1 parent 170e892 commit aa6e289

File tree

5 files changed

+165
-103
lines changed

5 files changed

+165
-103
lines changed

service-registry/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Java Microservice - Service Registry
2+
3+
4+
## Dependencies
5+
* Linux, VirtualBox or Docker Desktop
6+
* Java 11
7+
* Maven
8+
* Spring Boot : 2.5.0
9+
* Spring Boot Starter : https://start.spring.io/
10+
* Spring Cloud : https://spring.io/projects/spring-cloud
11+
* Netflix Eureka Server : https://spring.io/guides/gs/service-registration-and-discovery/
12+
* Google Container Tools : https://github.com/GoogleContainerTools/jib
13+
14+
---
15+
## Development
16+
```shell
17+
$ ./mvnw package
18+
$ java -jar target/*.jar
19+
```
20+
Visit : http://localhost:8761/
21+
22+
---
23+
## Production With Docker
24+
We will create Docker Image using Google Container Tools and run this Docker Image with Docker Compose.
25+
26+
Build docker image:
27+
```shell
28+
$ ./mvnw -Pprod verify jib:dockerBuild
29+
```
30+
Run:
31+
```shell
32+
$ docker-compose -f src/main/docker/app.yml up -d
33+
34+
Creating docker_service-registry_1 ... done
35+
```
36+
Visit : http://localhost:8761/
37+
38+
---
39+
View docker images:
40+
```shell
41+
$ docker images
42+
43+
REPOSITORY TAG IMAGE ID CREATED SIZE
44+
cevheri/service-registry latest 3d6fd7dccfb5 14 minutes ago 291MB
45+
46+
```
47+
48+
View docker containers:
49+
````shell
50+
$ docker ps
51+
52+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
53+
fac279d0d208 cevheri/service-registry "bash -c /entrypoint…" 18 seconds ago Up 16 seconds 0.0.0.0:8761->8761/tcp, :::8761->8761/tcp docker_service-registry_1
54+
````
55+
56+

service-registry/pom.xml

Lines changed: 94 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,104 @@
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>
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>
55

6-
<parent>
7-
<groupId>org.springframework.boot</groupId>
8-
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>2.5.0</version>
10-
<relativePath/> <!-- lookup parent from repository -->
11-
</parent>
6+
<parent>
7+
<groupId>org.springframework.boot</groupId>
8+
<artifactId>spring-boot-starter-parent</artifactId>
9+
<version>2.5.0</version>
10+
<relativePath/> <!-- lookup parent from repository -->
11+
</parent>
1212

13-
<groupId>com.cevher.ms</groupId>
14-
<artifactId>service-registry</artifactId>
15-
<version>0.0.1</version>
16-
<name>service-registry</name>
17-
<description>Service Registry Application</description>
13+
<groupId>com.cevher.ms</groupId>
14+
<artifactId>service-registry</artifactId>
15+
<version>0.0.1</version>
16+
<name>service-registry</name>
17+
<description>Service Registry Application</description>
1818

19-
<properties>
20-
<java.version>11</java.version>
21-
<spring-cloud.version>2020.0.3</spring-cloud.version>
22-
<jib-maven-plugin.version>2.8.0</jib-maven-plugin.version>
23-
</properties>
24-
<dependencies>
25-
<dependency>
26-
<groupId>org.springframework.cloud</groupId>
27-
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
28-
</dependency>
19+
<properties>
20+
<java.version>11</java.version>
21+
<spring-cloud.version>2020.0.3</spring-cloud.version>
22+
<jib-maven-plugin.version>2.8.0</jib-maven-plugin.version>
23+
</properties>
24+
<dependencies>
25+
<dependency>
26+
<groupId>org.springframework.cloud</groupId>
27+
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
28+
</dependency>
2929

30-
<dependency>
31-
<groupId>org.springframework.boot</groupId>
32-
<artifactId>spring-boot-starter-test</artifactId>
33-
<scope>test</scope>
34-
</dependency>
35-
</dependencies>
36-
<dependencyManagement>
37-
<dependencies>
38-
<dependency>
39-
<groupId>org.springframework.cloud</groupId>
40-
<artifactId>spring-cloud-dependencies</artifactId>
41-
<version>${spring-cloud.version}</version>
42-
<type>pom</type>
43-
<scope>import</scope>
44-
</dependency>
45-
</dependencies>
46-
</dependencyManagement>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-test</artifactId>
33+
<scope>test</scope>
34+
</dependency>
35+
</dependencies>
36+
<dependencyManagement>
37+
<dependencies>
38+
<dependency>
39+
<groupId>org.springframework.cloud</groupId>
40+
<artifactId>spring-cloud-dependencies</artifactId>
41+
<version>${spring-cloud.version}</version>
42+
<type>pom</type>
43+
<scope>import</scope>
44+
</dependency>
45+
</dependencies>
46+
</dependencyManagement>
4747

48-
<build>
49-
<plugins>
50-
<plugin>
51-
<groupId>org.springframework.boot</groupId>
52-
<artifactId>spring-boot-maven-plugin</artifactId>
53-
</plugin>
54-
<plugin>
55-
<groupId>com.google.cloud.tools</groupId>
56-
<artifactId>jib-maven-plugin</artifactId>
57-
</plugin>
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-maven-plugin</artifactId>
53+
</plugin>
54+
<plugin>
55+
<groupId>com.google.cloud.tools</groupId>
56+
<artifactId>jib-maven-plugin</artifactId>
57+
</plugin>
58+
</plugins>
5859

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>service-registry: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>8761</port>
82-
<port>8761/udp</port>
83-
</ports>
84-
<environment>
85-
<SPRING_OUTPUT_ANSI_ENABLED>ALWAYS</SPRING_OUTPUT_ANSI_ENABLED>
86-
<JHIPSTER_SLEEP>0</JHIPSTER_SLEEP>
87-
</environment>
88-
<creationTime>USE_CURRENT_TIMESTAMP</creationTime>
89-
<user>1000</user>
90-
</container>
91-
<extraDirectories>
92-
<paths>src/main/docker/jib</paths>
93-
<permissions>
94-
<permission>
95-
<file>/entrypoint.sh</file>
96-
<mode>755</mode>
97-
</permission>
98-
</permissions>
99-
</extraDirectories>
100-
</configuration>
101-
</plugin>
102-
</plugins>
103-
</pluginManagement>
104-
</build>
60+
<pluginManagement>
61+
<plugins>
62+
<plugin>
63+
<groupId>com.google.cloud.tools</groupId>
64+
<artifactId>jib-maven-plugin</artifactId>
65+
<version>${jib-maven-plugin.version}</version>
66+
<configuration>
67+
<from>
68+
<image>adoptopenjdk:11-jre-hotspot</image>
69+
</from>
70+
<to>
71+
<image>cevheri/service-registry:latest</image>
72+
</to>
73+
<container>
74+
<entrypoint>
75+
<shell>bash</shell>
76+
<option>-c</option>
77+
<arg>/entrypoint.sh</arg>
78+
</entrypoint>
79+
<ports>
80+
<port>8761</port>
81+
</ports>
82+
<environment>
83+
<SPRING_OUTPUT_ANSI_ENABLED>ALWAYS</SPRING_OUTPUT_ANSI_ENABLED>
84+
<APP_SLEEP>0</APP_SLEEP>
85+
</environment>
86+
<creationTime>USE_CURRENT_TIMESTAMP</creationTime>
87+
<user>1000</user>
88+
</container>
89+
<extraDirectories>
90+
<paths>src/main/docker/jib</paths>
91+
<permissions>
92+
<permission>
93+
<file>/entrypoint.sh</file>
94+
<mode>755</mode>
95+
</permission>
96+
</permissions>
97+
</extraDirectories>
98+
</configuration>
99+
</plugin>
100+
</plugins>
101+
</pluginManagement>
102+
</build>
105103

106104
</project>
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
#deprecated use app.yml
2-
FROM openjdk:11-jre-slim
1+
# syntax=docker/dockerfile:1
2+
3+
#deprecated
4+
# FROM openjdk:11-jdk
5+
WORKDIR /app
36
ARG JAR_FILE=target/*.jar
47
COPY ${JAR_FILE} app.jar
58
ENTRYPOINT ["java","-jar","/app.jar"]
69
EXPOSE 8761
7-
# docker build -t cevher/microservices-service-registry .
8-
# docker run -p 8761:8761 cevher/microservices-service-registry
10+
11+
12+
# mvn compile jib:dockerBuild
13+
# docker build -t cevher/ms-service-registry .
14+
# docker run -p 8761:8761 cevher/microservices-service-registry
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
version: '3.8'
22
services:
33
service-registry:
4-
image: service-registry
4+
image: cevheri/service-registry
55
environment:
66
- _JAVA_OPTIONS=-Xmx512m -Xms256m
7-
- LOGGING_FILE_NAME=/tmp/microservices-sr.log
7+
- SPRING_PROFILES_ACTIVE=prod,api-docs
8+
- MANAGEMENT_METRICS_EXPORT_PROMETHEUS_ENABLED=true
9+
- APP_SLEEP=10
810
ports:
911
- 8761:8761
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22

3-
echo "The application will start in ..."
3+
echo "The application will start in ${APP_SLEEP}s..." && sleep ${APP_SLEEP}
44
exec java ${JAVA_OPTS} -noverify -XX:+AlwaysPreTouch -Djava.security.egd=file:/dev/./urandom -cp /app/resources/:/app/classes/:/app/libs/* "com.cevher.ms.service.registry.ServiceRegistryApplication" "$@"

0 commit comments

Comments
 (0)