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+

0 commit comments

Comments
 (0)