Skip to content

Commit 7ef1fa3

Browse files
committed
Add NAIS deployment
1 parent 1df26aa commit 7ef1fa3

12 files changed

+583
-195
lines changed

.github/labels.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
# Labels names are important as they are used by Release Drafter to decide
3+
# regarding where to record them in changelog or if to skip them.
4+
#
5+
# The repository labels will be automatically configured using this file and
6+
# the GitHub Action https://github.com/marketplace/actions/github-labeler.
7+
- name: breaking
8+
description: Breaking Changes
9+
color: bfd4f2
10+
- name: bug
11+
description: Something isn't working
12+
color: d73a4a
13+
- name: build
14+
description: Build System and Dependencies
15+
color: bfdadc
16+
- name: ci
17+
description: Continuous Integration
18+
color: 4a97d6
19+
- name: dependencies
20+
description: Pull requests that update a dependency file
21+
color: 0366d6
22+
- name: documentation
23+
description: Improvements or additions to documentation
24+
color: 0075ca
25+
- name: duplicate
26+
description: This issue or pull request already exists
27+
color: cfd3d7
28+
- name: enhancement
29+
description: New feature or request
30+
color: a2eeef
31+
- name: github_actions
32+
description: Pull requests that update Github_actions code
33+
color: "000000"
34+
- name: good first issue
35+
description: Good for newcomers
36+
color: 7057ff
37+
- name: help wanted
38+
description: Extra attention is needed
39+
color: 008672
40+
- name: invalid
41+
description: This doesn't seem right
42+
color: e4e669
43+
- name: performance
44+
description: Performance
45+
color: "016175"
46+
- name: python
47+
description: Pull requests that update Python code
48+
color: 2b67c6
49+
- name: question
50+
description: Further information is requested
51+
color: d876e3
52+
- name: refactoring
53+
description: Refactoring
54+
color: ef67c4
55+
- name: removal
56+
description: Removals and Deprecations
57+
color: 9ae7ea
58+
- name: style
59+
description: Style
60+
color: c120e5
61+
- name: testing
62+
description: Testing
63+
color: b1fc6f
64+
- name: wontfix
65+
description: This will not be worked on
66+
color: ffffff

.github/release-drafter.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
categories:
2+
- title: ":boom: Breaking Changes"
3+
label: "breaking"
4+
- title: ":rocket: Features"
5+
label: "enhancement"
6+
- title: ":fire: Removals and Deprecations"
7+
label: "removal"
8+
- title: ":beetle: Fixes"
9+
label: "bug"
10+
- title: ":racehorse: Performance"
11+
label: "performance"
12+
- title: ":rotating_light: Testing"
13+
label: "testing"
14+
- title: ":construction_worker: Continuous Integration"
15+
label: "ci"
16+
- title: ":books: Documentation"
17+
label: "documentation"
18+
- title: ":hammer: Refactoring"
19+
label: "refactoring"
20+
- title: ":lipstick: Style"
21+
label: "style"
22+
- title: ":package: Dependencies"
23+
labels:
24+
- "dependencies"
25+
- "build"
26+
27+
autolabeler:
28+
- label: 'documentation'
29+
branch:
30+
- '/docs{0,1}\/.+/'
31+
- label: 'bug'
32+
branch:
33+
- '/fix\/.+/'
34+
title:
35+
- '/fix/i'
36+
- label: 'enhancement'
37+
branch:
38+
- '/feat\/.+/'
39+
body:
40+
- '/JIRA-[0-9]{1,4}/'
41+
- label: 'refactoring'
42+
branch:
43+
- '/refactor\/.+/'
44+
title:
45+
- '/^refactor/i'
46+
- label: 'testing'
47+
branch:
48+
- '/test\/.+/'
49+
- label: 'breaking'
50+
title:
51+
- '/breaking change/i'
52+
- label: 'ci'
53+
files:
54+
- '.github/*'
55+
56+
template: |
57+
## Changes
58+
59+
$CHANGES

.github/workflows/build-deploy.yml

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
## This workflow is either triggered when:
2+
on:
3+
release:
4+
types: [ published ]
5+
push:
6+
branches:
7+
- master
8+
paths-ignore:
9+
- "**/*.md"
10+
- "Makefile"
11+
- ".mvn"
12+
- ".gitignore"
13+
14+
env:
15+
REGISTRY: europe-north1-docker.pkg.dev/artifact-registry-5n/dapla-stat-docker/maskinporten-guardian
16+
IMAGE: maskinporten-guardian
17+
18+
jobs:
19+
setup-build-push-deploy:
20+
name: Set up variables to build/push or deploy
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
id-token: write
25+
26+
outputs:
27+
nais-image: ${{steps.image-tag.outputs.nais_image}}
28+
nais-cluster: ${{steps.nais-deploy-vars.outputs.cluster}}
29+
nais-config-path: ${{steps.nais-deploy-vars.outputs.nais_config_path}}
30+
tags: ${{steps.image-tag.outputs.tags}}
31+
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- name: Generate image tags
36+
id: image-tag
37+
run: |
38+
if [ ${{ github.event_name }} == "release" ]; then
39+
RELEASE_VERSION=${GITHUB_REF#refs/*/}
40+
semver=${REGISTRY}/${IMAGE}:v${RELEASE_VERSION}
41+
major_minor_version=${REGISTRY}/${IMAGE}:v$(echo "$RELEASE_VERSION" | cut -d'.' -f1-2)
42+
major_version=${REGISTRY}/${IMAGE}:v$(echo "$RELEASE_VERSION" | cut -d'.' -f1)
43+
latest=${REGISTRY}/${IMAGE}:latest
44+
45+
## NAIS image is the image used by NAIS for deployment
46+
echo "nais_image=${semver}" >> "$GITHUB_OUTPUT"
47+
48+
tags=${latest},${semver},${major_minor_version},${major_version}
49+
echo "tags=${tags}" >> "$GITHUB_OUTPUT"
50+
else
51+
git_sha_short="$(git rev-parse --short ${{github.sha}})"
52+
current_sha_tag=${REGISTRY}/${IMAGE}:${{github.event.repository.default_branch}}-$git_sha_short
53+
latest=${REGISTRY}/${IMAGE}:latest
54+
55+
## NAIS image is the image used by NAIS for deployment
56+
echo "nais_image=${current_sha_tag}" >> "$GITHUB_OUTPUT"
57+
tags=${latest},${current_sha_tag}
58+
echo "tags=${tags}" >> "$GITHUB_OUTPUT"
59+
fi
60+
61+
- name: Generate NAIS deploy variables
62+
id: nais-deploy-vars
63+
run: |
64+
if [[ ${{github.event_name}} == "release" ]]; then
65+
echo "cluster=prod" >> "$GITHUB_OUTPUT"
66+
echo "nais_config_path=.nais/prod.yaml" >> "$GITHUB_OUTPUT"
67+
else
68+
echo "cluster=test" >> "$GITHUB_OUTPUT"
69+
echo "nais_config_path=.nais/test.yaml" >> "$GITHUB_OUTPUT"
70+
fi
71+
72+
build-push:
73+
name: Build and push to registries
74+
# If triggering event is release, the commits on 'master' should build
75+
# the image
76+
needs: setup-build-push-deploy
77+
runs-on: ubuntu-latest
78+
permissions:
79+
contents: read
80+
id-token: write
81+
82+
steps:
83+
- uses: actions/checkout@v4
84+
85+
- name: Set up JDK 21
86+
uses: actions/setup-java@v4
87+
with:
88+
java-version: 21
89+
distribution: temurin
90+
cache: maven
91+
92+
- name: Authenticate to Google Cloud
93+
id: auth
94+
uses: google-github-actions/auth@v2
95+
with:
96+
workload_identity_provider: "projects/848539402404/locations/global/workloadIdentityPools/gh-actions/providers/gh-actions"
97+
service_account: "gh-actions-dapla-stat@artifact-registry-5n.iam.gserviceaccount.com"
98+
token_format: access_token
99+
100+
- name: Set up Docker Buildx
101+
id: buildx
102+
uses: docker/setup-buildx-action@v3
103+
104+
- name: Login to Artifact Registry
105+
uses: docker/login-action@v3
106+
with:
107+
registry: ${{ env.REGISTRY }}
108+
username: "oauth2accesstoken"
109+
password: "${{ steps.auth.outputs.access_token }}"
110+
111+
- name: Maven build and install
112+
run: |
113+
if [[ ${{github.event_name}} == "push" ]]; then
114+
mvn --batch-mode -P artifact-registry,github deploy
115+
else
116+
mvn --batch-mode clean install
117+
fi
118+
119+
- name: Docker meta
120+
id: docker_metadata
121+
uses: docker/metadata-action@v5
122+
with:
123+
images: ${{ env.REGISTRY }}/${{ env.IMAGE }}
124+
125+
- name: Build and push docker image to Artifact Registry
126+
id: docker_build
127+
uses: docker/build-push-action@v5
128+
with:
129+
context: .
130+
file: Dockerfile
131+
push: true
132+
tags: ${{ needs.setup-build-push-deploy.outputs.tags }}
133+
labels: ${{ steps.docker_metadata.outputs.labels }}
134+
135+
deploy:
136+
name: Deploy to NAIS
137+
needs: [build-push, setup-build-push-deploy]
138+
uses: ./.github/workflows/deploy-to-nais.yml
139+
with:
140+
image: ${{needs.setup-build-push-deploy.outputs.nais-image}}
141+
cluster: ${{needs.setup-build-push-deploy.outputs.nais-cluster}}
142+
nais-config-path: ${{needs.setup-build-push-deploy.outputs.nais-config-path}}

.github/workflows/build-test.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- master
5+
paths-ignore:
6+
- "**/*.md"
7+
- "Makefile"
8+
- ".mvn"
9+
- ".gitignore"
10+
11+
env:
12+
REGISTRY: europe-north1-docker.pkg.dev/artifact-registry-5n/dapla-stat-docker
13+
14+
jobs:
15+
build-test:
16+
name: Build and test with Maven
17+
if: ${{github.event_name == 'pull_request'}}
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
id-token: write
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Set up JDK 21
27+
uses: actions/setup-java@v4
28+
with:
29+
java-version: 21
30+
distribution: temurin
31+
cache: maven
32+
33+
- name: Authenticate to Google Cloud
34+
id: auth
35+
uses: google-github-actions/auth@v2
36+
with:
37+
workload_identity_provider: "projects/848539402404/locations/global/workloadIdentityPools/gh-actions/providers/gh-actions"
38+
service_account: "gh-actions-dapla-stat@artifact-registry-5n.iam.gserviceaccount.com"
39+
token_format: access_token
40+
41+
- name: Login to Artifact Registry
42+
uses: docker/login-action@v3
43+
with:
44+
registry: ${{ env.REGISTRY }}
45+
username: "oauth2accesstoken"
46+
password: "${{ steps.auth.outputs.access_token }}"
47+
48+
- name: Maven build and install
49+
run: mvn --batch-mode clean install

.github/workflows/deploy-to-nais.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Deploy to NAIS
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
image:
7+
description: Image on the form <REGISTRY>/<REPOSITORY>/<IMAGE_NAME>
8+
required: true
9+
type: string
10+
cluster:
11+
description: NAIS cluster environment
12+
required: true
13+
type: string
14+
nais-config-path:
15+
description: Path to the NAIS configuration file
16+
required: true
17+
type: string
18+
19+
jobs:
20+
deploy:
21+
name: Deploy to NAIS cluster
22+
runs-on: ubuntu-latest
23+
permissions:
24+
contents: "read"
25+
id-token: "write"
26+
steps:
27+
- uses: actions/checkout@v4
28+
- uses: nais/deploy/actions/deploy@v2
29+
env:
30+
CLUSTER: ${{ inputs.cluster }}
31+
RESOURCE: ${{ inputs.nais-config-path }}
32+
VAR: image=${{ inputs.image }}
33+
DEPLOY_SERVER: deploy.ssb.cloud.nais.io:443

.github/workflows/labeler.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Labeler
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
labeler:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Check out the repository
13+
uses: actions/checkout@v3
14+
15+
# Reads labels from .github/labels.yml
16+
- name: Run Labeler
17+
uses: crazy-max/ghaction-github-labeler@v4
18+
with:
19+
skip-delete: true

0 commit comments

Comments
 (0)