Skip to content

Commit

Permalink
Merge pull request #3 from navikt/dev/bekreftelse-api
Browse files Browse the repository at this point in the history
Dev/bekreftelse api
  • Loading branch information
naviktthomas authored Sep 16, 2024
2 parents b2402b3 + 23fe04a commit b346168
Show file tree
Hide file tree
Showing 60 changed files with 1,156 additions and 475 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/bekreftelse-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Bekreftelse API

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

env:
MODULE: bekreftelse-api
IMAGE: europe-north1-docker.pkg.dev/${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}/paw/paw-arbeidssoeker-bekreftelse-api
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 }},kafka=nav-dev

# 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 }},kafka=nav-prod
5 changes: 3 additions & 2 deletions apps/bekreftelse-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ 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:bekreftelse-interne-hendelser"))
implementation(project(":domain:bekreftelsesmelding-schema"))
implementation(project(":domain:bekreftelsesmelding-avro-schema"))

// Server
implementation(ktorServer.bundles.withNettyAndMicrometer)
Expand Down Expand Up @@ -73,7 +74,7 @@ java {
}

application {
mainClass.set("no.nav.paw.rapportering.api.ApplicationKt")
mainClass.set("no.nav.paw.bekreftelse.api.ApplicationKt")
}

tasks.withType<Test>().configureEach {
Expand Down
27 changes: 19 additions & 8 deletions apps/bekreftelse-api/nais/nais-dev.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
apiVersion: nais.io/v1alpha1
kind: Application
metadata:
name: paw-rapportering-api
name: paw-arbeidssoeker-bekreftelse-api
namespace: paw
labels:
team: paw
spec:
image: {{ image }}
port: 8080
env:
- name: KAFKA_KEY_SCOPE
value: "api://dev-gcp.paw.paw-kafka-key-generator/.default"
replicas:
min: 1
max: 1
resources:
limits:
memory: 1024Mi
Expand All @@ -26,9 +26,6 @@ spec:
claims:
extra:
- NAVident
replicas:
min: 1
max: 1
liveness:
path: /internal/isAlive
initialDelay: 10
Expand All @@ -43,4 +40,18 @@ spec:
enabled: true
runtime: java
kafka:
pool: nav-dev
pool: {{ kafka }}
streams: true
accessPolicy:
inbound:
rules:
- application: tokenx-token-generator
namespace: aura
- application: azure-token-generator
namespace: aura
outbound:
rules:
- application: paw-kafka-key-generator
namespace: paw
- application: poao-tilgang
namespace: poao
27 changes: 19 additions & 8 deletions apps/bekreftelse-api/nais/nais-prod.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
apiVersion: nais.io/v1alpha1
kind: Application
metadata:
name: paw-rapportering-api
name: paw-arbeidssoeker-bekreftelse-api
namespace: paw
labels:
team: paw
spec:
image: {{ image }}
port: 8080
env:
- name: KAFKA_KEY_SCOPE
value: "api://prod-gcp.paw.paw-kafka-key-generator/.default"
replicas:
min: 1
max: 1
resources:
limits:
memory: 1024Mi
Expand All @@ -26,9 +26,6 @@ spec:
claims:
extra:
- NAVident
replicas:
min: 1
max: 1
liveness:
path: /internal/isAlive
initialDelay: 10
Expand All @@ -43,4 +40,18 @@ spec:
enabled: true
runtime: java
kafka:
pool: nav-prod
pool: {{ kafka }}
streams: true
accessPolicy:
inbound:
rules:
- application: tokenx-token-generator
namespace: aura
- application: azure-token-generator
namespace: aura
outbound:
rules:
- application: paw-kafka-key-generator
namespace: paw
- application: poao-tilgang
namespace: poao
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,41 @@ 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.config.hoplite.loadNaisOrLocalConfiguration
import no.nav.paw.config.kafka.KAFKA_CONFIG_WITH_SCHEME_REG
import no.nav.paw.config.kafka.KAFKA_STREAMS_CONFIG_WITH_SCHEME_REG
import no.nav.paw.config.kafka.KafkaConfig
import no.nav.paw.kafkakeygenerator.auth.AzureM2MConfig
import no.nav.paw.kafkakeygenerator.client.KafkaKeyConfig
import no.nav.paw.bekreftelse.api.config.APPLICATION_CONFIG_FILE_NAME
import no.nav.paw.bekreftelse.api.config.ApplicationConfig
import no.nav.paw.bekreftelse.api.config.SERVER_CONFIG_FILE_NAME
import no.nav.paw.bekreftelse.api.config.ServerConfig
import no.nav.paw.bekreftelse.api.plugins.configureAuthentication
import no.nav.paw.bekreftelse.api.plugins.configureHTTP
import no.nav.paw.bekreftelse.api.plugins.configureKafka
import no.nav.paw.bekreftelse.api.plugins.configureLogging
import no.nav.paw.bekreftelse.api.plugins.configureMetrics
import no.nav.paw.bekreftelse.api.plugins.configureOtel
import no.nav.paw.bekreftelse.api.plugins.configureSerialization
import no.nav.paw.bekreftelse.api.routes.healthRoutes
import no.nav.paw.bekreftelse.api.plugins.configureTracing
import no.nav.paw.bekreftelse.api.routes.bekreftelseRoutes
import no.nav.paw.bekreftelse.api.routes.metricsRoutes
import no.nav.paw.bekreftelse.api.routes.swaggerRoutes
import no.nav.paw.config.hoplite.loadNaisOrLocalConfiguration
import no.nav.paw.health.route.healthRoutes
import org.slf4j.LoggerFactory

fun main() {
val logger = LoggerFactory.getLogger("rapportering-api")
logger.info("Starter: ${ApplicationInfo.id}")
val logger = LoggerFactory.getLogger("no.nav.paw.logger.application")

val applicationConfig = loadNaisOrLocalConfiguration<ApplicationConfig>(APPLICATION_CONFIG_FILE_NAME)
val kafkaConfig = loadNaisOrLocalConfiguration<KafkaConfig>(KAFKA_CONFIG_WITH_SCHEME_REG)
val kafkaStreamsConfig = loadNaisOrLocalConfiguration<KafkaConfig>(KAFKA_STREAMS_CONFIG_WITH_SCHEME_REG)
val azureM2MConfig = loadNaisOrLocalConfiguration<AzureM2MConfig>("azure_m2m_key_config.toml")
val kafkaKeyConfig = loadNaisOrLocalConfiguration<KafkaKeyConfig>("kafka_key_generator_client_config.toml")
val serverConfig = loadNaisOrLocalConfiguration<ServerConfig>(SERVER_CONFIG_FILE_NAME)

val dependencies = createDependencies(
applicationConfig,
kafkaConfig,
kafkaStreamsConfig,
azureM2MConfig,
kafkaKeyConfig
)
logger.info("Starter: ${applicationConfig.appId}")

embeddedServer(Netty, port = 8080) {
module(applicationConfig, dependencies)
}.apply {
addShutdownHook { stop(300, 300) }
start(wait = true)
val dependencies = createDependencies(applicationConfig)

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

Expand All @@ -56,22 +49,22 @@ fun Application.module(
) {
configureMetrics(dependencies.prometheusMeterRegistry)
configureHTTP()
configureAuthentication(applicationConfig.authProviders)
configureAuthentication(applicationConfig)
configureLogging()
configureSerialization()
configureOtel()
configureTracing()
if (!applicationConfig.brukMock) { // TODO Bruker mock for utvikling
configureKafka(applicationConfig, listOf(dependencies.bekreftelseKafkaStreams))
}

routing {
healthRoutes(dependencies.prometheusMeterRegistry, dependencies.health)
healthRoutes(dependencies.healthIndicatorRepository)
metricsRoutes(dependencies.prometheusMeterRegistry)
swaggerRoutes()
bekreftelseRoutes(
kafkaKeyClient = dependencies.kafkaKeysClient,
bekreftelseStateStore = dependencies.bekreftelseStateStore,
stateStoreName = applicationConfig.bekreftelseStateStoreName,
kafkaStreams = dependencies.kafkaStreams,
httpClient = dependencies.httpClient,
bekreftelseProducer = dependencies.bekreftelseProducer,
autorisasjonService = dependencies.autorisasjonService
dependencies.kafkaKeysClient,
dependencies.bekreftelseService,
dependencies.autorisasjonService
)
}
}
Expand Down

This file was deleted.

Loading

0 comments on commit b346168

Please sign in to comment.