Skip to content

Commit 54b6e10

Browse files
authored
Merge pull request #9 from dksifoua/feature/5-setup-config-server
Setup Config Server
2 parents f5bef19 + 9b08c19 commit 54b6e10

File tree

18 files changed

+251
-49
lines changed

18 files changed

+251
-49
lines changed

.github/workflows/config.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: config-server
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop
8+
- feature/**
9+
pull_request:
10+
branches:
11+
- main
12+
- develop
13+
- feature/**
14+
15+
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Setup Java
21+
uses: actions/setup-java@v4
22+
with:
23+
distribution: oracle
24+
java-version: 21
25+
- name: Setup Task
26+
uses: arduino/setup-task@v2
27+
with:
28+
version: 3.x
29+
repo-token: ${{ secrets.GH_TOKEN }}
30+
- name: Test config server
31+
run: task config:test

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ Event driven microservice-based c2c ecommerce platform
66

77
[![](https://github.com/dksifoua/eshop/actions/workflows/gateway.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/gateway.yaml)
88
[![](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml)
9+
[![](https://github.com/dksifoua/eshop/actions/workflows/config.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/config.yaml)
910
[![](https://github.com/dksifoua/eshop/actions/workflows/eureka.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/eureka.yaml)

Taskfile.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ version: 3
33
includes:
44
catalog:
55
taskfile: ./catalog-service/Taskfile.yaml
6+
config:
7+
taskfile: ./config-server/Taskfile.yaml
68
eureka:
79
taskfile: ./eureka-server/Taskfile.yaml
810
gateway:

api-gateway/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies {
2828

2929
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
3030
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
31+
implementation 'org.springframework.cloud:spring-cloud-starter-config'
3132
developmentOnly 'org.springframework.boot:spring-boot-devtools'
3233
testImplementation 'org.springframework.boot:spring-boot-starter-test'
3334
testImplementation 'io.projectreactor:reactor-test'
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
1-
server:
2-
port: 8080
3-
4-
eureka:
5-
client:
6-
service-url:
7-
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
8-
91
spring:
102
application:
113
name: api-gateway
12-
devtools:
13-
livereload:
14-
port: 35730
154

16-
cloud:
17-
gateway:
18-
routes:
19-
- id: catalog-service
20-
uri: http://localhost:8081
21-
predicates:
22-
- Path=/api/v1/catalog/**
23-
logging:
24-
level:
25-
root: info
26-
org.springframework.cloud.gateway: trace
27-
org.springframework.web: debug
28-
org.springframework.web.reactive: debug
5+
config:
6+
import: optional:configserver:http://dksifoua:dksifoua@localhost:8888

catalog-service/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies {
3131
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
3232
implementation 'org.springframework.boot:spring-boot-starter-webflux'
3333
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
34+
implementation 'org.springframework.cloud:spring-cloud-starter-config'
3435
compileOnly 'org.projectlombok:lombok'
3536
developmentOnly 'org.springframework.boot:spring-boot-devtools'
3637
developmentOnly 'org.springframework.boot:spring-boot-docker-compose'
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1-
app:
2-
base-path: /api/v1/catalog
3-
4-
eureka:
5-
client:
6-
service-url:
7-
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
8-
9-
server:
10-
port: 8081
11-
121
spring:
132
application:
143
name: catalog-service
15-
devtools:
16-
livereload:
17-
port: 35729
184

19-
logging:
20-
level:
21-
root: info
22-
org.springframework.web: debug
23-
org.springframework.web.reactive: debug
5+
config:
6+
import: optional:configserver:http://dksifoua:dksifoua@localhost:8888

catalog-service/src/test/java/io/dksifoua/eshop/catalog/CatalogServiceApplicationTests.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33
import org.junit.jupiter.api.Test;
44
import org.springframework.boot.test.context.SpringBootTest;
55
import org.springframework.context.annotation.Import;
6-
import org.springframework.test.context.TestPropertySource;
6+
import org.springframework.test.context.ActiveProfiles;
77

88
@Import(TestcontainersConfiguration.class)
99
@SpringBootTest
10-
@TestPropertySource(properties = {
11-
"eureka.client.enabled=false",
12-
"eureka.client.register-with-eureka=false",
13-
"eureka.client.fetch-registry=false"
14-
})
10+
@ActiveProfiles(profiles = "test")
1511
class CatalogServiceApplicationTests {
1612

1713
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
app:
2+
base-path: /api/v1/catalog
3+
4+
eureka:
5+
client:
6+
enabled: false
7+
register-with-eureka: false
8+
fetch-registry: false
9+
10+
server:
11+
port: 8081
12+
13+
spring:
14+
application:
15+
name: catalog-service
16+
17+
devtools:
18+
livereload:
19+
port: 35729
20+
21+
logging:
22+
level:
23+
root: info
24+
org.springframework.web: debug
25+
org.springframework.web.reactive: debug

config-server/.gitignore

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
HELP.md
2+
.gradle
3+
build/
4+
!gradle/wrapper/gradle-wrapper.jar
5+
!**/src/main/**/build/
6+
!**/src/test/**/build/
7+
8+
### STS ###
9+
.apt_generated
10+
.classpath
11+
.factorypath
12+
.project
13+
.settings
14+
.springBeans
15+
.sts4-cache
16+
bin/
17+
!**/src/main/**/bin/
18+
!**/src/test/**/bin/
19+
20+
### IntelliJ IDEA ###
21+
.idea
22+
*.iws
23+
*.iml
24+
*.ipr
25+
out/
26+
!**/src/main/**/out/
27+
!**/src/test/**/out/
28+
29+
### NetBeans ###
30+
/nbproject/private/
31+
/nbbuild/
32+
/dist/
33+
/nbdist/
34+
/.nb-gradle/
35+
36+
### VS Code ###
37+
.vscode/

config-server/Taskfile.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: 3
2+
3+
tasks:
4+
clean:
5+
desc: Clean config server build
6+
cmd: ./gradlew :config-server:clean
7+
silent: true
8+
9+
run:
10+
desc: Run config server
11+
cmd: ./gradlew :config-server:bootRun
12+
silent: true
13+
14+
test:
15+
desc: Test config server
16+
cmds:
17+
- task: clean
18+
- ./gradlew :config-server:test
19+
silent: true

config-server/build.gradle

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
plugins {
2+
id 'java'
3+
id 'org.springframework.boot' version '3.3.4'
4+
id 'io.spring.dependency-management' version '1.1.6'
5+
}
6+
7+
group = 'io.dksifoua.eshop'
8+
version = '0.0.1-SNAPSHOT'
9+
10+
java {
11+
toolchain {
12+
languageVersion = JavaLanguageVersion.of(21)
13+
}
14+
}
15+
16+
repositories {
17+
mavenCentral()
18+
}
19+
20+
ext {
21+
set('springCloudVersion', "2023.0.3")
22+
}
23+
24+
dependencies {
25+
implementation 'org.springframework.boot:spring-boot-starter-security'
26+
implementation 'org.springframework.cloud:spring-cloud-config-server'
27+
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
28+
testImplementation 'org.springframework.boot:spring-boot-starter-test'
29+
testImplementation 'org.springframework.security:spring-security-test'
30+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
31+
}
32+
33+
dependencyManagement {
34+
imports {
35+
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
36+
}
37+
}
38+
39+
tasks.named('test') {
40+
useJUnitPlatform()
41+
}

config-server/settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'config'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.dksifoua.eshop.config;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.config.server.EnableConfigServer;
6+
7+
@SpringBootApplication
8+
@EnableConfigServer
9+
public class ConfigServerApplication {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(ConfigServerApplication.class, args);
13+
}
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
eureka:
2+
client:
3+
enabled: false
4+
register-with-eureka: false
5+
fetch-registry: false
6+
7+
logging:
8+
level:
9+
root: info
10+
org.springframework.cloud.config: debug
11+
12+
server:
13+
port: 8888
14+
15+
spring:
16+
application:
17+
name: config-server
18+
19+
cloud:
20+
config:
21+
server:
22+
git:
23+
uri: https://github.com/dksifoua/eshop-config
24+
25+
security:
26+
user:
27+
name: dksifoua
28+
password: dksifoua
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
eureka:
2+
client:
3+
service-url:
4+
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
5+
6+
logging:
7+
level:
8+
root: info
9+
org.springframework.cloud.config: debug
10+
11+
server:
12+
port: 8888
13+
14+
spring:
15+
application:
16+
name: config-server
17+
18+
cloud:
19+
config:
20+
server:
21+
git:
22+
uri: https://github.com/dksifoua/eshop-config
23+
24+
security:
25+
user:
26+
name: dksifoua
27+
password: dksifoua
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.dksifoua.eshop.config;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
import org.springframework.test.context.ActiveProfiles;
6+
7+
@SpringBootTest
8+
@ActiveProfiles(profiles = "test")
9+
class ConfigServerApplicationTests {
10+
11+
@Test
12+
void contextLoads() {
13+
}
14+
15+
}

settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ rootProject.name = 'eshop'
22

33
include('api-gateway')
44
include('catalog-service')
5+
include('config-server')
56
include('eureka-server')

0 commit comments

Comments
 (0)