Skip to content

Commit 1a15245

Browse files
authored
Merge pull request #25 from Nasruddin/master
Revamp Sync
2 parents 8600bfd + ec2b775 commit 1a15245

File tree

56 files changed

+939
-84
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+939
-84
lines changed

.DS_Store

8 KB
Binary file not shown.

.github/workflows/docker-image.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Build the Docker image
18+
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)

.github/workflows/maven.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Java CI with Maven
10+
11+
on:
12+
push:
13+
branches: [ "master" ]
14+
pull_request:
15+
branches: [ "master" ]
16+
17+
jobs:
18+
build:
19+
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v3
24+
- name: Set up JDK 17
25+
uses: actions/setup-java@v3
26+
with:
27+
java-version: '17'
28+
distribution: 'temurin'
29+
cache: maven
30+
- name: Build with Maven
31+
run: mvn -B package --file pom.xml
32+
33+
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
34+
- name: Update dependency graph
35+
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
/.idea/
1+
*.*
22
/Status
3+

README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,52 @@
11
# spring-boot-based-microservices
22

3-
Basic skeleton for Spring Boot Microservices. It includes spring spring security for basic Auth. Zuul is also implemented as an API gateway. Lots of the spring cloud component integrated.
3+
Basic skeleton for Spring Boot Microservices. It includes spring security for basic Auth. Spring cloud gateway is also implemented as an Edge Service. Lots of the spring cloud component integrated.
44

5+
# How to run
6+
7+
- Navigate to root of the project
8+
```
9+
cd spring-boot-based-microservices
10+
```
11+
- Build the project
12+
```
13+
mvn clean package -DskipTests
14+
```
15+
![Maven Build](https://github.com/Nasruddin/spring-boot-based-microservices/blob/master/images/build.png?raw=true)
16+
17+
- Locate the docker directory from the root directory and run docker compose to startup the containers
18+
```
19+
cd docker && docker compose up --build
20+
```
21+
![Docker Compose Build](https://github.com/Nasruddin/spring-boot-based-microservices/blob/master/images/docker-compose.png?raw=true)
22+
23+
- Check if all our services are running and healthy
24+
```
25+
docker ps
26+
```
27+
![Docker PS](https://github.com/Nasruddin/spring-boot-based-microservices/blob/master/images/docker-ps.png?raw=true)
28+
29+
- Let's check if all the services are up and running. We will reach to eureka server using gateway.
30+
Open the browser and hit http://localhost:8443/eureka/web You will need to authenticate yourself before accessing the endpoint.
31+
```
32+
username : user
33+
password : password
34+
```
35+
![Eureka](https://github.com/Nasruddin/spring-boot-based-microservices/blob/master/images/eureka.png?raw=true)
36+
37+
- Now, we have a look at our gateway endpoints configurations as well. Hit http://localhost:8443/actuator/gateway/routes in the browser again and, you should be able to find all the routes configured.
38+
![Gateway Routes](https://github.com/Nasruddin/spring-boot-based-microservices/blob/master/images/gateway-routes.png?raw=true)
39+
40+
41+
- Coming to swagger/openapi specs, here is the address to access them - http://localhost:8443/openapi/swagger-ui.html
42+
![Swagger OpenApi Specs](https://github.com/Nasruddin/spring-boot-based-microservices/blob/master/images/swagger-openapi.png?raw=true)
43+
44+
- Please use the below curl to generate the access token with both read and write scope.
45+
```
46+
curl -k http://writer:secret-writer@localhost:8443/oauth2/token -d grant_type=client_credentials -d scope="course:read course:write"
47+
```
48+
![Swagger OpenApi Specs](https://github.com/Nasruddin/spring-boot-based-microservices/blob/master/images/oauth-endpoint.png?raw=true)
49+
![Swagger OpenApi Specs](https://github.com/Nasruddin/spring-boot-based-microservices/blob/master/images/jwt-io.png?raw=true)
50+
51+
## Note : Currently this project uses Spring Authorization server. Keep in mind, I'm planning to enhance the whole OAuth flow because it's in shaky state right now and, you may some face issues. We may also move to keycloak.
52+
## These instructions are basic starting point and, the project does lot of other stuff like elastic and mongo configuration etc. Please feel free to play around. I really want to maintain this and keep up-to-date, however my current role doesn't give me enough spare time. Therefore, contributors and their contributions are welcome :)

api/pom.xml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>2.6.6</version>
8+
<version>3.4.3</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111
<groupId>io.javatab.microservices.api</groupId>
1212
<artifactId>api</artifactId>
1313
<version>1.0.0</version>
14+
<packaging>jar</packaging>
1415
<name>api</name>
1516
<description>Demo project for Spring Boot</description>
1617
<properties>
@@ -41,11 +42,18 @@
4142
<build>
4243
<plugins>
4344
<plugin>
44-
<groupId>org.springframework.boot</groupId>
45-
<artifactId>spring-boot-maven-plugin</artifactId>
46-
<configuration>
47-
<classifier>exec</classifier>
48-
</configuration>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-maven-plugin</artifactId>
47+
<version>3.4.3</version> <!-- Match your Spring Boot version -->
48+
<executions>
49+
<execution>
50+
<id>repackage</id>
51+
<phase>none</phase>
52+
<goals>
53+
<goal>repackage</goal>
54+
</goals>
55+
</execution>
56+
</executions>
4957
</plugin>
5058
</plugins>
5159
</build>

api/src/test/java/io/javatab/microservices/api/ApiApplicationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.junit.jupiter.api.Test;
44
import org.springframework.boot.test.context.SpringBootTest;
55

6-
@SpringBootTest
6+
@SpringBootTest()
77
class ApiApplicationTests {
88

99
@Test

config-repo/auth-server.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server.port: 9999
2+
server.forward-headers-strategy: framework

config-repo/course-composite.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ springdoc:
99
cache:
1010
disabled: true
1111
swagger-ui:
12-
oauth2-redirect-url: https://localhost:8443/webjars/swagger-ui/oauth2-redirect.html
12+
oauth2-redirect-url: http://localhost:8443/webjars/swagger-ui/oauth2-redirect.html
1313
oauth:
1414
clientId: writer
1515
clientSecret: secret
1616
useBasicAuthenticationWithAccessCodeGrant: true
1717
oAuthFlow:
18-
authorizationUrl: https://localhost:8443/oauth2/authorize
19-
tokenUrl: https://localhost:8443/oauth2/token
18+
authorizationUrl: http://localhost:8443/oauth2/authorize
19+
tokenUrl: http://localhost:8443/oauth2/token
2020

2121
server.forward-headers-strategy: framework
2222

config-repo/eureka-server.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
server:
2+
port: 8761
3+
4+
eureka:
5+
instance:
6+
hostname: localhost
7+
client:
8+
registerWithEureka: false
9+
fetchRegistry: false
10+
serviceUrl:
11+
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
12+
# from: https://github.com/spring-cloud-samples/eureka/blob/master/src/main/resources/application.yml
13+
server:
14+
waitTimeInMsWhenSyncEmpty: 0
15+
response-cache-update-interval-ms: 5000
16+
17+

config-repo/gateway.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
server.port: 8443
2+
test1.data: helloupdate
3+
logging:
4+
level:
5+
root: INFO
6+
org.springframework.cloud.gateway.route.RouteDefinitionRouteLocator: INFO
7+
org.springframework.cloud.gateway: TRACE
8+
org.springframework.web.server.adapter.HttpWebHandlerAdapter: TRACE
9+
10+
spring.cloud.gateway.routes:
11+
- id: course-composite
12+
uri: lb://course-composite
13+
predicates:
14+
- Path=/course-composite/**
15+
16+
- id: oauth2-server
17+
uri: lb://auth-server
18+
predicates:
19+
- Path=/oauth2/**
20+
21+
- id: oauth2-login
22+
uri: lb://auth-server
23+
predicates:
24+
- Path=/login/**
25+
26+
- id: oauth2-error
27+
uri: lb://auth-server
28+
predicates:
29+
- Path=/error/**
30+
31+
- id: course-composite-swagger-ui
32+
uri: lb://course-composite
33+
predicates:
34+
- Path=/openapi/**
35+
36+
- id: course-composite-swagger-ui-webjars
37+
uri: lb://course-composite
38+
predicates:
39+
- Path=/webjars/**
40+
41+
- id: eureka-api
42+
uri: http://${app.eureka-server}:8761
43+
predicates:
44+
- Path=/eureka/api/{segment}
45+
filters:
46+
- SetPath=/eureka/{segment}
47+
48+
- id: eureka-web-start
49+
uri: http://${app.eureka-server}:8761
50+
predicates:
51+
- Path=/eureka/web
52+
filters:
53+
- SetPath=/
54+
55+
- id: eureka-web-other
56+
uri: http://${app.eureka-server}:8761
57+
predicates:
58+
- Path=/eureka/**
59+
- id: config-server
60+
uri: ${spring.cloud.config.uri}
61+
predicates:
62+
- Path=/config/**
63+
filters:
64+
- RewritePath=/config/(?<segment>.*), /$\{segment}
65+
66+
spring.security.oauth2.resourceserver.jwt.issuer-uri: http://${app.auth-server}:9999
67+
68+
69+
management.endpoint.gateway.enabled: true
70+
management.endpoints.web.exposure.include: "*"
71+
72+
#server.ssl:
73+
# key-store-type: PKCS12
74+
# key-store: classpath:keystore/edge.p12
75+
# key-store-password: password
76+
# key-alias: localhost

create-project.bash

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env bash
22

3-
mkdir microservices
4-
cd microservices
3+
mkdir spring-boot-based-microservices
4+
cd spring-boot-based-microservices
55

66
spring init \
7-
--boot-version=2.5.2 \
7+
--boot-version=3.4.3 \
88
--build=maven \
99
--java-version=17 \
1010
--packaging=jar \
@@ -16,7 +16,7 @@ spring init \
1616
student-service
1717

1818
spring init \
19-
--boot-version=2.5.2 \
19+
--boot-version=3.4.3 \
2020
--build=maven \
2121
--java-version=17 \
2222
--packaging=jar \
@@ -28,7 +28,7 @@ spring init \
2828
course-service
2929

3030
spring init \
31-
--boot-version=2.5.2 \
31+
--boot-version=3.4.3 \
3232
--build=maven \
3333
--java-version=17 \
3434
--packaging=jar \
@@ -40,7 +40,7 @@ spring init \
4040
vote-service
4141

4242
spring init \
43-
--boot-version=2.5.2 \
43+
--boot-version=3.4.3 \
4444
--build=maven \
4545
--java-version=17 \
4646
--packaging=jar \
@@ -52,7 +52,7 @@ spring init \
5252
search-service
5353

5454
spring init \
55-
--boot-version=2.5.2 \
55+
--boot-version=3.4.3 \
5656
--build=maven \
5757
--java-version=17 \
5858
--packaging=jar \
@@ -63,4 +63,4 @@ spring init \
6363
--version=1.0.0 \
6464
course-composite-service
6565

66-
cd ..
66+
cd ..

docker/docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '2.1'
2-
31
services:
42
course:
53
build: ../microservices/course-service

images/build.png

642 KB
Loading

images/docker-compose.png

147 KB
Loading

images/docker-ps.png

645 KB
Loading

images/eureka.png

498 KB
Loading

images/gateway-routes.png

196 KB
Loading

images/jwt-io.png

201 KB
Loading

images/oauth-endpoint.png

212 KB
Loading

images/swagger-openapi.png

371 KB
Loading
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# stage 1
22
# Start with a base image containing Java runtime
3-
# TODO :: Upgrade to slim jre version for 17 once available
4-
FROM openjdk:17-alpine as builder
3+
FROM eclipse-temurin:17-jre-alpine as builder
54
WORKDIR application
65
ARG JAR_FILE=target/*.jar
76
COPY ${JAR_FILE} application.jar
87
RUN java -Djarmode=layertools -jar application.jar extract
98

109
# the second stage of our build will copy the extracted layers
11-
FROM openjdk:17-alpine
10+
FROM eclipse-temurin:17-jre-alpine
1211
WORKDIR application
12+
# Copy extracted layers into the correct locations
1313
COPY --from=builder application/dependencies/ ./
1414
COPY --from=builder application/spring-boot-loader/ ./
1515
COPY --from=builder application/snapshot-dependencies/ ./
1616
COPY --from=builder application/application/ ./
1717

1818
EXPOSE 8080
1919

20-
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
20+
ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"]

0 commit comments

Comments
 (0)