Skip to content

Commit

Permalink
Tweaks etter flytting av kafka-key-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
naviktthomas committed Aug 14, 2024
1 parent f610332 commit 0ed83a6
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 119 deletions.
62 changes: 43 additions & 19 deletions .github/workflows/kafka-key-generator.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
name: Build, push, and deploy
name: PAW Kafka Key Generator

on: [push]
on:
push:
paths:
- 'apps/kafka-key-generator/**'
- 'lib/**'
- 'domain/**'
- '.github/workflows/kafka-key-generator.yaml'
- 'gradle/**'
- 'settings.gradle.kts'
- 'gradle.properties'
- 'gradlew'
- 'gradlew.bat'

env:
IMAGE: europe-north1-docker.pkg.dev/${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}/paw/${{ github.event.repository.name }}
IMAGE: europe-north1-docker.pkg.dev/${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}/paw/paw-kafka-key-generator
jobs:
build:
name: Build and push Docker container
Expand All @@ -14,60 +25,73 @@ jobs:
outputs:
image: ${{ steps.docker-build-push.outputs.image }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
- name: Checkout
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: 21
distribution: temurin
cache: gradle
- name: Set version
- name: Specify module
run: echo "MODULE=:apps:kafka-key-generator" >> $GITHUB_ENV
- name: Specify version
run: echo "VERSION=$(date +'%y.%m.%d').${{ github.run_number }}-${{ github.run_attempt }}" >> $GITHUB_ENV
- name: Login GAR
uses: nais/login@v0
with:
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
team: paw
- name: Build and push image with Gradle
- name: Build and push image
id: docker-build-push
working-directory: ./
run: |
echo "image=${{ env.IMAGE }}:${{ env.VERSION }}" >> $GITHUB_OUTPUT
./gradlew -Pversion=${{ env.VERSION }} -Pimage=${{ env.IMAGE }} build jib
echo -Pversion=${{ env.VERSION }} -Pimage=${{ env.IMAGE }} ${{ env.MODULE }}:build ${{ env.MODULE }}:test ${{ env.MODULE }}:jib
./gradlew -Pversion=${{ env.VERSION }} -Pimage=${{ env.IMAGE }} ${{ env.MODULE }}:build ${{ env.MODULE }}:test ${{ env.MODULE }}:jib
echo "DIGEST=$(cat app/build/jib-image.digest)" >> $GITHUB_ENV
env:
ORG_GRADLE_PROJECT_githubPassword: ${{ secrets.GITHUB_TOKEN }}
- name: Attest and sign
- name: Attest and sign image
uses: nais/[email protected]
with:
image_ref: ${{ env.IMAGE }}@${{ env.DIGEST }}

deploy-dev:
name: Deploy to NAIS dev
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/dev')
name: Deploy to dev-gcp
needs:
- build
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: nais/deploy/actions/deploy@v2
- name: Checkout
uses: actions/checkout@v3
- name: Deploy to GCP
uses: nais/deploy/actions/deploy@v2
env:
CLUSTER: dev-gcp
RESOURCE: nais/nais-dev.yaml
VAR: image=${{ needs.build.outputs.image }}

deploy-prod:
if: github.ref == 'refs/heads/main'
name: Deploy to NAIS prod
name: Deploy to prod-gcp
needs:
- build
- deploy-dev
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
needs: [deploy-dev,build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: nais/deploy/actions/deploy@v2
- name: Checkout
uses: actions/checkout@v3
- name: Deploy to GCP
uses: nais/deploy/actions/deploy@v2
env:
CLUSTER: prod-gcp
RESOURCE: nais/nais-prod.yaml
Expand Down
140 changes: 73 additions & 67 deletions apps/kafka-key-generator/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,100 +1,102 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "2.0.0"
kotlin("jvm")
application
id("com.google.cloud.tools.jib") version "3.4.3"
id("com.google.cloud.tools.jib")
}
val jvmVersion = 21
val image: String? by project


val exposedVersion = "0.52.0"
val logbackVersion = "1.5.2"
val logstashVersion = "7.4"
val navCommonModulesVersion = "3.2024.05.23_05.46-2b29fa343e8e"
val tokenSupportVersion = "5.0.1"
val ktorVersion = "2.3.12"
val image: String? by project
val baseImage: String by project
val jvmMajorVersion: String by project

dependencies {
implementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-annotations:2.1.0")
// Konfigurasjon
implementation("com.sksamuel.hoplite:hoplite-core:2.8.0.RC3")
implementation("com.sksamuel.hoplite:hoplite-toml:2.8.0.RC3")
// PAW
implementation(project(":lib:hoplite-config"))
implementation(pawClients.pawPdlClient)

// NAV
implementation("no.nav.security:token-validation-ktor-v2:$tokenSupportVersion")
implementation("no.nav.security:token-client-core:$tokenSupportVersion")
implementation("no.nav.common:token-client:$navCommonModulesVersion")
implementation("no.nav.common:log:$navCommonModulesVersion")
implementation("no.nav.security:token-validation-ktor-v2:$tokenSupportVersion")
implementation("no.nav.security:token-client-core:$tokenSupportVersion")
implementation("no.nav.paw:pdl-client:24.07.04.39-1")

// Database
implementation("org.postgresql:postgresql:42.7.3")
implementation("org.flywaydb:flyway-core:9.21.2")
implementation("org.jetbrains.exposed:exposed-core:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-crypt:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-dao:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
implementation("com.zaxxer:HikariCP:5.1.0")
implementation(navCommon.log)
implementation(navCommon.tokenClient)
implementation(navSecurity.tokenClient)
implementation(navSecurity.tokenValidationKtorV2)

// Ktor
implementation("io.ktor:ktor-server-core:$ktorVersion")
implementation("io.ktor:ktor-server-core-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-netty:$ktorVersion")
implementation("io.ktor:ktor-server-metrics-micrometer:$ktorVersion")
implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-swagger:$ktorVersion")
implementation("io.ktor:ktor-server-status-pages:$ktorVersion")
implementation("io.ktor:ktor-serialization-jackson:$ktorVersion")
implementation("io.ktor:ktor-client-okhttp-jvm:$ktorVersion")
implementation("io.ktor:ktor-client-logging-jvm:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")

//Otel
implementation("io.opentelemetry:opentelemetry-api:1.39.0")
implementation("io.opentelemetry.instrumentation:opentelemetry-ktor-2.0:2.4.0-alpha")

// Micrometer
implementation("io.micrometer:micrometer-registry-prometheus:1.12.3")
implementation(ktor.serializationJackson)

// Ktor Server
implementation(ktorServer.bundles.withNettyAndMicrometer)
implementation(ktorServer.cors)
implementation(ktorServer.swagger)
implementation(ktorServer.callId)
implementation(ktorServer.statusPages)
implementation(ktorServer.contentNegotiation)

// Ktor Client
implementation(ktorClient.contentNegotiation)
implementation(ktorClient.core)
implementation(ktorClient.cio)
implementation(ktorClient.okhttp)
implementation(ktorClient.logging)

// Micrometer & OTEL
implementation(micrometer.registryPrometheus)
implementation(otel.api)
implementation(otel.annotations)
implementation(otel.ktor)

// Database
implementation(exposed.core)
implementation(exposed.crypt)
implementation(exposed.dao)
implementation(exposed.jdbc)
implementation(exposed.javaTime)
implementation(postgres.driver)
implementation(flyway.core)
implementation(flyway.postgres)
implementation(hikari.connectionPool)

// Config
implementation(hoplite.hopliteToml)

// Logging
implementation("ch.qos.logback:logback-classic:$logbackVersion")
implementation("net.logstash.logback:logstash-logback-encoder:$logstashVersion")
implementation(loggingLibs.logbackClassic)
implementation(loggingLibs.logstashLogbackEncoder)

// Tester
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.9.2")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testImplementation("io.kotest:kotest-runner-junit5-jvm:4.6.3")
testImplementation("io.ktor:ktor-client-mock:$ktorVersion")
testImplementation("org.testcontainers:postgresql:1.19.8")
}

tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
freeCompilerArgs.add("-Xcontext-receivers")
}
testImplementation(testLibs.bundles.withUnitTesting)
testImplementation(testLibs.testContainers)
testImplementation(testLibs.postgresql)
testImplementation(ktorServer.testJvm)
testImplementation(ktorClient.mock)
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(jvmVersion))
languageVersion.set(JavaLanguageVersion.of(jvmMajorVersion))
}
}

application {
mainClass.set("no.nav.paw.kafkakeygenerator.AppStarterKt")
}

tasks.named<Test>("test") {
useJUnitPlatform()
tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
freeCompilerArgs.add("-Xcontext-receivers")
}
}

tasks.withType(Jar::class) {
manifest {
attributes["Implementation-Version"] = project.version
attributes["Main-Class"] = application.mainClass.get()
attributes["Implementation-Title"] = rootProject.name
}
}

jib {
from.image = "ghcr.io/navikt/baseimages/temurin:$jvmVersion"
from.image = "$baseImage:$jvmMajorVersion"
to.image = "${image ?: project.name}:${project.version}"
container {
environment = mapOf(
Expand All @@ -107,6 +109,10 @@ jib {
}
}

tasks.named<Test>("test") {
useJUnitPlatform()
}

tasks.create("runTestApp", JavaExec::class) {
classpath = sourceSets["test"].runtimeClasspath +
sourceSets["main"].runtimeClasspath
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package no.nav.paw.kafkakeygenerator

import io.micrometer.prometheus.PrometheusConfig
import io.micrometer.prometheus.PrometheusMeterRegistry
import io.micrometer.prometheusmetrics.PrometheusConfig
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
import no.nav.paw.kafkakeygenerator.config.Autentiseringskonfigurasjon
import no.nav.paw.kafkakeygenerator.config.DatabaseKonfigurasjon
import no.nav.paw.kafkakeygenerator.config.dataSource
import no.nav.paw.kafkakeygenerator.config.lastKonfigurasjon
import no.nav.paw.kafkakeygenerator.database.flywayMigrate
import no.nav.paw.kafkakeygenerator.ktor.initKtorServer
import no.nav.paw.kafkakeygenerator.pdl.PdlIdentitesTjeneste
import no.nav.paw.kafkakeygenerator.pdl.opprettPdlKlient
import no.nav.paw.kafkakeygenerator.ktor.initKtorServer
import no.nav.paw.pdl.PdlClient
import org.jetbrains.exposed.sql.Database
import javax.sql.DataSource
Expand All @@ -33,6 +33,7 @@ fun main() {
pdlKlient
)
}

fun startApplikasjon(
autentiseringKonfig: Autentiseringskonfigurasjon,
dataSource: DataSource,
Expand All @@ -47,5 +48,6 @@ fun startApplikasjon(
Applikasjon(
KafkaKeys(database),
PdlIdentitesTjeneste(pdlKlient)
)).start(wait = true)
)
).start(wait = true)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package no.nav.paw.kafkakeygenerator.ktor

import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.micrometer.prometheus.PrometheusMeterRegistry
import io.ktor.server.application.call
import io.ktor.server.response.respond
import io.ktor.server.response.respondText
import io.ktor.server.routing.Routing
import io.ktor.server.routing.get
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry

fun Routing.konfigurereHelse(prometheusMeterRegistry: PrometheusMeterRegistry) {
get("/internal/isAlive") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package no.nav.paw.kafkakeygenerator.ktor

import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.micrometer.prometheus.PrometheusMeterRegistry
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
import no.nav.paw.kafkakeygenerator.Applikasjon
import no.nav.paw.kafkakeygenerator.config.Autentiseringskonfigurasjon

Expand Down
Loading

0 comments on commit 0ed83a6

Please sign in to comment.