Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8381c1ba7d | ||
|
|
4308130cd1 | ||
|
|
721cdac95d | ||
|
|
395fa52962 | ||
|
|
45e5c473ff | ||
|
|
1c3648f0f4 | ||
|
|
5b707728b8 | ||
|
|
c19c211839 | ||
|
|
aace535914 | ||
|
|
59982ef762 | ||
|
|
56c6fef178 | ||
|
|
46b1b32708 | ||
|
|
519101023c | ||
|
|
82b4f51390 | ||
|
|
3256939ac7 | ||
|
|
02e4c5318d | ||
|
|
f06abd2838 | ||
|
|
f0297f2d2c | ||
|
|
ec23bd4d32 | ||
|
|
bab1892673 | ||
|
|
247fe83caa | ||
|
|
5fe6165373 | ||
|
|
64a8f17e6e | ||
|
|
5eff527c48 | ||
|
|
642713e14c | ||
|
|
ff8b205124 | ||
|
|
8c5f925e36 | ||
|
|
fe5cd41749 | ||
|
|
3a25e33f3f | ||
|
|
ec625fb7b5 | ||
|
|
c8e4474175 | ||
|
|
499c85ae49 | ||
|
|
e88d98efc1 | ||
|
|
8d545aa7fb | ||
|
|
a04094bc60 | ||
|
|
7d68612e57 | ||
|
|
64295db0e7 | ||
|
|
6dcd302ab7 |
+64
-3
@@ -88,10 +88,71 @@ volumes:
|
|||||||
path: /var/lib/drone/cache/.gradle
|
path: /var/lib/drone/cache/.gradle
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
event:
|
event:
|
||||||
include:
|
include:
|
||||||
- push
|
- tag
|
||||||
- custom
|
- custom
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: deploy image
|
||||||
|
type: docker
|
||||||
|
|
||||||
|
platform:
|
||||||
|
os: linux
|
||||||
|
arch: arm64
|
||||||
|
|
||||||
|
clone:
|
||||||
|
disable: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: clone
|
||||||
|
image: alpine/git
|
||||||
|
environment:
|
||||||
|
SSH_KEY:
|
||||||
|
from_secret: ssh_key
|
||||||
|
commands:
|
||||||
|
- mkdir $HOME/.ssh
|
||||||
|
- echo "$SSH_KEY" > $HOME/.ssh/id_ed25519
|
||||||
|
- chmod 600 $HOME/.ssh/id_ed25519
|
||||||
|
- touch $HOME/.ssh/known_hosts
|
||||||
|
- chmod 600 $HOME/.ssh/known_hosts
|
||||||
|
- ssh-keyscan -H git.2martens.de > $HOME/.ssh/known_hosts 2>/dev/null
|
||||||
|
- git clone ssh://giteajim@git.2martens.de:22/2martens/cloud-configuration.git .
|
||||||
|
- git checkout main
|
||||||
|
- name: modify deployed image
|
||||||
|
image: alpine
|
||||||
|
commands:
|
||||||
|
- sed -i -r "s/(wahlrecht_image_version:).*/\1\ ${DRONE_SEMVER}/" ansible/inventories/host_vars/api-server/public.yaml
|
||||||
|
- name: save modified variable file
|
||||||
|
image: alpine/git
|
||||||
|
environment:
|
||||||
|
SSH_KEY:
|
||||||
|
from_secret: ssh_key
|
||||||
|
commands:
|
||||||
|
- mkdir $HOME/.ssh
|
||||||
|
- echo "$SSH_KEY" > $HOME/.ssh/id_ed25519
|
||||||
|
- chmod 600 $HOME/.ssh/id_ed25519
|
||||||
|
- touch $HOME/.ssh/known_hosts
|
||||||
|
- chmod 600 $HOME/.ssh/known_hosts
|
||||||
|
- ssh-keyscan -H git.2martens.de > $HOME/.ssh/known_hosts 2>/dev/null
|
||||||
|
- git add ansible/inventories/host_vars/api-server/public.yaml
|
||||||
|
- git commit -m "[Drone] Changed wahlrecht_image_version to ${DRONE_SEMVER}"
|
||||||
|
- git push origin main
|
||||||
|
- name: deploy image
|
||||||
|
image: plugins/ansible:latest
|
||||||
|
settings:
|
||||||
|
playbook: ansible/deploy_spring.yaml
|
||||||
|
inventory: ansible/inventories/production
|
||||||
|
private_key:
|
||||||
|
from_secret: ssh_key
|
||||||
|
vault_password:
|
||||||
|
from_secret: vault_password
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
target:
|
||||||
|
- production
|
||||||
|
event:
|
||||||
|
include:
|
||||||
|
- promote
|
||||||
|
- rollback
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ tasks.named("buildAll") {
|
|||||||
|
|
||||||
val formatter: DateTimeFormatter = ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
|
val formatter: DateTimeFormatter = ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
|
||||||
|
|
||||||
tasks.bootJar {
|
tasks.jar {
|
||||||
manifest {
|
manifest {
|
||||||
attributes["Implementation-Title"] = rootProject.name
|
attributes["Implementation-Title"] = rootProject.name
|
||||||
attributes["Implementation-Version"] = archiveVersion.get()
|
attributes["Implementation-Version"] = archiveVersion.get()
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ spring-boot-oauth2-resource-server = { module = "org.springframework.boot:spring
|
|||||||
spring-boot-config = { module = "org.springframework.boot:spring-boot-configuration-processor", version.ref = "spring-boot" }
|
spring-boot-config = { module = "org.springframework.boot:spring-boot-configuration-processor", version.ref = "spring-boot" }
|
||||||
spring-cloud = { module = "org.springframework.cloud:spring-cloud-dependencies", version.ref = "spring-cloud" }
|
spring-cloud = { module = "org.springframework.cloud:spring-cloud-dependencies", version.ref = "spring-cloud" }
|
||||||
spring-cloud-starter = { module = "org.springframework.cloud:spring-cloud-starter" }
|
spring-cloud-starter = { module = "org.springframework.cloud:spring-cloud-starter" }
|
||||||
|
spring-cloud-starter-bus-kafka = { module = "org.springframework.cloud:spring-cloud-starter-bus-kafka" }
|
||||||
spring-cloud-starter-config = { module = "org.springframework.cloud:spring-cloud-starter-config" }
|
spring-cloud-starter-config = { module = "org.springframework.cloud:spring-cloud-starter-config" }
|
||||||
spring-cloud-config-server = { module = "org.springframework.cloud:spring-cloud-config-server" }
|
spring-cloud-config-server = { module = "org.springframework.cloud:spring-cloud-config-server" }
|
||||||
spring-boot-starter = { module = "org.springframework.boot:spring-boot-starter" }
|
spring-boot-starter = { module = "org.springframework.boot:spring-boot-starter" }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
POST http://localhost:12000/wahlrecht/v1/calculate
|
POST {{backend}}/wahlrecht/v1/calculate
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
GET {{backend}}/wahlrecht/v1/elections
|
||||||
|
Content-Type: application/json
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"dev": {
|
||||||
|
"backend": "http://localhost:12000"
|
||||||
|
},
|
||||||
|
"prod" : {
|
||||||
|
"backend": "https://api.2martens.de"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
server:
|
|
||||||
port: 12000
|
|
||||||
@@ -10,4 +10,5 @@ dependencies {
|
|||||||
annotationProcessor(libs.mapstruct.processor)
|
annotationProcessor(libs.mapstruct.processor)
|
||||||
kapt(libs.mapstruct.processor)
|
kapt(libs.mapstruct.processor)
|
||||||
implementation(libs.spring.cloud.starter.config)
|
implementation(libs.spring.cloud.starter.config)
|
||||||
|
implementation(libs.spring.cloud.starter.bus.kafka)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -16,8 +16,8 @@ open class WebConfiguration(private val headerInterceptorRest: HeaderInterceptor
|
|||||||
override fun addCorsMappings(registry: CorsRegistry) {
|
override fun addCorsMappings(registry: CorsRegistry) {
|
||||||
val registration = registry.addMapping("/**")
|
val registration = registry.addMapping("/**")
|
||||||
registration.allowedMethods(
|
registration.allowedMethods(
|
||||||
HttpMethod.GET.name(), HttpMethod.POST.name(),
|
HttpMethod.GET.name(), HttpMethod.POST.name(),
|
||||||
HttpMethod.PUT.name(), HttpMethod.OPTIONS.name()
|
HttpMethod.PUT.name(), HttpMethod.HEAD.name()
|
||||||
)
|
)
|
||||||
registration.allowCredentials(true)
|
registration.allowCredentials(true)
|
||||||
registration.allowedOrigins(
|
registration.allowedOrigins(
|
||||||
|
|||||||
+4
-2
@@ -32,14 +32,16 @@ class VersionHtmlController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getTitle(): String {
|
private fun getTitle(): String {
|
||||||
val title = VersionHtmlController::class.java.getPackage().implementationTitle
|
val title = VersionHtmlController::class.java.`package`.implementationTitle
|
||||||
|
?: return "application"
|
||||||
return title.ifBlank {
|
return title.ifBlank {
|
||||||
"application"
|
"application"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getVersion(): String {
|
private fun getVersion(): String {
|
||||||
val version = VersionHtmlController::class.java.getPackage().implementationVersion
|
val version = VersionHtmlController::class.java.`package`.implementationVersion
|
||||||
|
?: return "DEVELOPER"
|
||||||
return version.ifBlank {
|
return version.ifBlank {
|
||||||
"DEVELOPER"
|
"DEVELOPER"
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -1,5 +1,6 @@
|
|||||||
package de.twomartens.wahlrecht.controller.v1
|
package de.twomartens.wahlrecht.controller.v1
|
||||||
|
|
||||||
|
import de.twomartens.wahlrecht.property.ServiceProperties
|
||||||
import io.swagger.v3.oas.annotations.Hidden
|
import io.swagger.v3.oas.annotations.Hidden
|
||||||
import org.springframework.web.bind.annotation.GetMapping
|
import org.springframework.web.bind.annotation.GetMapping
|
||||||
import org.springframework.web.bind.annotation.RequestMapping
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
@@ -7,11 +8,12 @@ import org.springframework.web.bind.annotation.RestController
|
|||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value = ["/wahlrecht/v1"])
|
@RequestMapping(value = ["/wahlrecht/v1"])
|
||||||
class HealthCheckController {
|
class HealthCheckController(private val properties: ServiceProperties) {
|
||||||
|
|
||||||
|
|
||||||
@Hidden
|
@Hidden
|
||||||
@GetMapping("/healthCheck")
|
@GetMapping("/healthCheck")
|
||||||
fun healthCheck(message: String): String {
|
fun healthCheck(message: String): String {
|
||||||
return message
|
return properties.greeting.format(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+8
-5
@@ -1,6 +1,7 @@
|
|||||||
package de.twomartens.wahlrecht.monitoring.actuator
|
package de.twomartens.wahlrecht.monitoring.actuator
|
||||||
|
|
||||||
import de.twomartens.wahlrecht.interceptor.HeaderInterceptorRest
|
import de.twomartens.wahlrecht.interceptor.HeaderInterceptorRest
|
||||||
|
import de.twomartens.wahlrecht.property.ServiceProperties
|
||||||
import org.springframework.boot.actuate.health.Health
|
import org.springframework.boot.actuate.health.Health
|
||||||
import org.springframework.boot.actuate.health.HealthIndicator
|
import org.springframework.boot.actuate.health.HealthIndicator
|
||||||
import org.springframework.boot.actuate.health.Status
|
import org.springframework.boot.actuate.health.Status
|
||||||
@@ -28,8 +29,10 @@ import java.time.Clock
|
|||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
class RestHealthIndicator(
|
class RestHealthIndicator(
|
||||||
clock: Clock, interceptor: HeaderInterceptorRest,
|
clock: Clock, interceptor: HeaderInterceptorRest,
|
||||||
serverProperties: ServerProperties, private val restTemplateRestHealthIndicator: RestTemplate
|
serverProperties: ServerProperties,
|
||||||
|
private val restTemplateRestHealthIndicator: RestTemplate,
|
||||||
|
private val serviceProperties: ServiceProperties
|
||||||
) : AbstractHealthIndicator(clock, Preparable { interceptor.markAsHealthCheck() }), HealthIndicator {
|
) : AbstractHealthIndicator(clock, Preparable { interceptor.markAsHealthCheck() }), HealthIndicator {
|
||||||
private val randomizer = SecureRandom()
|
private val randomizer = SecureRandom()
|
||||||
private val urlPrefix: String = (HTTP_PREFIX + HOST + HOST_PORT_SEPARATOR
|
private val urlPrefix: String = (HTTP_PREFIX + HOST + HOST_PORT_SEPARATOR
|
||||||
@@ -43,10 +46,10 @@ class RestHealthIndicator(
|
|||||||
val random = randomizer.nextInt(100000, 999999).toString()
|
val random = randomizer.nextInt(100000, 999999).toString()
|
||||||
val url = "$urlPrefix{random}"
|
val url = "$urlPrefix{random}"
|
||||||
val response = restTemplateRestHealthIndicator.getForEntity(url, String::class.java, random)
|
val response = restTemplateRestHealthIndicator.getForEntity(url, String::class.java, random)
|
||||||
val status = if (response.body == random) Status.UP else Status.DOWN
|
val status = if (response.body == serviceProperties.greeting.format(random)) Status.UP else Status.DOWN
|
||||||
return Health.status(status)
|
return Health.status(status)
|
||||||
.withDetail(DETAIL_ENDPOINT_KEY, url)
|
.withDetail(DETAIL_ENDPOINT_KEY, url)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ package de.twomartens.wahlrecht.property
|
|||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||||
import org.springframework.boot.context.properties.bind.ConstructorBinding
|
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope
|
import org.springframework.cloud.context.config.annotation.RefreshScope
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
|
|
||||||
@RefreshScope
|
@RefreshScope
|
||||||
@ConfigurationProperties(prefix = "de.twomartens.wahlrecht")
|
@ConfigurationProperties(prefix = "de.twomartens.wahlrecht")
|
||||||
@Schema(description = "Properties, to configure this Application")
|
@Schema(description = "Properties, to configure this Application")
|
||||||
data class ServiceProperties @ConstructorBinding constructor(val defaultTimeZone: ZoneId, val greeting: String)
|
class ServiceProperties {
|
||||||
|
lateinit var defaultTimeZone: ZoneId
|
||||||
|
lateinit var greeting: String
|
||||||
|
}
|
||||||
|
|||||||
-41
@@ -1,41 +0,0 @@
|
|||||||
package de.twomartens.wahlrecht.service
|
|
||||||
|
|
||||||
import mu.KotlinLogging
|
|
||||||
import org.apache.logging.log4j.message.StringMapMessage
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier
|
|
||||||
import org.springframework.cloud.context.refresh.ContextRefresher
|
|
||||||
import org.springframework.scheduling.annotation.Scheduled
|
|
||||||
import org.springframework.stereotype.Service
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
/**
|
|
||||||
* automatically reloads application*.yaml. reload can also be triggered manually by doing a post
|
|
||||||
* request on http://localhost:12001/actuator/refresh
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
class PropertyReloadService(@Qualifier("configDataContextRefresher") private val contextRefresher: ContextRefresher) {
|
|
||||||
@Scheduled(
|
|
||||||
fixedDelay = REFRESH_SECONDS.toLong(),
|
|
||||||
initialDelay = REFRESH_SECONDS.toLong(),
|
|
||||||
timeUnit = TimeUnit.SECONDS
|
|
||||||
)
|
|
||||||
fun refresh() {
|
|
||||||
val properties = contextRefresher.refresh()
|
|
||||||
if (properties.isNotEmpty()) {
|
|
||||||
log.info(
|
|
||||||
StringMapMessage()
|
|
||||||
.with(PARAM_MESSAGE, "properties changed")
|
|
||||||
.with(PARAM_PROPERTIES, properties.joinToString("\n"))
|
|
||||||
.asString()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val REFRESH_SECONDS = 60
|
|
||||||
const val PARAM_MESSAGE = "message"
|
|
||||||
const val PARAM_PROPERTIES = "labels.properties"
|
|
||||||
|
|
||||||
private val log = KotlinLogging.logger {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,2 +1,9 @@
|
|||||||
server.port: 12000
|
server.port: 12000
|
||||||
management.server.port: 12001
|
management.server.port: 12001
|
||||||
|
|
||||||
|
|
||||||
|
spring:
|
||||||
|
config:
|
||||||
|
import:
|
||||||
|
- "classpath:config/wahlrecht.yaml"
|
||||||
|
- "optional:configserver:http://localhost:8888/config"
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
spring:
|
||||||
|
config:
|
||||||
|
import:
|
||||||
|
- "configserver:http://configserver:8888/config"
|
||||||
|
kafka:
|
||||||
|
bootstrap-servers:
|
||||||
|
- kafka:9092
|
||||||
@@ -23,8 +23,9 @@ management:
|
|||||||
http.server.requests: true
|
http.server.requests: true
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
config:
|
cloud:
|
||||||
import: "optional:configserver:http://127.0.0.1:8888/config"
|
config:
|
||||||
|
name: wahlrecht
|
||||||
main:
|
main:
|
||||||
banner-mode: off
|
banner-mode: off
|
||||||
profiles:
|
profiles:
|
||||||
@@ -40,17 +41,6 @@ spring:
|
|||||||
application:
|
application:
|
||||||
name: wahlrecht
|
name: wahlrecht
|
||||||
|
|
||||||
|
|
||||||
# properties for application
|
|
||||||
de.twomartens.wahlrecht:
|
|
||||||
defaultTimeZone: Europe/Berlin
|
|
||||||
greeting: "Hello %s"
|
|
||||||
statusprobe:
|
|
||||||
scheduleDuration: 60
|
|
||||||
maxKafkaFailureDuration: 5
|
|
||||||
maxBlobFailureCount: 5
|
|
||||||
maxFailurePercent: 50
|
|
||||||
|
|
||||||
springdoc:
|
springdoc:
|
||||||
swagger-ui:
|
swagger-ui:
|
||||||
display-request-duration: true
|
display-request-duration: true
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
de.twomartens.wahlrecht:
|
||||||
|
greeting: "Moin %s, you are test"
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
de.twomartens.wahlrecht:
|
||||||
|
defaultTimeZone: Europe/Berlin
|
||||||
|
greeting: "Hello %s, on millenium"
|
||||||
|
statusprobe:
|
||||||
|
scheduleDuration: 60
|
||||||
|
maxKafkaFailureDuration: 5
|
||||||
|
maxBlobFailureCount: 5
|
||||||
|
maxFailurePercent: 50
|
||||||
Reference in New Issue
Block a user