Skip to content

Commit 95863ae

Browse files
Merge pull request #19 from TajudeenBusari/implementing-github-action-work-flow
Implementing GitHub action work flow
2 parents 2f57006 + b68e66d commit 95863ae

File tree

34 files changed

+581
-56
lines changed

34 files changed

+581
-56
lines changed

.github/workflows/maven-build.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Ecommerce Microservices CI with Maven
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
jobs:
8+
build:
9+
name: Build All Modules (skip tests)
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Check out the repository
14+
uses: actions/checkout@v4
15+
- name: Set up JDK 17
16+
uses: actions/setup-java@v3
17+
with:
18+
java-version: '17'
19+
distribution: 'temurin'
20+
cache: maven
21+
- name: Build all modules (skipping tests)
22+
run: mvn --batch-mode clean install -DskipTests
23+
outputs:
24+
build-status-key: ${{ steps.cache.outputs.cache-hit }}
25+
26+
test:
27+
name: Run Tests
28+
runs-on: ubuntu-latest
29+
needs: build
30+
steps:
31+
- name: Check out the repository
32+
uses: actions/checkout@v4
33+
- name: Set up JDK 17
34+
uses: actions/setup-java@v3
35+
with:
36+
java-version: '17'
37+
distribution: 'temurin'
38+
cache: maven
39+
- name: Run tests
40+
run: mvn --batch-mode test
41+
42+
43+
44+
45+
# pull_request:
46+
# branches:
47+
# - master
48+
#jobs:
49+
# build-and-test:
50+
# runs-on: ubuntu-latest
51+
#
52+
# strategy:
53+
# matrix:
54+
# service: [product-service,
55+
# order-service,
56+
# inventory-service,
57+
# api-gateway,
58+
# config-server,
59+
# eureka-server]
60+
# steps:
61+
# - name: Check out the repository
62+
# uses: actions/checkout@v4
63+
# - name: Set up JDK 17
64+
# uses: actions/setup-java@v3
65+
# with:
66+
# java-version: '17'
67+
# distribution: 'temurin'
68+
# cache: maven
69+
#
70+
#
71+
# - name: Build and test ${matrix.service}
72+
# working-directory: ./${{ matrix.service }}
73+
# run: mvn --batch-mode package

.idea/dataSources/dbb0ccd9-06dd-407f-b700-8142fac9bbbd.xml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/dataSources/dbb0ccd9-06dd-407f-b700-8142fac9bbbd/storage_v2/_src_/database/ECommerce-Inventory-Service.t2ibDQ/schema/public.abK9xQ.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

894 Bytes

maven command for cleaning and building the project: mvn clean install -DskipTests To highlight text in the editor: File -> Settings -> Editor -> TODO-> Add a new pattern and chose a color.

  • POTENTIAL MEMORY LEAKS:
    • When using WebClient, ensure that you are not creating a new instance of WebClient for each request.
      Instead, create a single instance of WebClient and reuse it for all requests.
      This will help in reducing memory leaks and improving performance.
      Use the WebClient.Builder to create a single instance of WebClient and reuse it for all requests.
      This will help in reducing memory leaks and improving performance.
      #What was observed during integration testing:
      The web application [ROOT] appears to have started a thread named [reactor-http-nio-*] but has failed to stop it. 
      This is very likely to create a memory leak:
      is a very common issue when using Netty-based servers (like Spring Webflux or reactive cleint like WebClient)
      in integration tests, espcially when tests are run inside Spring boot + Tomcat(Servlet-based) environment.
      For now, it is been suppressed by setting the following property in the application-test.yml file
      with: logging:
        level:
        org.apache.catalina.loader.WebappClassLoaderBase: ERROR
      
    • API DOCUMENTATION:
      • Use Swagger or Spring REST Docs to document the APIs.
        
      • Add the dependency in the pom.xml file for Swagger or Spring REST Docs.
        
      • Configure the application.yml file with the Swagger or Spring REST Docs details.
        
      • Expose an API to get the API documentation.
        
      • In this project, we will use springdoc-openapi-ui for API documentation (springdoc.org).
        
      • AUtomatically generate doc in JSON/YML and HTML formats APIs. Check more from the link:
        https://springdoc.org
        
        • STEPS TO ADD SPRINGDOC-OPENAPI-UI: - Add the following dependency in the pom.xml file for springdoc-openapi-ui. - change path in the application.yml: e.g., http://localhost:port/swagger-ui.html - Add the @OpenAPIDefinition annotation in the main class of the services. - Configure the application.yml file with the springdoc-openapi-ui details. - Expose an API to get the API documentation. - Access the API documentation at http://localhost:port/swagger-ui.html
      • dependency in the pom.xml file for springdoc-openapi-ui in HTML format.
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.8.9</version>
        </dependency>
        
      • dependency in the pom.xml file for springdoc-openapi-ui in JSON/YML format.
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
            <version>2.8.9</version>
        </dependency>
        
      • command to run docker compose file from the common-utils folder:
         ****docker compose -f docker-compose.yml up --build
        
      • command to run docker compose file from the root folder:
        *****docker compose -f common-utils/docker-compose.yml up --build
        
      • Check actuator endpoints in the browser:
        *****http://localhost:port/actuator/health
        
  • API DOCUMENTATION:
    • Use Swagger or Spring REST Docs to document the APIs.
      
    • Add the dependency in the pom.xml file for Swagger or Spring REST Docs.
      
    • Configure the application.yml file with the Swagger or Spring REST Docs details.
      
    • Expose an API to get the API documentation.
      
    • In this project, we will use springdoc-openapi-ui for API documentation (springdoc.org).
      
    • AUtomatically generate doc in JSON/YML and HTML formats APIs. Check more from the link:
      https://springdoc.org
      
      • STEPS TO ADD SPRINGDOC-OPENAPI-UI: - Add the following dependency in the pom.xml file for springdoc-openapi-ui. - change path in the application.yml: e.g., http://localhost:port/swagger-ui.html - Add the @OpenAPIDefinition annotation in the main class of the services. - Configure the application.yml file with the springdoc-openapi-ui details. - Expose an API to get the API documentation. - Access the API documentation at http://localhost:port/swagger-ui.html
    • dependency in the pom.xml file for springdoc-openapi-ui in HTML format.
      <dependency>
          <groupId>org.springdoc</groupId>
          <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
          <version>2.8.9</version>
      </dependency>
      
    • dependency in the pom.xml file for springdoc-openapi-ui in JSON/YML format.
      <dependency>
          <groupId>org.springdoc</groupId>
          <artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
          <version>2.8.9</version>
      </dependency>
      

api-gateway/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM eclipse-temurin:17-jre as builder
2+
WORKDIR application
3+
ARG JAR_FILE=target/*.jar
4+
COPY ${JAR_FILE} application.jar
5+
RUN java -Djarmode=layertools -jar application.jar extract
6+
7+
FROM eclipse-temurin:17-jre
8+
WORKDIR application
9+
COPY --from=builder application/dependencies/ ./
10+
COPY --from=builder application/spring-boot-loader/ ./
11+
COPY --from=builder application/snapshot-dependencies/ ./
12+
COPY --from=builder application/application/ ./
13+
ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"]
14+
EXPOSE 8080

api-gateway/pom.xml

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
<artifactId>spring-boot-starter-actuator</artifactId>
4141
</dependency>
4242

43-
44-
4543
<dependency>
4644
<groupId>org.springframework.cloud</groupId>
4745
<artifactId>spring-cloud-starter-circuitbreaker-reactor-resilience4j</artifactId>
@@ -58,23 +56,43 @@
5856
<groupId>org.springframework.cloud</groupId>
5957
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
6058
</dependency>
59+
6160
<dependency>
6261
<groupId>org.springframework.cloud</groupId>
6362
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
63+
<exclusions>
64+
<exclusion>
65+
<groupId>org.springframework.boot</groupId>
66+
<artifactId>spring-boot-starter-web</artifactId>
67+
</exclusion>
68+
</exclusions>
6469
</dependency>
6570

6671
<!--Add spring cloud config client dependency so application can use the
6772
config server configuration-->
6873
<dependency>
6974
<groupId>org.springframework.cloud</groupId>
7075
<artifactId>spring-cloud-starter-config</artifactId>
76+
<exclusions>
77+
<exclusion>
78+
<groupId>org.springframework.boot</groupId>
79+
<artifactId>spring-boot-starter-web</artifactId>
80+
</exclusion>
81+
</exclusions>
82+
7183
</dependency>
7284

7385
<!--Add spring cloud bootstrap dependency so application can use the
7486
config server config file-->
7587
<dependency>
7688
<groupId>org.springframework.cloud</groupId>
7789
<artifactId>spring-cloud-starter-bootstrap</artifactId>
90+
<exclusions>
91+
<exclusion>
92+
<groupId>org.springframework.boot</groupId>
93+
<artifactId>spring-boot-starter-web</artifactId>
94+
</exclusion>
95+
</exclusions>
7896
</dependency>
7997

8098
<dependency>
@@ -88,18 +106,23 @@
88106
<scope>test</scope>
89107
</dependency>
90108

91-
<!-- api documentation HTML FORMAT AND JSON FORMAT-->
92109
<dependency>
93-
<groupId>org.springdoc</groupId>
94-
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
95-
<version>2.8.9</version>
110+
<groupId>org.springframework.boot</groupId>
111+
<artifactId>spring-boot-starter-webflux</artifactId>
96112
</dependency>
97113

98-
<dependency>
99-
<groupId>org.springdoc</groupId>
100-
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
101-
<version>2.8.9</version>
102-
</dependency>
114+
<!-- api documentation HTML FORMAT AND JSON FORMAT-->
115+
<!-- <dependency>-->
116+
<!-- <groupId>org.springdoc</groupId>-->
117+
<!-- <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>-->
118+
<!-- <version>2.8.9</version>-->
119+
<!-- </dependency>-->
120+
121+
<!-- <dependency>-->
122+
<!-- <groupId>org.springdoc</groupId>-->
123+
<!-- <artifactId>springdoc-openapi-starter-webmvc-api</artifactId>-->
124+
<!-- <version>2.8.9</version>-->
125+
<!-- </dependency>-->
103126

104127
<dependency>
105128
<groupId>org.springdoc</groupId>

api-gateway/src/main/java/com/tjtechy/api_gateway/Config/CorsGlobalConfig.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,30 @@ public class CorsGlobalConfig {
2323
public CorsWebFilter corsWebFilter() {
2424
CorsConfiguration config = new CorsConfiguration();
2525
config.setAllowCredentials(true);
26-
config.addAllowedOriginPattern("*"); // Allow all origins
27-
config.setAllowedHeaders(Arrays.asList("*"));
28-
config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS"));
26+
config.setAllowedOriginPatterns(Arrays.asList(
27+
"http://localhost:[*]",
28+
"http://127.0.0.1:[*]",
29+
"http://host.docker.internal:[*]",
30+
"http://172.*.*.*:[*]",
31+
"http://192.168.*.*:[*]",
32+
"http://10.*.*.*:[*]",
33+
"https://docs.swagger.io"
34+
));
35+
config.setAllowedHeaders(Arrays.asList(
36+
"Authorization",
37+
"Content-Type",
38+
"X-Requested-With",
39+
"Origin",
40+
"Accept",
41+
"Access-Control-Request-Method",
42+
"Access-Control-Request-Headers"));
43+
config.setAllowedMethods(Arrays.asList(
44+
"GET",
45+
"POST",
46+
"PUT",
47+
"DELETE",
48+
"OPTIONS"));
49+
2950
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
3051
source.registerCorsConfiguration("/**", config);
3152
return new CorsWebFilter(source);

api-gateway/src/main/resources/application.yml

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11
server:
22
port: 8080
33
spring:
4+
main:
5+
web-application-type: reactive #use reactive web application type
46
application:
57
name: api-gateway
6-
springdoc: #access at http://localhost:8080/swagger-ui.html
7-
api-docs:
8-
path: /api-docs
9-
swagger-ui:
10-
path: /swagger-ui.html
11-
urls:
12-
- name: Product Service
13-
url: /aggregate/product-service/v3/api-docs
14-
- name: Inventory Service
15-
url: /aggregate/inventory-service/v3/api-docs
16-
- name: Order Service
17-
url: /aggregate/order-service/v3/api-docs
18-
198
cloud:
209
gateway:
2110
discovery:
2211
locator:
2312
enabled: true
13+
#new
14+
globalcors:
15+
cors-configurations:
16+
'[/**]':
17+
allowedOriginPatterns: #allow all origins
18+
- "http://localhost:[*]"
19+
- "http://127.0.0.1:[*]"
20+
- "http://host.docker.internal:[*]"# Docker host
21+
- "http://api-gateway:[*]" # Docker Compose service name
22+
- "http://inventory-service:[*]"
23+
- "http://product-service:[*]"
24+
- "http://order-service:[*]"
25+
- "https://docs.swagger.io"
26+
27+
allowedMethods: #allow all methods
28+
- GET
29+
- POST
30+
- PUT
31+
- DELETE
32+
- OPTIONS
33+
- PATCH
34+
allowedHeaders: #allow all headers
35+
- '*'
36+
allowCredentials: true #allow credentials
37+
maxAge: 3600 #cache preflight response for 1 hour
38+
# new
2439
routes:
2540
#product api route
2641
- id: product-service
@@ -60,10 +75,32 @@ springdoc: #access at http://localhost:8080/swagger-ui.html
6075
- Path=/aggregate/order-service/v3/api-docs
6176
filters:
6277
- RewritePath=/aggregate/order-service/v3/api-docs, /v3/api-docs
78+
springdoc: #access at http://localhost:8080/swagger-ui.html
79+
api-docs:
80+
path: /api-docs
81+
swagger-ui:
82+
path: /swagger-ui.html
83+
urls:
84+
- name: Product Service
85+
url: /aggregate/product-service/v3/api-docs
86+
- name: Inventory Service
87+
url: /aggregate/inventory-service/v3/api-docs
88+
- name: Order Service
89+
url: /aggregate/order-service/v3/api-docs
90+
91+
6392
logging:
6493
level:
6594
org.springframework.cloud.gateway: INFO
6695
com.tjtechy: DEBUG
96+
management:
97+
endpoints:
98+
web:
99+
exposure:
100+
include: health,info
101+
endpoint:
102+
health:
103+
show-details: always #show details in the health endpoint
67104

68105

69106
#I will create custom filters later and will be added here

common-utils/.env

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# env file
2+
3+
DB_USER=postgres
4+
DB_PASSWORD=postgres
5+
6+
# Optional: You can define default DB names per service for local development
7+
ORDER_DB=ECommerce-Order-Service
8+
PRODUCT_DB=ECommerce-Product-Service
9+
INVENTORY_DB=ECommerce-Inventory-Service

0 commit comments

Comments
 (0)