Skip to content

Commit

Permalink
Setup api gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
dksifoua committed Sep 12, 2024
1 parent 9bb4470 commit c0b44d4
Show file tree
Hide file tree
Showing 35 changed files with 331 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/catalog.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI/CD pipeline for product catalog service
name: catalog-service

on:
push:
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/eshop.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: eshop

on:
push:
branches:
- main
- develop
- feature/**
pull_request:
branches:
- main
- develop
- feature/**

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: oracle
java-version: 21
- name: Setup Task
uses: arduino/setup-task@v2
with:
version: 3.x
repo-token: ${{ secrets.GH_TOKEN }}
- name: Test all services
run: task test
31 changes: 31 additions & 0 deletions .github/workflows/gateway.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: api-gateway

on:
push:
branches:
- main
- develop
- feature/**
pull_request:
branches:
- main
- develop
- feature/**

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: oracle
java-version: 21
- name: Setup Task
uses: arduino/setup-task@v2
with:
version: 3.x
repo-token: ${{ secrets.GH_TOKEN }}
- name: Test api gateway
run: task gateway:test
48 changes: 8 additions & 40 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,40 +1,8 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Gradle ###
.gradle/
.idea/
**/.gradle/
**/gradle/
**/build/
**/gradlew*

!/gradle/
!/gradlew*
Binary file removed .gradle/8.5/checksums/checksums.lock
Binary file not shown.
Binary file not shown.
Empty file.
Binary file removed .gradle/8.5/executionHistory/executionHistory.bin
Binary file not shown.
Binary file removed .gradle/8.5/executionHistory/executionHistory.lock
Binary file not shown.
Binary file removed .gradle/8.5/fileChanges/last-build.bin
Binary file not shown.
Binary file removed .gradle/8.5/fileHashes/fileHashes.bin
Binary file not shown.
Binary file removed .gradle/8.5/fileHashes/fileHashes.lock
Binary file not shown.
Empty file removed .gradle/8.5/gc.properties
Empty file.
Binary file removed .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
2 changes: 0 additions & 2 deletions .gradle/buildOutputCleanup/cache.properties

This file was deleted.

Binary file removed .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file removed .gradle/file-system.probe
Binary file not shown.
Empty file removed .gradle/vcs-1/gc.properties
Empty file.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

Event driven microservice-based c2c ecommerce platform

[![Catalog Pipeline](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml)
[![](https://github.com/dksifoua/eshop/actions/workflows/eshop.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/eshop.yaml)

[![](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml)
[![](https://github.com/dksifoua/eshop/actions/workflows/gateway.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/gateway.yaml)
31 changes: 19 additions & 12 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
version: 3

includes:
catalog:
taskfile: ./catalog-service/Taskfile.yaml
gateway:
taskfile: ./api-gateway/Taskfile.yaml

tasks:
catalog:clean:
desc: Clean product catalog service build
cmd: ./gradlew catalog:clean
clean:
desc: Clean all projects
cmd: ./gradlew clean --parallel
silent: true

catalog:run:
desc: Run product catalog service
cmd: ./gradlew catalog:bootRun
run:
desc: Run all projects
cmd: ./gradlew bootRun --parallel
silent: true
test:
desc: Test all projects
cmd: ./gradlew test --parallel
silent: true

catalog:test:
desc: Test product catalog service
cmds:
- task: catalog:clean
- ./gradlew catalog:test
gradle:stop:
desc: Stop all gradle daemons
cmd: ./gradlew --stop
silent: true
21 changes: 21 additions & 0 deletions api-gateway/HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Getting Started

### Reference Documentation
For further reference, please consider the following sections:

* [Official Gradle documentation](https://docs.gradle.org)
* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/3.3.3/gradle-plugin)
* [Create an OCI image](https://docs.spring.io/spring-boot/3.3.3/gradle-plugin/packaging-oci-image.html)
* [Reactive Gateway](https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html/)
* [Spring Boot DevTools](https://docs.spring.io/spring-boot/docs/3.3.3/reference/htmlsingle/index.html#using.devtools)

### Guides
The following guides illustrate how to use some features concretely:

* [Using Spring Cloud Gateway](https://github.com/spring-cloud-samples/spring-cloud-gateway-sample)

### Additional Links
These additional references should also help you:

* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle)

19 changes: 19 additions & 0 deletions api-gateway/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 3

tasks:
clean:
desc: Clean api gateway build
cmd: ./gradlew :api-gateway:clean
silent: true

run:
desc: Run api gateway
cmd: ./gradlew :api-gateway:bootRun
silent: true

test:
desc: Test api gateway
cmds:
- task: clean
- ./gradlew :api-gateway:test
silent: true
44 changes: 44 additions & 0 deletions api-gateway/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.3'
id 'io.spring.dependency-management' version '1.1.6'
}

group = 'io.dksifoua.eshop'
version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}

repositories {
mavenCentral()
}

ext {
set('springCloudVersion', "2023.0.3")
}

dependencies {
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
implementation 'io.netty:netty-resolver-dns-native-macos:4.1.113.Final:osx-aarch_64'
}

implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}

tasks.named('test') {
useJUnitPlatform()
}
1 change: 1 addition & 0 deletions api-gateway/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'gateway'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.dksifoua.eshop.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ApiGatewayApplication {

public static void main(String[] args) {
SpringApplication.run(ApiGatewayApplication.class, args);
}

}
23 changes: 23 additions & 0 deletions api-gateway/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
server:
port: 8080

spring:
application:
name: api-gateway
devtools:
livereload:
port: 35730

cloud:
gateway:
routes:
- id: catalog-service
uri: http://localhost:8081
predicates:
- Path=/api/v1/catalog/**
logging:
level:
root: info
org.springframework.cloud.gateway: trace
org.springframework.web: debug
org.springframework.web.reactive: debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.dksifoua.eshop.gateway;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class ApiGatewayApplicationTests {

@Test
void contextLoads() {
}

}
45 changes: 45 additions & 0 deletions catalog-service/HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Getting Started

### Reference Documentation
For further reference, please consider the following sections:

* [Official Gradle documentation](https://docs.gradle.org)
* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/3.3.3/gradle-plugin)
* [Create an OCI image](https://docs.spring.io/spring-boot/3.3.3/gradle-plugin/packaging-oci-image.html)
* [Spring Boot Testcontainers support](https://docs.spring.io/spring-boot/3.3.3/reference/testing/testcontainers.html#testing.testcontainers)
* [Testcontainers MongoDB Module Reference Guide](https://java.testcontainers.org/modules/databases/mongodb/)
* [Spring Data MongoDB](https://docs.spring.io/spring-boot/docs/3.3.3/reference/htmlsingle/index.html#data.nosql.mongodb)
* [Spring Boot DevTools](https://docs.spring.io/spring-boot/docs/3.3.3/reference/htmlsingle/index.html#using.devtools)
* [Docker Compose Support](https://docs.spring.io/spring-boot/docs/3.3.3/reference/htmlsingle/index.html#features.docker-compose)
* [Testcontainers](https://java.testcontainers.org/)
* [Spring Reactive Web](https://docs.spring.io/spring-boot/docs/3.3.3/reference/htmlsingle/index.html#web.reactive)

### Guides
The following guides illustrate how to use some features concretely:

* [Accessing Data with MongoDB](https://spring.io/guides/gs/accessing-data-mongodb/)
* [Building a Reactive RESTful Web Service](https://spring.io/guides/gs/reactive-rest-service/)

### Additional Links
These additional references should also help you:

* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle)

### Docker Compose support
This project contains a Docker Compose file named `compose.yaml`.
In this file, the following services have been defined:

* mongodb: [`mongo:latest`](https://hub.docker.com/_/mongo)

Please review the tags of the used images and set them to the same as you're running in production.

### Testcontainers support

This project uses [Testcontainers at development time](https://docs.spring.io/spring-boot/3.3.3/reference/features/dev-services.html#features.dev-services.testcontainers).

Testcontainers has been configured to use the following Docker images:

* [`mongo:latest`](https://hub.docker.com/_/mongo)

Please review the tags of the used images and set them to the same as you're running in production.

19 changes: 19 additions & 0 deletions catalog-service/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 3

tasks:
clean:
desc: Clean product catalog service build
cmd: ./gradlew :catalog-service:clean
silent: true

run:
desc: Run product catalog service
cmd: ./gradlew :catalog-service:bootRun
silent: true

test:
desc: Test product catalog service
cmds:
- task: clean
- ./gradlew :catalog-service:test
silent: true
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
@SpringBootApplication
public class CatalogServiceApplication {

public static void main(String[] args) {
SpringApplication.run(CatalogServiceApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(CatalogServiceApplication.class, args);
}

}
Loading

0 comments on commit c0b44d4

Please sign in to comment.