Skip to content

Commit

Permalink
Merge pull request #9 from dksifoua/feature/5-setup-config-server
Browse files Browse the repository at this point in the history
Setup Config Server
  • Loading branch information
dksifoua authored Oct 1, 2024
2 parents f5bef19 + 9b08c19 commit 54b6e10
Show file tree
Hide file tree
Showing 18 changed files with 251 additions and 49 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: config-server

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 config server
run: task config:test
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Event driven microservice-based c2c ecommerce platform

[![](https://github.com/dksifoua/eshop/actions/workflows/gateway.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/gateway.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/config.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/config.yaml)
[![](https://github.com/dksifoua/eshop/actions/workflows/eureka.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/eureka.yaml)
2 changes: 2 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ version: 3
includes:
catalog:
taskfile: ./catalog-service/Taskfile.yaml
config:
taskfile: ./config-server/Taskfile.yaml
eureka:
taskfile: ./eureka-server/Taskfile.yaml
gateway:
Expand Down
1 change: 1 addition & 0 deletions api-gateway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {

implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
Expand Down
26 changes: 2 additions & 24 deletions api-gateway/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
server:
port: 8080

eureka:
client:
service-url:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}

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
config:
import: optional:configserver:http://dksifoua:dksifoua@localhost:8888
1 change: 1 addition & 0 deletions catalog-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
developmentOnly 'org.springframework.boot:spring-boot-docker-compose'
Expand Down
21 changes: 2 additions & 19 deletions catalog-service/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
app:
base-path: /api/v1/catalog

eureka:
client:
service-url:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}

server:
port: 8081

spring:
application:
name: catalog-service
devtools:
livereload:
port: 35729

logging:
level:
root: info
org.springframework.web: debug
org.springframework.web.reactive: debug
config:
import: optional:configserver:http://dksifoua:dksifoua@localhost:8888
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.ActiveProfiles;

@Import(TestcontainersConfiguration.class)
@SpringBootTest
@TestPropertySource(properties = {
"eureka.client.enabled=false",
"eureka.client.register-with-eureka=false",
"eureka.client.fetch-registry=false"
})
@ActiveProfiles(profiles = "test")
class CatalogServiceApplicationTests {

@Test
Expand Down
25 changes: 25 additions & 0 deletions catalog-service/src/test/resources/application-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
app:
base-path: /api/v1/catalog

eureka:
client:
enabled: false
register-with-eureka: false
fetch-registry: false

server:
port: 8081

spring:
application:
name: catalog-service

devtools:
livereload:
port: 35729

logging:
level:
root: info
org.springframework.web: debug
org.springframework.web.reactive: debug
37 changes: 37 additions & 0 deletions config-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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/
19 changes: 19 additions & 0 deletions config-server/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 3

tasks:
clean:
desc: Clean config server build
cmd: ./gradlew :config-server:clean
silent: true

run:
desc: Run config server
cmd: ./gradlew :config-server:bootRun
silent: true

test:
desc: Test config server
cmds:
- task: clean
- ./gradlew :config-server:test
silent: true
41 changes: 41 additions & 0 deletions config-server/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.4'
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 {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.cloud:spring-cloud-config-server'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-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 config-server/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'config'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.dksifoua.eshop.config;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {

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

}
28 changes: 28 additions & 0 deletions config-server/src/main/resources/application-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
eureka:
client:
enabled: false
register-with-eureka: false
fetch-registry: false

logging:
level:
root: info
org.springframework.cloud.config: debug

server:
port: 8888

spring:
application:
name: config-server

cloud:
config:
server:
git:
uri: https://github.com/dksifoua/eshop-config

security:
user:
name: dksifoua
password: dksifoua
27 changes: 27 additions & 0 deletions config-server/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
eureka:
client:
service-url:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}

logging:
level:
root: info
org.springframework.cloud.config: debug

server:
port: 8888

spring:
application:
name: config-server

cloud:
config:
server:
git:
uri: https://github.com/dksifoua/eshop-config

security:
user:
name: dksifoua
password: dksifoua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.dksifoua.eshop.config;

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

@SpringBootTest
@ActiveProfiles(profiles = "test")
class ConfigServerApplicationTests {

@Test
void contextLoads() {
}

}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ rootProject.name = 'eshop'

include('api-gateway')
include('catalog-service')
include('config-server')
include('eureka-server')

0 comments on commit 54b6e10

Please sign in to comment.