From 1b70d8fc39f1127f8a4c0dcd1d2f1dd5077a7c0c Mon Sep 17 00:00:00 2001 From: dksifoua Date: Wed, 25 Sep 2024 21:05:52 -0400 Subject: [PATCH] Setup Config Server --- api-gateway/build.gradle | 1 + .../src/main/resources/application.yaml | 26 +----------- catalog-service/build.gradle | 1 + .../src/main/resources/application.yaml | 21 +--------- config-server/.gitignore | 37 +++++++++++++++++ config-server/build.gradle | 41 +++++++++++++++++++ config-server/settings.gradle | 1 + .../eshop/config/ConfigServerApplication.java | 15 +++++++ .../src/main/resources/application.yaml | 27 ++++++++++++ .../config/ConfigServerApplicationTests.java | 13 ++++++ settings.gradle | 1 + 11 files changed, 141 insertions(+), 43 deletions(-) create mode 100644 config-server/.gitignore create mode 100644 config-server/build.gradle create mode 100644 config-server/settings.gradle create mode 100644 config-server/src/main/java/io/dksifoua/eshop/config/ConfigServerApplication.java create mode 100644 config-server/src/main/resources/application.yaml create mode 100644 config-server/src/test/java/io/dksifoua/eshop/config/ConfigServerApplicationTests.java diff --git a/api-gateway/build.gradle b/api-gateway/build.gradle index e26d159..62bed87 100644 --- a/api-gateway/build.gradle +++ b/api-gateway/build.gradle @@ -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' diff --git a/api-gateway/src/main/resources/application.yaml b/api-gateway/src/main/resources/application.yaml index 056c708..0bfe967 100644 --- a/api-gateway/src/main/resources/application.yaml +++ b/api-gateway/src/main/resources/application.yaml @@ -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 \ No newline at end of file + config: + import: optional:configserver:http://dksifoua:dksifoua@localhost:8888 \ No newline at end of file diff --git a/catalog-service/build.gradle b/catalog-service/build.gradle index 7ffee82..0022f37 100644 --- a/catalog-service/build.gradle +++ b/catalog-service/build.gradle @@ -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' diff --git a/catalog-service/src/main/resources/application.yaml b/catalog-service/src/main/resources/application.yaml index cb29fb4..e7fb039 100644 --- a/catalog-service/src/main/resources/application.yaml +++ b/catalog-service/src/main/resources/application.yaml @@ -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 diff --git a/config-server/.gitignore b/config-server/.gitignore new file mode 100644 index 0000000..c2065bc --- /dev/null +++ b/config-server/.gitignore @@ -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/ diff --git a/config-server/build.gradle b/config-server/build.gradle new file mode 100644 index 0000000..e2f4f2d --- /dev/null +++ b/config-server/build.gradle @@ -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() +} diff --git a/config-server/settings.gradle b/config-server/settings.gradle new file mode 100644 index 0000000..6bbfae7 --- /dev/null +++ b/config-server/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'config' diff --git a/config-server/src/main/java/io/dksifoua/eshop/config/ConfigServerApplication.java b/config-server/src/main/java/io/dksifoua/eshop/config/ConfigServerApplication.java new file mode 100644 index 0000000..d891ec4 --- /dev/null +++ b/config-server/src/main/java/io/dksifoua/eshop/config/ConfigServerApplication.java @@ -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); + } + +} diff --git a/config-server/src/main/resources/application.yaml b/config-server/src/main/resources/application.yaml new file mode 100644 index 0000000..4204337 --- /dev/null +++ b/config-server/src/main/resources/application.yaml @@ -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 diff --git a/config-server/src/test/java/io/dksifoua/eshop/config/ConfigServerApplicationTests.java b/config-server/src/test/java/io/dksifoua/eshop/config/ConfigServerApplicationTests.java new file mode 100644 index 0000000..0222386 --- /dev/null +++ b/config-server/src/test/java/io/dksifoua/eshop/config/ConfigServerApplicationTests.java @@ -0,0 +1,13 @@ +package io.dksifoua.eshop.config; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ConfigServerApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/settings.gradle b/settings.gradle index 834be30..419de04 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,4 +2,5 @@ rootProject.name = 'eshop' include('api-gateway') include('catalog-service') +include('config-server') include('eureka-server') \ No newline at end of file