Skip to content

Commit c7e8e33

Browse files
authored
Merge pull request #196 from statisticsnorway/feat/deploy-to-nais
Deploy to Nais
2 parents 094285b + d1cfde2 commit c7e8e33

File tree

6 files changed

+128
-1
lines changed

6 files changed

+128
-1
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: App build and deploy
2+
3+
on:
4+
release:
5+
types: [published]
6+
push:
7+
branches:
8+
- master
9+
10+
env:
11+
REGISTRY: europe-north1-docker.pkg.dev/${{ secrets.NAIS_MANAGEMENT_PROJECT_ID }}/dapla-metadata
12+
DOCKER_IMAGE: europe-north1-docker.pkg.dev/${{ secrets.NAIS_MANAGEMENT_PROJECT_ID }}/dapla-metadata/klass-api:${{ github.sha }}
13+
14+
jobs:
15+
docker-build:
16+
name: Docker build
17+
permissions:
18+
contents: "read"
19+
id-token: "write"
20+
runs-on: ubuntu-latest
21+
outputs:
22+
nais_config_path: ${{ steps.nais-deploy-vars.outputs.nais_config_path }}
23+
nais_cluster: ${{ steps.nais-deploy-vars.outputs.nais_cluster }}
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Build with Maven
30+
run: mvn --batch-mode install -pl '!:klass-forvaltning' -DskipTests
31+
32+
- name: Build and push
33+
uses: nais/docker-build-push@v0
34+
id: docker-build-push
35+
with:
36+
team: dapla-metadata
37+
dockerfile: klass-api/Dockerfile
38+
docker_context: klass-api
39+
40+
- name: Generate NAIS deploy variables
41+
id: nais-deploy-vars
42+
run: |
43+
if [[ ${{ github.event_name }} == "release" ]]; then
44+
echo "nais_cluster=prod" >> "$GITHUB_OUTPUT"
45+
echo "nais_config_path=.nais/prod/nais.yaml" >> "$GITHUB_OUTPUT"
46+
else
47+
echo "nais_cluster=test" >> "$GITHUB_OUTPUT"
48+
echo "nais_config_path=.nais/test/nais.yaml" >> "$GITHUB_OUTPUT"
49+
fi
50+
51+
- uses: nais/deploy/actions/deploy@v2
52+
env:
53+
CLUSTER: ${{ steps.nais-deploy-vars.outputs.nais_cluster }}
54+
RESOURCE: ${{ steps.nais-deploy-vars.outputs.nais_config_path }}
55+
VAR: image=${{ steps.docker-build-push.outputs.image }}
56+
DEPLOY_SERVER: deploy.ssb.cloud.nais.io:443
57+
WORKLOAD_IMAGE: ${{ steps.docker-build-push.outputs.image }}
58+
TELEMETRY: ${{ steps.docker-build-push.outputs.telemetry }}

.nais/test/nais.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Deploy config for the test cluster
2+
apiVersion: nais.io/v1alpha1
3+
kind: Application
4+
metadata:
5+
name: klass-api
6+
namespace: dapla-metadata
7+
labels:
8+
team: dapla-metadata
9+
spec:
10+
image: "{{ image }}" # Injected from the GitHub Action
11+
port: 8080
12+
13+
ingresses:
14+
- https://klass-api.intern.test.ssb.no
15+
16+
accessPolicy:
17+
18+
replicas:
19+
min: 1
20+
max: 1
21+
resources:
22+
requests:
23+
cpu: 20m
24+
memory: 400Mi
25+
26+
gcp:
27+
sqlInstances:
28+
- type: POSTGRES_17
29+
tier: db-f1-micro
30+
databases:
31+
- name: klass-db
32+
33+
prometheus:
34+
enabled: true
35+
path: /prometheus
36+
port: "8090"
37+
38+
liveness:
39+
path: /actuator/health/liveness
40+
port: 8080
41+
initialDelay: 60
42+
readiness:
43+
path: /actuator/health/readiness
44+
port: 8080
45+
initialDelay: 60
46+
startup:
47+
path: /actuator/health/liveness
48+
port: 8080
49+
initialDelay: 60

klass-api/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM eclipse-temurin:17-jre
2+
WORKDIR /app
3+
COPY target/*.war app.war
4+
ENTRYPOINT ["java", "-jar", "app.war"]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# custom properties used when "postgres" Profile is used
2+
3+
spring.datasource.url=${NAIS_DATABASE_KLASS_API_KLASS_DB_JDBC_URL}
4+
spring.datasource.username=${NAIS_DATABASE_KLASS_API_KLASS_DB_USERNAME}
5+
spring.datasource.password=${NAIS_DATABASE_KLASS_API_KLASS_DB_PASSWORD}
6+
spring.datasource.driverclassName=org.postgresql.Driver
7+
8+
spring.jpa.hibernate.ddl-auto=validate
9+

klass-api/src/main/resources/application.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ info.build.version=@project.version@
77
# Profiles for production
88
# production = disables test users
99
# mariadb = use remote mariaDB database
10+
# postgres = use remote postgres database
1011
# remote-solr = use remote Solr server (make sure klass.env.search.solr.url is correct)
1112
# skip-indexing = skips indexing classifications for search at startup, (useful when running multiple nodes)
1213
#
@@ -23,7 +24,7 @@ info.build.version=@project.version@
2324
#-----------------------
2425

2526
# Dev. self contained
26-
spring.profiles.active=api, h2, small-import, skip-indexing, embedded-solr
27+
spring.profiles.active=api, h2-inmemory , small-import, skip-indexing, embedded-solr
2728

2829
# Dev. with external dependencies (db and solr)
2930
#spring.profiles.active=api,mariadb,remote-solr,skip-indexing

klass-shared/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<klass.doc.env.url />
2525
<klass.doc.env.port />
2626

27+
<postgresql.version>42.7.5</postgresql.version>
2728
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2829
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2930
<findbugs-version>3.0.5</findbugs-version>
@@ -113,6 +114,11 @@
113114
<groupId>org.mariadb.jdbc</groupId>
114115
<artifactId>mariadb-java-client</artifactId>
115116
</dependency>
117+
<dependency>
118+
<groupId>org.postgresql</groupId>
119+
<artifactId>postgresql</artifactId>
120+
<version>${postgresql.version}</version>
121+
</dependency>
116122
<dependency>
117123
<!--java based ldap server for testing-->
118124
<groupId>org.apache.directory.server</groupId>

0 commit comments

Comments
 (0)