Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/devsetting-bekreftelse-tjeneste'
Browse files Browse the repository at this point in the history
  • Loading branch information
robertkittilsen committed Sep 30, 2024
2 parents 565457d + 448e9be commit 63b990e
Show file tree
Hide file tree
Showing 36 changed files with 1,539 additions and 784 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/bekreftelse-tjeneste.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Bekreftelse Tjeneste

on:
push:
branches:
- main
- dev/*
paths:
- 'apps/bekreftelse-tjeneste/**'
- 'lib/**'
- 'domain/**'
- '.github/workflows/bekreftelse-tjeneste.yaml'
- 'gradle/**'
- 'settings.gradle.kts'
- 'gradle.properties'
- 'gradlew'
- 'gradlew.bat'

env:
MODULE: bekreftelse-tjeneste
IMAGE: europe-north1-docker.pkg.dev/${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}/paw/paw-arbeidssoekerregisteret-bekreftelse-tjeneste
jobs:
build:
name: Build
permissions:
contents: read
id-token: write
packages: write
runs-on: ubuntu-latest
outputs:
image: ${{ steps.docker-build-push.outputs.image }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: gradle
- name: Set 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
id: docker-build-push
working-directory: ./
env:
ORG_GRADLE_PROJECT_githubPassword: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "image=${{ env.IMAGE }}:${{ env.VERSION }}" >> $GITHUB_OUTPUT
echo -Pversion=${{ env.VERSION }} -Pimage=${{ env.IMAGE }} :apps:${{ env.MODULE }}:build :apps:${{ env.MODULE }}:jib
./gradlew -Pversion=${{ env.VERSION }} -Pimage=${{ env.IMAGE }} :apps:${{ env.MODULE }}:build :apps:${{ env.MODULE }}:jib
echo "DIGEST=$(cat ./apps/${{ env.MODULE }}/build/jib-image.digest)" >> $GITHUB_ENV
- name: Attest and sign image
uses: nais/[email protected]
with:
image_ref: ${{ env.IMAGE }}@${{ env.DIGEST }}

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

# deploy-prod:
# if: github.ref == 'refs/heads/main'
# name: Deploy to prod-gcp
# needs:
# - build
# - deploy-dev
# permissions:
# contents: read
# id-token: write
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: Deploy to GCP
# uses: nais/deploy/actions/deploy@v2
# env:
# TEAM: paw
# CLUSTER: prod-gcp
# RESOURCE: ./apps/${{ env.MODULE }}/nais/nais-prod.yaml
# VAR: image=${{ needs.build.outputs.image }}
64 changes: 53 additions & 11 deletions apps/bekreftelse-tjeneste/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,36 +1,78 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
id("com.google.cloud.tools.jib")
application
}

val jvmMajorVersion: String by project
val baseImage: String by project
val image: String? by project


dependencies {
// Project
implementation(project(":lib:hoplite-config"))
implementation(project(":lib:error-handling"))
implementation(project(":lib:kafka-streams"))
implementation(project(":lib:kafka-key-generator-client"))
implementation(project(":domain:main-avro-schema"))
implementation(project(":domain:bekreftelse-interne-hendelser"))
implementation(project(":domain:bekreftelsesansvar-avro-schema"))
implementation(project(":domain:bekreftelsesmelding-avro-schema"))
implementation(libs.kafkaStreams)

// Server
implementation(libs.bundles.ktorServerWithNettyAndMicrometer)

// Serialization
implementation(libs.ktorSerializationJackson)
implementation(libs.ktorSerializationJson)
implementation(libs.jacksonDatatypeJsr310)
implementation(libs.jacksonKotlin)
implementation(libs.kafkaStreamsAvroSerde)

// Tooling
implementation(libs.arrowCore)
implementation(libs.bundles.ktorServerWithNettyAndMicrometer)

// Logging
implementation(libs.logbackClassic)
implementation(libs.logstashLogbackEncoder)
implementation(libs.log)
implementation(libs.auditLog)

// Instrumentation
implementation(libs.micrometerRegistryPrometheus)

// Kafka
implementation(libs.kafkaStreams)
implementation(libs.kafkaStreamsAvroSerde)

// Testing
testImplementation(libs.ktorServerTestsJvm)
testImplementation(libs.streamsTest)
testImplementation(libs.runnerJunit5)
testImplementation(libs.assertionsCore)
testImplementation(libs.bundles.testLibsWithUnitTesting)
testImplementation(project(":test:test-data-lib"))
}

//enable context receiver
tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
freeCompilerArgs.add("-Xcontext-receivers")
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(jvmMajorVersion))
}
}

application {
mainClass.set("no.nav.paw.bekreftelsetjeneste.ApplicationKt")
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

jib {
from.image = "$baseImage:$jvmMajorVersion"
to.image = "${image ?: project.name}:${project.version}"
container {
environment = mapOf(
"IMAGE_WITH_VERSION" to "${image ?: project.name}:${project.version}"
)
jvmFlags = listOf("-XX:ActiveProcessorCount=4", "-XX:+UseZGC", "-XX:+ZGenerational")
}
}
58 changes: 58 additions & 0 deletions apps/bekreftelse-tjeneste/nais/nais-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
apiVersion: nais.io/v1alpha1
kind: Application
metadata:
name: paw-arbeidssoekerregisteret-bekreftelse-tjeneste
namespace: paw
labels:
team: paw
spec:
image: {{ image }}
port: 8080
env:
- name: KAFKA_STREAMS_ID_SUFFIX
value: "v1"
- name: KAFKA_PAW_ARBEIDSSOKER_BEKREFTELSE_TOPIC
value: "paw.arbeidssoker-bekreftelse-beta-v1"
- name: KAFKA_PAW_ARBEIDSSOKER_BEKREFTELSE_HENDELSELOGG_TOPIC
value: "paw.arbeidssoker-bekreftelse-hendelseslogg-beta-v1"
- name: KAFKA_PAW_ARBEIDSSOKERPERIODER_TOPIC
value: "paw.arbeidssokerperioder-v1"
- name: KAFKA_PUNCTUATOR_INTERVAL
value: "PT1M"
- name: BEKREFTELSE_INTERVAL
value: "PT28M"
- name: BEKREFTELSE_GRACEPERIODE
value: "PT14M"
- name: BEKREFTELSE_TILGJENGELIG_OFFSET
value: "PT6M"

replicas:
min: 1
max: 1
resources:
limits:
memory: 1024Mi
requests:
cpu: 200m
memory: 256Mi
liveness:
path: /internal/isAlive
initialDelay: 10
readiness:
path: /internal/isReady
initialDelay: 10
prometheus:
enabled: true
path: /internal/metrics
observability:
autoInstrumentation:
enabled: true
runtime: java
kafka:
pool: nav-dev
streams: true
accessPolicy:
outbound:
rules:
- application: paw-kafka-key-generator
namespace: paw

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package no.nav.paw.bekreftelsetjeneste

import io.ktor.server.application.Application
import io.ktor.server.engine.addShutdownHook
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import io.ktor.server.routing.routing
import no.nav.paw.bekreftelsetjeneste.config.APPLICATION_CONFIG_FILE_NAME
import no.nav.paw.bekreftelsetjeneste.config.ApplicationConfig
import no.nav.paw.bekreftelsetjeneste.config.SERVER_CONFIG_FILE_NAME
import no.nav.paw.bekreftelsetjeneste.config.ServerConfig
import no.nav.paw.bekreftelsetjeneste.context.ApplicationContext
import no.nav.paw.bekreftelsetjeneste.plugins.buildKafkaStreams
import no.nav.paw.bekreftelsetjeneste.plugins.configureKafka
import no.nav.paw.bekreftelsetjeneste.plugins.configureMetrics
import no.nav.paw.bekreftelsetjeneste.routes.metricsRoutes
import no.nav.paw.bekreftelsetjeneste.topology.buildTopology
import no.nav.paw.config.env.appNameOrDefaultForLocal
import no.nav.paw.config.env.currentRuntimeEnvironment
import no.nav.paw.config.hoplite.loadNaisOrLocalConfiguration
import no.nav.paw.health.route.healthRoutes
import org.slf4j.LoggerFactory

fun main() {
val logger = LoggerFactory.getLogger("no.nav.paw.logger.application")

val serverConfig = loadNaisOrLocalConfiguration<ServerConfig>(SERVER_CONFIG_FILE_NAME)
val applicationConfig = loadNaisOrLocalConfiguration<ApplicationConfig>(APPLICATION_CONFIG_FILE_NAME)

logger.info("Starter: ${currentRuntimeEnvironment.appNameOrDefaultForLocal()}")

with(serverConfig) {
embeddedServer(Netty, port = port) {
module(applicationConfig)
}.apply {
addShutdownHook { stop(gracePeriodMillis, timeoutMillis) }
start(wait = true)
}
}
}

fun Application.module(applicationConfig: ApplicationConfig) {
val applicationContext = ApplicationContext.create(applicationConfig)

val kafkaTopology = buildTopology(applicationContext)
val kafkaStreams = buildKafkaStreams(applicationContext, kafkaTopology)

configureMetrics(applicationContext)
configureKafka(applicationContext, kafkaStreams)

routing {
healthRoutes(applicationContext.healthIndicatorRepository)
metricsRoutes(applicationContext)
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 63b990e

Please sign in to comment.