-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lager et søtt Spanner image for lokal kjøring
Co-authored-by: Hege Haavaldsen <hege.haavaldsen@nav.no>
- Loading branch information
1 parent
512ab45
commit 3198739
Showing
7 changed files
with
200 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Bygge lokal-spanner image | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
name: build docker image | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '21.x' | ||
cache: 'gradle' | ||
- name: test and build | ||
run: ./gradlew build -settings-file lokal-spanner.settings.gradle.kts | ||
env: | ||
ORG_GRADLE_PROJECT_githubPassword: ${{ secrets.GITHUB_TOKEN }} | ||
- name: build docker image | ||
uses: nais/docker-build-push@v0 | ||
id: docker-build-push | ||
with: | ||
team: tbd | ||
tag: latest | ||
dockerfile: Dockerfile | ||
docker_context: filbackend | ||
image_suffix: lokal | ||
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }} | ||
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Lokal Spanner | ||
|
||
Dette er en readme i startgropen. | ||
|
||
``` | ||
gcloud auth configure-docker europe-north1-docker.pkg.dev | ||
gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://europe-north1-docker.pkg.dev | ||
docker europe-north1-docker.pkg.dev/nais-management-233d/tbd/helse-spanner-lokal:latest | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import java.nio.file.Paths | ||
|
||
val ktorVersion = "2.3.7" | ||
|
||
plugins { | ||
kotlin("jvm") version "1.9.22" | ||
} | ||
|
||
repositories { | ||
val githubPassword: String? by project | ||
mavenCentral() | ||
/* ihht. https://github.com/navikt/utvikling/blob/main/docs/teknisk/Konsumere%20biblioteker%20fra%20Github%20Package%20Registry.md | ||
så plasseres github-maven-repo (med autentisering) før nav-mirror slik at github actions kan anvende førstnevnte. | ||
Det er fordi nav-mirroret kjører i Google Cloud og da ville man ellers fått unødvendige utgifter til datatrafikk mellom Google Cloud og GitHub | ||
*/ | ||
maven { | ||
url = uri("https://maven.pkg.github.com/navikt/maven-release") | ||
credentials { | ||
username = "x-access-token" | ||
password = githubPassword | ||
} | ||
} | ||
maven("https://github-package-registry-mirror.gc.nav.no/cached/maven-release") | ||
} | ||
|
||
dependencies { | ||
implementation("io.ktor:ktor-server-core:$ktorVersion") | ||
implementation("io.ktor:ktor-server-cio:$ktorVersion") | ||
implementation("ch.qos.logback:logback-classic:1.4.12") | ||
implementation("net.logstash.logback:logstash-logback-encoder:7.4") { | ||
exclude("com.fasterxml.jackson.core") | ||
exclude("com.fasterxml.jackson.dataformat") | ||
} | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(21) | ||
} | ||
} | ||
|
||
tasks { | ||
test { | ||
useJUnitPlatform() | ||
testLogging { | ||
events("passed", "skipped", "failed") | ||
} | ||
} | ||
|
||
jar { | ||
mustRunAfter(":frontend:npm_run_build") | ||
|
||
archiveFileName.set("app.jar") | ||
|
||
manifest { | ||
attributes["Main-Class"] = "FilbackendKt" | ||
attributes["Class-Path"] = configurations.runtimeClasspath.get().joinToString(separator = " ") { | ||
it.name | ||
} | ||
} | ||
|
||
|
||
from({ Paths.get(project(":frontend").layout.buildDirectory.get().toString()) }) { | ||
into("static") | ||
} | ||
|
||
doLast { | ||
configurations.runtimeClasspath.get() | ||
.filter { it.name != "app.jar" } | ||
.forEach { | ||
val file = File("${layout.buildDirectory.get()}/libs/${it.name}") | ||
if (!file.exists()) it.copyTo(file) | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import Filsluse.finnHendelse | ||
import Filsluse.finnPerson | ||
import io.ktor.http.* | ||
import io.ktor.http.ContentType.Application.Json | ||
import io.ktor.http.HttpStatusCode.Companion.BadRequest | ||
import io.ktor.http.HttpStatusCode.Companion.NotFound | ||
import io.ktor.http.HttpStatusCode.Companion.OK | ||
import io.ktor.server.application.* | ||
import io.ktor.server.cio.* | ||
import io.ktor.server.engine.* | ||
import io.ktor.server.http.content.* | ||
import io.ktor.server.response.* | ||
import io.ktor.server.routing.* | ||
import java.util.UUID | ||
|
||
fun main() { | ||
embeddedServer(CIO, environment = applicationEngineEnvironment { | ||
|
||
module { | ||
routing { | ||
frontendRouting() | ||
|
||
get("/api/meg") { | ||
call.respondText("""{ "navn": "Viggo Velferdsvenn", "ident": "V1660" } """, Json, OK) | ||
} | ||
|
||
get("/api/person/") { | ||
val maskertId = call.request.headers["maskertId"]?.let { UUID.fromString(it) } ?: return@get call.respond(BadRequest) | ||
val person = maskertId.finnPerson() ?: return@get call.respond(NotFound) | ||
call.respondText(person, Json, OK) | ||
} | ||
|
||
post("/api/uuid/") { | ||
val maskertId = call.request.headers["maskertId"]?.let { UUID.fromString(it) } ?: return@post call.respond(BadRequest) | ||
val person = maskertId.finnPerson() ?: return@post call.respond(NotFound) | ||
call.respondText(person, Json, OK) | ||
} | ||
|
||
get("/api/hendelse/{meldingsreferanse}") { | ||
val meldingsreferanse = call.parameters["meldingsreferanse"]?.let { UUID.fromString(it) } ?: return@get call.respond(BadRequest) | ||
val hendelse = meldingsreferanse.finnHendelse() ?: return@get call.respond(NotFound) | ||
call.respondText(hendelse, Json, OK) | ||
} | ||
} | ||
} | ||
|
||
connector { | ||
port = 3000 | ||
} | ||
}).start(true) | ||
} | ||
|
||
private fun Route.frontendRouting() { | ||
get("/person/*") { | ||
call.respondText( | ||
this::class.java.classLoader.getResource("static/index.html")!!.readText(), | ||
ContentType.Text.Html | ||
) | ||
} | ||
staticResources("/", "/static/") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import java.io.File | ||
import java.util.UUID | ||
|
||
object Filsluse { | ||
private fun String.innhold() = File(this).takeIf { it.exists() }?.readText() | ||
private fun spannerRoot() = "${System.getenv("HOME")}/.spanner" | ||
fun UUID.finnPerson() = "${spannerRoot()}/personer/$this.json".innhold() | ||
fun UUID.finnHendelse() = "${spannerRoot()}/hendelser/$this.json".innhold() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
rootProject.name = "lokal-spanner" | ||
|
||
pluginManagement { | ||
repositories { | ||
gradlePluginPortal() | ||
} | ||
} | ||
include("frontend", "filbackend") |