Init
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
FROM bellsoft/liberica-openjre-alpine:21.0.5
|
||||
|
||||
ENV JAVA_OPTS="-jar"
|
||||
|
||||
ADD ./build/libs/*.jar /app.jar
|
||||
|
||||
EXPOSE 8888
|
||||
ENTRYPOINT ["java", "-jar", "/app.jar"]
|
||||
@@ -0,0 +1,29 @@
|
||||
# spring-cloud-config-server
|
||||
|
||||
Spring Cloud Config Server для PCP.
|
||||
|
||||
Сервер читает конфигурацию из GitLab-репозитория через backend `spring.cloud.config.server.git`.
|
||||
|
||||
Обязательные переменные окружения:
|
||||
|
||||
- `CONFIG_GIT_URI`: HTTPS URL GitLab-репозитория с конфигами, например `https://gitlab.example.com/group/pcp-config.git`
|
||||
- `CONFIG_GIT_TOKEN`: access token для чтения приватного репозитория
|
||||
|
||||
Рекомендуемые переменные окружения:
|
||||
|
||||
- `CONFIG_GIT_USERNAME`: логин для GitLab HTTPS auth. Для token-based auth обычно подходит `oauth2`
|
||||
- `CONFIG_GIT_DEFAULT_LABEL`: ветка с конфигами, по умолчанию `main`
|
||||
- `CONFIG_GIT_SEARCH_PATHS`: подкаталог внутри репозитория, по умолчанию `config-repo`
|
||||
- `SERVER_PORT`: порт сервера, по умолчанию `8888`
|
||||
|
||||
Для локального запуска в корне репозитория подготовлен `.env` и шаблон `.env.example`.
|
||||
|
||||
Запуск в Docker Compose из корня проекта:
|
||||
|
||||
`docker compose up --build spring-cloud-config-server`
|
||||
|
||||
Пример запроса:
|
||||
|
||||
`GET /pcp-stations-service/default`
|
||||
|
||||
Если конфиги лежат в корне репозитория, задайте `CONFIG_GIT_SEARCH_PATHS=`.
|
||||
@@ -0,0 +1,73 @@
|
||||
group = "space.nstart.pcp"
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
kotlin("plugin.spring")
|
||||
id("org.springframework.boot")
|
||||
id("io.spring.dependency-management")
|
||||
id("org.sonarqube")
|
||||
jacoco
|
||||
}
|
||||
|
||||
version = "1.0.0"
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
freeCompilerArgs.addAll("-Xjsr305=strict")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("${property("dep.spring.actuator")}")
|
||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||
implementation("org.springframework.boot:spring-boot-starter-validation")
|
||||
implementation("org.springframework.cloud:spring-cloud-config-server")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("versions.spring.cloud")}")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<Jar> {
|
||||
manifest {
|
||||
attributes["Built-By"] = "nstart"
|
||||
attributes["Implementation-Version"] = archiveVersion
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
useJUnitPlatform()
|
||||
finalizedBy(tasks.jacocoTestReport)
|
||||
systemProperty("spring.profiles.active", "test")
|
||||
}
|
||||
|
||||
tasks.check {
|
||||
dependsOn(tasks.jacocoTestCoverageVerification)
|
||||
}
|
||||
|
||||
tasks.jacocoTestReport {
|
||||
dependsOn(tasks.test)
|
||||
reports {
|
||||
xml.required = true
|
||||
html.required = true
|
||||
csv.required = false
|
||||
}
|
||||
}
|
||||
|
||||
sonar {
|
||||
properties {
|
||||
property("sonar.projectKey", "pcp")
|
||||
property("sonar.login", "sqp_tokenExample")
|
||||
property("sonar.qualitygate.wait", "${property("sonar.qualitygate.wait")}")
|
||||
property("sonar.host.url", "${property("sonar.host.url")}")
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package space.nstart.pcp.spring_cloud_config_server
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.boot.runApplication
|
||||
import org.springframework.cloud.config.server.EnableConfigServer
|
||||
|
||||
@EnableConfigServer
|
||||
@SpringBootApplication
|
||||
class SpringCloudConfigServerApplication
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
runApplication<SpringCloudConfigServerApplication>(*args)
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
spring:
|
||||
application:
|
||||
name: spring-cloud-config-server
|
||||
profiles:
|
||||
group:
|
||||
local: native
|
||||
cloud:
|
||||
config:
|
||||
server:
|
||||
git:
|
||||
uri: ${CONFIG_GIT_URI:}
|
||||
default-label: ${CONFIG_GIT_DEFAULT_LABEL:main}
|
||||
search-paths: ${CONFIG_GIT_SEARCH_PATHS:config-repo}
|
||||
clone-on-start: ${CONFIG_GIT_CLONE_ON_START:false}
|
||||
force-pull: ${CONFIG_GIT_FORCE_PULL:true}
|
||||
timeout: ${CONFIG_GIT_TIMEOUT:10}
|
||||
username: ${CONFIG_GIT_USERNAME:oauth2}
|
||||
password: ${CONFIG_GIT_TOKEN:}
|
||||
skipSslValidation: ${CONFIG_GIT_SKIP_SSL_VALIDATION:false}
|
||||
boot:
|
||||
admin:
|
||||
client:
|
||||
enabled: false
|
||||
|
||||
server:
|
||||
port: ${SERVER_PORT:8888}
|
||||
|
||||
management:
|
||||
health:
|
||||
client-config-server:
|
||||
enabled: false
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info,env,refresh
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
|
||||
logging:
|
||||
level:
|
||||
org.springframework.cloud.config.server: INFO
|
||||
|
||||
---
|
||||
spring:
|
||||
config:
|
||||
activate:
|
||||
on-profile: local
|
||||
cloud:
|
||||
config:
|
||||
server:
|
||||
native:
|
||||
search-locations: ${CONFIG_NATIVE_SEARCH_LOCATIONS:optional:file:./config-repo,optional:file:../config-repo,optional:file:../../config-repo}
|
||||
|
||||
---
|
||||
spring:
|
||||
config:
|
||||
activate:
|
||||
on-profile: test
|
||||
cloud:
|
||||
config:
|
||||
server:
|
||||
git:
|
||||
uri: https://gitlab.example.invalid/group/config-repo.git
|
||||
clone-on-start: false
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package space.nstart.pcp.spring_cloud_config_server
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
|
||||
@SpringBootTest
|
||||
class SpringCloudConfigServerApplicationTests {
|
||||
|
||||
@Test
|
||||
fun contextLoads() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user