From 36837f8351af222e4e6fc51190250045525626b8 Mon Sep 17 00:00:00 2001 From: Hanna Kurhuzenkava Date: Mon, 16 Dec 2024 21:29:18 +0300 Subject: [PATCH] DOKY-204 Update deployment for email-service (#133) Set up non-web `email-service` and enhance observability Configured `email-service` to run as a non-web application by disabling the web application type. Added a dedicated `Dockerfile` for `email-service` with Datadog integration and introduced a production-specific JSON logging configuration. Adjusted environment configurations to improve flexibility and maintain consistency across services. --- app-server/build.gradle.kts | 13 +++---- build.gradle.kts | 13 +++++++ email-service/build.gradle.kts | 30 ++++++++++++++- .../org/hkurh/doky/EmailServiceApplication.kt | 5 ++- .../src/main/resources/application.properties | 2 - .../src/main/resources/logback-spring.xml | 38 +++++++++++++++++++ teamcity/app-server.Dockerfile | 12 +++--- teamcity/email-service.Dockerfile | 33 ++++++++++++++++ 8 files changed, 130 insertions(+), 16 deletions(-) create mode 100644 email-service/src/main/resources/logback-spring.xml create mode 100644 teamcity/email-service.Dockerfile diff --git a/app-server/build.gradle.kts b/app-server/build.gradle.kts index 778c8029..21447d23 100644 --- a/app-server/build.gradle.kts +++ b/app-server/build.gradle.kts @@ -126,11 +126,8 @@ tasks.named("integrationTest") { } } -val deployVersion = if (project.hasProperty("deployVersion")) { - project.property("deployVersion") as String -} else { - "Aardvark-v0.1" -} +val deployVersion = rootProject.extra["deployVersion"] as String +val buildDate = rootProject.extra["buildDate"] as String buildConfig { packageName("org.hkurh.doky") @@ -144,11 +141,13 @@ tasks { attributes( "Manifest-Version" to "1.0", "Main-Class" to "org.hkurh.doky.DokyApplication", - "Implementation-Title" to "Doky", + "Implementation-Title" to "Doky App Server", "Implementation-Version" to deployVersion, "Implementation-Vendor" to "hkurh-pets", "Created-By" to "Kotlin Gradle", - "Built-By" to "Hanna Kurhuzenkava" + "Built-By" to "Hanna Kurhuzenkava", + "Build-Jdk" to "17", + "Build-Date" to buildDate ) } } diff --git a/build.gradle.kts b/build.gradle.kts index 5eabe02d..a6181a9f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,6 @@ +import java.time.ZonedDateTime +import java.time.format.DateTimeFormatter + allprojects { repositories { mavenLocal() @@ -6,6 +9,16 @@ allprojects { } group = "org.hkurh.doky" +val deployVersion: String by extra { + if (project.hasProperty("deployVersion")) { + project.property("deployVersion") as String + } else { + "Aardvark-v0.1" + } +} +val buildDate: String by extra { + ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss Z")) +} plugins { alias(libs.plugins.kotlin.jvm) diff --git a/email-service/build.gradle.kts b/email-service/build.gradle.kts index 6f8a7782..e329c0ec 100644 --- a/email-service/build.gradle.kts +++ b/email-service/build.gradle.kts @@ -1,3 +1,7 @@ +plugins { + alias(libs.plugins.spring.boot) +} + dependencyManagement { imports { mavenBom(libs.spring.boot.bom.get().toString()) @@ -14,7 +18,6 @@ configurations { dependencies { implementation(project(":persistence")) - implementation(libs.bundles.spring.starter.web) implementation(libs.spring.boot.starter.data.jpa) implementation(libs.bundles.mail) implementation(libs.bundles.azure.keyvault) @@ -79,3 +82,28 @@ tasks.named("integrationTest") { events("PASSED", "SKIPPED", "FAILED") } } + +val deployVersion = rootProject.extra["deployVersion"] as String +val buildDate = rootProject.extra["buildDate"] as String + +tasks { + jar { + manifest { + attributes( + "Manifest-Version" to "1.0", + "Main-Class" to "org.hkurh.doky.EmailServiceApplication", + "Implementation-Title" to "Doky Email Service", + "Implementation-Version" to deployVersion, + "Implementation-Vendor" to "hkurh-pets", + "Created-By" to "Kotlin Gradle", + "Built-By" to "Hanna Kurhuzenkava", + "Build-Jdk" to "17", + "Build-Date" to buildDate + ) + } + } + + assemble { + dependsOn(jar) + } +} diff --git a/email-service/src/main/kotlin/org/hkurh/doky/EmailServiceApplication.kt b/email-service/src/main/kotlin/org/hkurh/doky/EmailServiceApplication.kt index a4dfe190..6a18e8a4 100644 --- a/email-service/src/main/kotlin/org/hkurh/doky/EmailServiceApplication.kt +++ b/email-service/src/main/kotlin/org/hkurh/doky/EmailServiceApplication.kt @@ -1,6 +1,7 @@ package org.hkurh.doky import org.springframework.beans.factory.annotation.Value +import org.springframework.boot.WebApplicationType import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication import org.springframework.context.annotation.Bean @@ -30,5 +31,7 @@ class EmailServiceApplication { } fun main(args: Array) { - runApplication(*args) + runApplication(*args) { + setWebApplicationType(WebApplicationType.NONE) + } } diff --git a/email-service/src/main/resources/application.properties b/email-service/src/main/resources/application.properties index ef1c619d..f91e82a0 100644 --- a/email-service/src/main/resources/application.properties +++ b/email-service/src/main/resources/application.properties @@ -39,5 +39,3 @@ doky.kafka.emails.group.id=doky-email-service doky.kafka.emails.consumer.id=email-notification-consumer doky.kafka.emails.consumer.autostart=true doky.kafka.emails.concurrency=3 -# actuator -management.endpoints.enabled-by-default=true diff --git a/email-service/src/main/resources/logback-spring.xml b/email-service/src/main/resources/logback-spring.xml new file mode 100644 index 00000000..ce3e08ae --- /dev/null +++ b/email-service/src/main/resources/logback-spring.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + UTC + + + + status + + + + + + mdc + + + + + + + + + + + + + diff --git a/teamcity/app-server.Dockerfile b/teamcity/app-server.Dockerfile index f2440f41..e45d5162 100644 --- a/teamcity/app-server.Dockerfile +++ b/teamcity/app-server.Dockerfile @@ -4,13 +4,15 @@ COPY --from=datadog/serverless-init:1 /datadog-init /app/datadog-init ADD 'https://dtdg.co/latest-java-tracer' /dd_tracer/java/dd-java-agent.jar ARG DD_VERSION=Aardvark-v0.1 +ARG DD_SERVICE=app-server +ARG DD_ENV=prod -ENV DD_SERVICE=app-server -ENV DD_ENV=prod +ENV DD_SERVICE=$DD_SERVICE +ENV DD_ENV=$DD_ENV ENV DD_VERSION=$DD_VERSION -LABEL com.datadoghq.tags.service=app-server -LABEL com.datadoghq.tags.env=prod +LABEL com.datadoghq.tags.service=$DD_SERVICE +LABEL com.datadoghq.tags.env=$DD_ENV LABEL com.datadoghq.tags.version=$DD_VERSION ENV DD_TRACE_SQL_ENABLED=true @@ -30,4 +32,4 @@ EXPOSE 8080 ARG JAR_FILE=app-server/build/libs/app-server.jar COPY ${JAR_FILE} app.jar -CMD ["/app/datadog-init", "java", "-jar", "-Dspring.profiles.active=prod", "/app.jar"] +CMD ["/app/datadog-init", "java", "-jar", "-Dspring.profiles.active=$DD_ENV", "/app.jar"] diff --git a/teamcity/email-service.Dockerfile b/teamcity/email-service.Dockerfile new file mode 100644 index 00000000..f5b0b321 --- /dev/null +++ b/teamcity/email-service.Dockerfile @@ -0,0 +1,33 @@ +FROM openjdk:17 + +COPY --from=datadog/serverless-init:1 /datadog-init /app/datadog-init +ADD 'https://dtdg.co/latest-java-tracer' /dd_tracer/java/dd-java-agent.jar + +ARG DD_VERSION=Aardvark-v0.1 +ARG DD_SERVICE=email-service +ARG DD_ENV=prod + +ENV DD_SERVICE=$DD_SERVICE +ENV DD_ENV=$DD_ENV +ENV DD_VERSION=$DD_VERSION + +LABEL com.datadoghq.tags.service=$DD_SERVICE +LABEL com.datadoghq.tags.env=$DD_ENV +LABEL com.datadoghq.tags.version=$DD_VERSION + +ENV DD_TRACE_SQL_ENABLED=true +ENV DD_DATABASE_MONITORING=true +ENV DD_MSSQL_ENABLED=true + +ENV DD_LOGS_ENABLED=true +ENV DD_IAST_ENABLED=true +ENV DD_APPSEC_ENABLED=true +ENV DD_PROFILING_ENABLED=true +ENV DD_TRACE_ENABLED=true +ENV DD_LOGS_INJECTION=true +ENV DD_TRACE_SAMPLE_RATE=1 + +ARG JAR_FILE=email-service/build/libs/email-service.jar +COPY ${JAR_FILE} app.jar + +CMD ["/app/datadog-init", "java", "-jar", "-Dspring.profiles.active=$DD_ENV", "/app.jar"]