Skip to content

Commit bd33815

Browse files
committed
Update on_deploy.yml
1 parent ada574c commit bd33815

File tree

1 file changed

+91
-15
lines changed

1 file changed

+91
-15
lines changed

.github/workflows/on_deploy.yml

Lines changed: 91 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,103 @@ on:
55
push:
66
branches:
77
- main
8+
9+
env:
10+
REGISTRY: europe-north1-docker.pkg.dev/artifact-registry-5n/kostra-docker
11+
IMAGE: kostra-kontrollprogram
12+
813
jobs:
9-
build_and_deploy:
10-
name: Build, push and deploy
11-
runs-on: ubuntu-latest
14+
docker_build:
15+
name: Create Docker image
16+
environment: build
1217
permissions:
13-
contents: read
18+
contents: write
1419
id-token: write
20+
runs-on: ubuntu-24.04
21+
outputs:
22+
image: ${{ env.DOCKER_IMAGE }}
1523
steps:
16-
- uses: actions/checkout@v4
17-
- name: Build and push image and SBOM to OCI registry
18-
uses: nais/docker-build-push@v0
19-
id: docker-build-push
24+
- name: Create image tag
25+
run: |
26+
echo "TAG=$(date +'%Y%m%d')-${{github.run_number}}" >> $GITHUB_ENV
27+
28+
- name: Set docker image env var
29+
run: |
30+
echo "DOCKER_IMAGE=${REGISTRY}/${IMAGE}:${TAG}" >> $GITHUB_ENV
31+
32+
- name: Set docker image env var
33+
run: |
34+
echo "DOCKER_IMAGE=${REGISTRY}/${IMAGE}:${TAG}" >> $GITHUB_ENV
35+
36+
- name: Echo image tag
37+
run: echo $DOCKER_IMAGE
38+
39+
- name: Check out code
40+
uses: actions/checkout@v4
41+
42+
- name: Set up JDK 21
43+
uses: actions/setup-java@v4
44+
with:
45+
java-version: '21'
46+
distribution: 'temurin'
47+
48+
- name: Set up gradle
49+
uses: gradle/actions/setup-gradle@v4
2050
with:
21-
team: ${{ vars.NAIS_TEAM }}
22-
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
23-
project_id: ${{ secrets.NAIS_MANAGEMENT_PROJECT_ID }}
24-
- name: Deploy to Nais
51+
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
52+
53+
- name: Authenticate to Google Cloud
54+
id: "auth"
55+
uses: google-github-actions/auth@v2.1.7
56+
with:
57+
workload_identity_provider: "projects/${{ vars.GAR_PROJECT_NUMBER }}/locations/global/workloadIdentityPools/gh-actions/providers/gh-actions"
58+
service_account: "gh-actions-kostra@${{ vars.GAR_PROJECT_ID }}.iam.gserviceaccount.com"
59+
token_format: "access_token"
60+
61+
- name: Login to registry
62+
uses: docker/login-action@v3
63+
with:
64+
registry: ${{ env.REGISTRY }}
65+
username: "oauth2accesstoken"
66+
password: "${{ steps.auth.outputs.access_token }}"
67+
68+
- name: Build and push Docker image to Google Artifact Registry
69+
run: >
70+
./gradlew
71+
jib
72+
--image=${{ env.DOCKER_IMAGE }}
73+
--daemon --parallel --build-cache
74+
75+
test_deploy:
76+
name: Deploy to NAIS test
77+
environment: test
78+
runs-on: ubuntu-24.04
79+
needs: docker_build
80+
permissions:
81+
contents: write
82+
id-token: write
83+
steps:
84+
- name: Recreate image tag
85+
run: |
86+
echo "TAG=$(date +'%Y%m%d')-${{github.run_number}}" >> $GITHUB_ENV
87+
88+
- name: Reset docker image env var
89+
run: |
90+
echo "DOCKER_IMAGE=${REGISTRY}/${IMAGE}:${TAG}" >> $GITHUB_ENV
91+
92+
- name: Echo image tag
93+
run: echo $DOCKER_IMAGE
94+
95+
- name: Check out code
96+
uses: actions/checkout@v4
97+
98+
- name: Echo image tag
99+
run: echo ${{ needs.docker_build.outputs.image }}
100+
101+
- name: Deploy to NAIS Test
25102
uses: nais/deploy/actions/deploy@v2
26103
env:
27104
CLUSTER: test
28105
RESOURCE: .nais/test.yaml
29-
VAR: image=${{ steps.docker-build-push.outputs.image }}
30-
TELEMETRY: ${{ steps.docker-build-push.outputs.telemetry }}
31-
DEPLOY_SERVER: deploy.ssb.cloud.nais.io:443
106+
VAR: image=${{ env.DOCKER_IMAGE }}
107+
DEPLOY_SERVER: deploy.ssb.cloud.nais.io:443

0 commit comments

Comments
 (0)