Skip to content

Commit 6c4d0c1

Browse files
committed
Added Docker Compose for API GATEWAY service. We generated docker image by "Google Container Tools". We used github repository for our configuration by config-server.
1 parent b933f96 commit 6c4d0c1

File tree

5 files changed

+179
-24
lines changed

5 files changed

+179
-24
lines changed

api-gateway/.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/

api-gateway/README.md

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

api-gateway/pom.xml

Lines changed: 50 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>Hoxton.SR11</spring-cloud.version>
19+
<jib-maven-plugin.version>2.8.0</jib-maven-plugin.version>
1920
</properties>
2021
<dependencies>
2122
<dependency>
@@ -84,7 +85,56 @@
8485
<groupId>org.springframework.boot</groupId>
8586
<artifactId>spring-boot-maven-plugin</artifactId>
8687
</plugin>
88+
89+
<plugin>
90+
<groupId>com.google.cloud.tools</groupId>
91+
<artifactId>jib-maven-plugin</artifactId>
92+
</plugin>
93+
8794
</plugins>
95+
96+
<pluginManagement>
97+
<plugins>
98+
<plugin>
99+
<groupId>com.google.cloud.tools</groupId>
100+
<artifactId>jib-maven-plugin</artifactId>
101+
<version>${jib-maven-plugin.version}</version>
102+
<configuration>
103+
<from>
104+
<image>adoptopenjdk:11-jre-hotspot</image>
105+
</from>
106+
<to>
107+
<image>cevheri/api-gateway:latest</image>
108+
</to>
109+
<container>
110+
<entrypoint>
111+
<shell>bash</shell>
112+
<option>-c</option>
113+
<arg>/entrypoint.sh</arg>
114+
</entrypoint>
115+
<ports>
116+
<port>9191</port>
117+
</ports>
118+
<environment>
119+
<SPRING_OUTPUT_ANSI_ENABLED>ALWAYS</SPRING_OUTPUT_ANSI_ENABLED>
120+
<APP_SLEEP>0</APP_SLEEP>
121+
</environment>
122+
<creationTime>USE_CURRENT_TIMESTAMP</creationTime>
123+
<user>1000</user>
124+
</container>
125+
<extraDirectories>
126+
<paths>src/main/docker/jib</paths>
127+
<permissions>
128+
<permission>
129+
<file>/entrypoint.sh</file>
130+
<mode>755</mode>
131+
</permission>
132+
</permissions>
133+
</extraDirectories>
134+
</configuration>
135+
</plugin>
136+
</plugins>
137+
</pluginManagement>
88138
</build>
89139

90140
</project>

api-gateway/src/main/docker/app.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: '3.8'
2+
services:
3+
api-gateway:
4+
image: cevheri/api-gateway
5+
environment:
6+
- _JAVA_OPTIONS=-Xmx512m -Xms256m
7+
ports:
8+
- 9191:9191
9+
zipkin:
10+
image: openzipkin/zipkin
11+
ports:
12+
- 9411:9411
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
exec java ${JAVA_OPTS} -noverify -XX:+AlwaysPreTouch -Djava.security.egd=file:/dev/./urandom -cp /app/resources/:/app/classes/:/app/libs/* "com.cevher.ms.apigateway.APIGatewayApplication" "$@"

0 commit comments

Comments
 (0)