Skip to content

Commit

Permalink
DOKY-204 Update deployment for email-service (#133)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hanna-eismant authored Dec 16, 2024
1 parent 8f67366 commit 36837f8
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 16 deletions.
13 changes: 6 additions & 7 deletions app-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,8 @@ tasks.named<Test>("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")
Expand All @@ -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
)
}
}
Expand Down
13 changes: 13 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter

allprojects {
repositories {
mavenLocal()
Expand All @@ -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)
Expand Down
30 changes: 29 additions & 1 deletion email-service/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
plugins {
alias(libs.plugins.spring.boot)
}

dependencyManagement {
imports {
mavenBom(libs.spring.boot.bom.get().toString())
Expand All @@ -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)
Expand Down Expand Up @@ -79,3 +82,28 @@ tasks.named<Test>("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)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -30,5 +31,7 @@ class EmailServiceApplication {
}

fun main(args: Array<String>) {
runApplication<EmailServiceApplication>(*args)
runApplication<EmailServiceApplication>(*args) {
setWebApplicationType(WebApplicationType.NONE)
}
}
2 changes: 0 additions & 2 deletions email-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 38 additions & 0 deletions email-service/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProfile name="!prod">
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<root level="info">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>
<springProfile name="prod">
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp>
<timeZone>UTC</timeZone>
</timestamp>
<loggerName/>
<logLevel>
<fieldName>status</fieldName>
</logLevel>
<threadName/>
<stackTrace/>
<message/>
<nestedField>
<fieldName>mdc</fieldName>
<providers>
<mdc/>
</providers>
</nestedField>
<throwableClassName/>
</providers>
</encoder>
</appender>
<root level="info">
<appender-ref ref="stdout"/>
</root>
</springProfile>
</configuration>
12 changes: 7 additions & 5 deletions teamcity/app-server.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
33 changes: 33 additions & 0 deletions teamcity/email-service.Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 36837f8

Please sign in to comment.