Skip to content

Commit

Permalink
Placeholder app for GCP PSQL (#3641)
Browse files Browse the repository at this point in the history
Ny app dolly-db som deployes for GCP-databaser.
  • Loading branch information
rfc3092 authored Oct 4, 2024
1 parent db9a3bf commit c6fe59d
Show file tree
Hide file tree
Showing 45 changed files with 760 additions and 166 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/db.dolly-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: db-dolly-backend

on:
push:
paths:
- "apps/dolly-db/db.dolly-backend.yml"
- "apps/dolly-db/src/**"
- ".github/workflows/db.dolly-backend.yml"

jobs:
workflow:
uses: ./.github/workflows/common.workflow.backend.yml
with:
working-directory: "apps/dolly-db"
nais-manifest: "db.dolly-backend.yml"
deploy-tag: "#db-dolly-backend"
sonar-enabled: false
permissions:
contents: read
id-token: write
secrets: inherit
20 changes: 20 additions & 0 deletions .github/workflows/db.organisasjon-forvalter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: db-organisasjon-forvalter

on:
push:
paths:
- "apps/dolly-db/db.organisasjon.forvalter.yml"
- ".github/workflows/db.organisasjon-forvalter.yml"

jobs:
workflow:
uses: ./.github/workflows/common.workflow.backend.yml
with:
working-directory: "apps/dolly-db"
nais-manifest: "db.organisasjon-forvalter.yml"
deploy-tag: "#db-organisasjon-forvalter"
sonar-enabled: false
permissions:
contents: read
id-token: write
secrets: inherit
20 changes: 20 additions & 0 deletions .github/workflows/db.pdl-forvalter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: db-pdl-forvalter

on:
push:
paths:
- "apps/dolly-db/db.pdl-forvalter.yml"
- ".github/workflows/db.pdl-forvalter.yml"

jobs:
workflow:
uses: ./.github/workflows/common.workflow.backend.yml
with:
working-directory: "apps/dolly-db"
nais-manifest: "db.pdl-forvalter.yml"
deploy-tag: "#db-pdl-forvalter"
sonar-enabled: false
permissions:
contents: read
id-token: write
secrets: inherit
33 changes: 8 additions & 25 deletions apps/dolly-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,17 @@ https://dolly.ekstern.dev.nav.no/swagger-ui.html
https://dolly-backend.intern.dev.nav.no/swagger-ui.html

## Kjør lokalt

https://dolly-backend.intern.dev.nav.no/swagger-ui.html

1. `naisdevice` må kjøre og være grønn.
2. Vault token må enten hentes manuelt fra [Vault](https://vault.adeo.no/) og settes ved kjøring som VM option `-Dspring.cloud.vault.token=<TOKEN>` eller så må du være logget inn med Vault CLI slik at token kan hentes med `vault print token` før applikasjonen kjører.

Så kjør `./gradlew clean build`

Deretter kan DollyBackendApplicationStarter startes med disse VM options:

```
-Dspring.profiles.active=local --add-opens java.base/java.lang=ALL-UNNAMED
* Se [generell informasjon](../../docs/local_general.md).
* Applikasjonen er avhengig av en database i GCP, se [egen dokumentasjon](../../docs/gcp_db.md).
* Applikasjonen er avhengig av Elasticsearch:
```aiexclude
> docker run -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" -e "plugins.security.disabled=true" -e "OPENSEARCH_INITIAL_ADMIN_PASSWORD=YLAgOm}rz#o6#Aq" --name opensearch -d opensearchproject/opensearch:latest
```
Legg merke til passord `YLAgOm}rz#o6#Aq` (tilfeldig [generert](https://www.strongpasswordgenerator.org/), men må være "sterkt" ellers vil ikke OpenSearch starte).

For å kjøre tester og bygge appen lokalt må Docker (Colima kan brukes på Mac) kjøre og man er nødt til å sette disse
miljøvariablene:

**Mac:** For å kjøre tester og bygge appen lokalt må Docker (Colima kan brukes) kjøre og man er nødt til å sette disse miljøvariablene:
```
DOCKER_HOST=unix://${HOME}/.colima/default/docker.sock
TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock
TESTCONTAINERS_RYUK_DISABLED=true
```

For å kjøre lokalt med elastic search:

```
docker run -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" -e "plugins.security.disabled=true" -e "OPENSEARCH_INITIAL_ADMIN_PASSWORD=YLAgOm}rz#o6#Aq" --name opensearch -d opensearchproject/opensearch:latest
```
Legg merke til passord `YLAgOm}rz#o6#Aq` (tilfeldig [generert](https://www.strongpasswordgenerator.org/), men må være "sterkt" ellers vil ikke OpenSearch starte).

Applikasjonen er avhengig av en lokal PSQL-database. For mer informasjon se [egen dokumentasjon](../../docs/local_db.md).
```
1 change: 0 additions & 1 deletion apps/dolly-backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ dependencies {
implementation 'no.nav.testnav.libs:data-transfer-objects'
implementation 'no.nav.testnav.libs:data-transfer-search-objects'
implementation 'no.nav.testnav.libs:reactive-core'
implementation 'no.nav.testnav.libs:vault'

implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:$versions.springdoc"
implementation "io.swagger.core.v3:swagger-annotations-jakarta:$versions.swagger"
Expand Down
1 change: 0 additions & 1 deletion apps/dolly-backend/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ includeBuild '../../libs/security-core'
includeBuild '../../libs/servlet-core'
includeBuild '../../libs/servlet-insecure-security'
includeBuild '../../libs/servlet-security'
includeBuild '../../libs/vault'

develocity {
buildScan {
Expand Down

This file was deleted.

14 changes: 2 additions & 12 deletions apps/dolly-backend/src/main/resources/application-local.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
spring:
cache:
type: none
cloud:
vault:
host: vault.adeo.no
port: 443
fail-fast: true
connection-timeout: 15000
read-timeout: 30000
generic:
enabled: false
datasource:
url: jdbc:postgresql://localhost:5432/dolly-test
driver-class-name: org.postgresql.Driver
username: postgres
url: jdbc:postgresql://localhost:5432/db-dolly-backend
username: ${NAV_USERNAME}

management:
endpoints:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ sts:
spring:
cloud:
vault:
token: test
enabled: false
datasource:
type: org.springframework.jdbc.datasource.SimpleDriverDataSource
Expand Down
37 changes: 37 additions & 0 deletions apps/dolly-db/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
6 changes: 6 additions & 0 deletions apps/dolly-db/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM ghcr.io/navikt/baseimages/temurin:21
LABEL maintainer="Team Dolly"

COPY build/libs/app.jar /app/app.jar

EXPOSE 8080
7 changes: 7 additions & 0 deletions apps/dolly-db/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
A dummy application deployed as multiple NAIS apps in order to provide easy access to the NAIS managed databases.

Originally contains one `RedirectToHealthController`, to provide NAIS with a minimum living application.

No need to run `DatabaseApplication` locally, but in any case:
* Use Spring profile `local`, for human readable log output.
* Swagger at http://localhost:8080/swagger, such as it is.
10 changes: 10 additions & 0 deletions apps/dolly-db/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
id "dolly-apps"
}

dependencies {
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:$versions.springdoc"
implementation "org.springframework.boot:spring-boot-starter-web"

testImplementation "org.testcontainers:junit-jupiter"
}
31 changes: 31 additions & 0 deletions apps/dolly-db/db.dolly-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: "nais.io/v1alpha1"
kind: "Application"
metadata:
name: "db-dolly-backend"
namespace: "dolly"
labels:
"team": "dolly"
spec:
gcp:
sqlInstances:
- type: POSTGRES_15
tier: db-custom-2-7680
databases:
- name: db-dolly-backend
image: "{{image}}"
ingresses:
- "https://dolly-db.intern.dev.nav.no"
liveness:
path: "/internal/health/liveness"
observability:
autoInstrumentation:
enabled: true
runtime: java
prometheus:
enabled: true
path: "/internal/prometheus"
readiness:
path: "/internal/health/readiness"
replicas:
min: 1
max: 1
29 changes: 29 additions & 0 deletions apps/dolly-db/db.organisasjon-forvalter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: "nais.io/v1alpha1"
kind: "Application"
metadata:
name: "db-organisasjon-forvalter"
namespace: "dolly"
labels:
"team": "dolly"
spec:
gcp:
sqlInstances:
- type: POSTGRES_15
tier: db-custom-1-3840
databases:
- name: db-organisasjon-forvalter
image: "{{image}}"
liveness:
path: "/internal/health/liveness"
observability:
autoInstrumentation:
enabled: true
runtime: java
prometheus:
enabled: true
path: "/internal/prometheus"
readiness:
path: "/internal/health/readiness"
replicas:
min: 1
max: 1
29 changes: 29 additions & 0 deletions apps/dolly-db/db.pdl-forvalter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: "nais.io/v1alpha1"
kind: "Application"
metadata:
name: "db-pdl-forvalter"
namespace: "dolly"
labels:
"team": "dolly"
spec:
gcp:
sqlInstances:
- type: POSTGRES_15
tier: db-custom-1-3840
databases:
- name: db-pdl-forvalter
image: "{{image}}"
liveness:
path: "/internal/health/liveness"
observability:
autoInstrumentation:
enabled: true
runtime: java
prometheus:
enabled: true
path: "/internal/prometheus"
readiness:
path: "/internal/health/readiness"
replicas:
min: 1
max: 1
Binary file added apps/dolly-db/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions apps/dolly-db/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit c6fe59d

Please sign in to comment.