Skip to content

Commit df46ff0

Browse files
author
Personbruker Workflow Authority
committed
2 file(s) updated by navikt/pb-workflow-authority, version 7c372ae
1 parent 0f1492e commit df46ff0

File tree

2 files changed

+50
-94
lines changed

2 files changed

+50
-94
lines changed

.github/workflows/deploy-branch-gh-cli.yaml

Lines changed: 26 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,81 +12,45 @@ permissions:
1212
packages: write
1313

1414
jobs:
15-
setup:
15+
build:
16+
name: Build and push docker image
1617
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
id-token: write
1721
outputs:
18-
docker_image: ${{ env.IMAGE_FULL_NAME }}
19-
should_build_image: ${{ env.SHOULD_BUILD_IMAGE }}
22+
image: ${{ steps.docker-build-push.outputs.image }}
2023
steps:
24+
- uses: actions/checkout@v4
2125

22-
- name: 'Sjekk ut ønsket commit'
23-
uses: 'actions/checkout@v3'
24-
25-
- name: 'Utled navn på docker-image basert på siste commit'
26-
run: |
27-
APP_NAME=$(echo $GITHUB_REPOSITORY | rev | cut -f1 -d"/" | rev )
28-
TAG_NAME="$(git log -1 --pretty='%ad' --date=format:'%Y%m%d%H%M%S')-$(git log -1 --pretty='%h')"
29-
IMAGE_BASE="ghcr.io/$GITHUB_REPOSITORY/$APP_NAME"
30-
echo "IMAGE_FULL_NAME=$IMAGE_BASE:$TAG_NAME" >> $GITHUB_ENV
31-
echo "IMAGE_TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
32-
33-
- name: 'Sjekker om docker-image eksisterer fra før av'
34-
run: |
35-
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_REPOSITORY --password-stdin
36-
RESULT=$(docker manifest inspect ${{ env.IMAGE_FULL_NAME }} > /dev/null 2> /dev/null ; echo $?)
37-
echo "SHOULD_BUILD_IMAGE=$([[ $RESULT == 0 ]] && echo 'false' || echo 'true' )" >> $GITHUB_ENV
38-
39-
build-docker-image:
40-
needs: setup
41-
if: needs.setup.outputs.should_build_image == 'true'
42-
runs-on: ubuntu-latest
43-
steps:
44-
- uses: actions/checkout@v3
45-
46-
- name: 'Setup java'
47-
uses: actions/setup-java@v1
26+
- uses: actions/setup-java@v3
4827
with:
49-
java-version: '17.x'
50-
51-
- name: 'Finn cache-variabler'
52-
uses: navikt/pb-common-gh-actions/cache-prep@v2
28+
java-version: 17
29+
distribution: 'temurin'
5330

54-
- name: 'Sett opp cache'
55-
uses: actions/cache@v2
56-
with:
57-
path: |
58-
${{ env.CACHE_PATHS }}
59-
key: ${{ runner.os }}${{ env.CACHE_KEY_NAMESPACE }}${{ hashFiles(env.CACHE_KEY_HASHED_PATH) }}
31+
- name: Gradle build
32+
run: ./gradlew assemble
6033

61-
- name: 'Bygg prosjekt'
62-
uses: navikt/pb-common-gh-actions/build@v2
34+
- name: Build and push image to GAR
35+
uses: nais/docker-build-push@v0
36+
id: docker-build-push
6337
with:
64-
SKIP_TESTS: "true"
65-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66-
67-
- name: 'Bygg, tag og push Docker image'
68-
run: |
69-
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_REPOSITORY --password-stdin
70-
docker build --tag ${{ needs.setup.outputs.docker_image }} .
71-
docker push ${{ needs.setup.outputs.docker_image }}
38+
team: min-side
39+
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
40+
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
7241

7342
deploy:
74-
needs:
75-
- setup
76-
- build-docker-image
43+
name: Deploy to NAIS
44+
needs: build
7745
runs-on: ubuntu-latest
78-
if: |
79-
always() &&
80-
( needs.build-docker-image.result == 'success' || needs.build-docker-image.result == 'skipped' )
46+
permissions:
47+
contents: read
48+
id-token: write
8149
steps:
82-
- uses: actions/checkout@v3
50+
- uses: actions/checkout@v4
8351

84-
- name: 'Deployer ${{ github.ref_name }} til ${{ inputs.cluster }}'
85-
uses: 'nais/deploy/actions/deploy@v1'
52+
- uses: nais/deploy/actions/deploy@v2
8653
env:
87-
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
8854
CLUSTER: ${{ inputs.cluster }}
8955
RESOURCE: ./nais/${{ inputs.cluster }}/nais.yaml
90-
VAR: version=${{ needs.setup.outputs.docker_image }}
91-
PRINT_PAYLOAD: true
92-
REF: ${{ github.sha }}
56+
VAR: version=${{ needs.build.outputs.image }}

.github/workflows/on-push-to-main.yaml

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: Bygg og publiser docker-image for main
33
on:
44
push:
55
branches:
6-
- master
76
- main
87
paths-ignore:
98
- .github/workflows/**
@@ -16,60 +15,53 @@ permissions:
1615

1716
jobs:
1817
build:
18+
name: Build and push docker image
1919
runs-on: ubuntu-latest
20+
permissions:
21+
contents: write
22+
id-token: write
2023
outputs:
21-
image: ${{ env.IMAGE }}
24+
image: ${{ steps.docker-build-push.outputs.image }}
2225
steps:
26+
- uses: actions/checkout@v4
2327

24-
- name: Sjekk ut koden
25-
uses: actions/checkout@v2
26-
27-
- name: Setup java
28-
uses: actions/setup-java@v1
29-
with:
30-
java-version: '17.x'
31-
32-
- name: Finn cache-variabler
33-
uses: navikt/pb-common-gh-actions/cache-prep@v2
34-
35-
- name: Sett opp cache
36-
uses: actions/cache@v2
28+
- uses: actions/setup-java@v3
3729
with:
38-
path: |
39-
${{ env.CACHE_PATHS }}
40-
key: ${{ runner.os }}${{ env.CACHE_KEY_NAMESPACE }}${{ hashFiles(env.CACHE_KEY_HASHED_PATH) }}
30+
java-version: 17
31+
distribution: 'temurin'
4132

42-
- name: Bygg prosjekt og kjør tester
43-
uses: navikt/pb-common-gh-actions/build@v2
44-
with:
45-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
- name: Gradle build
34+
run: ./gradlew build
4635

47-
- name: Bygg, tag og push Docker image
48-
uses: navikt/pb-common-gh-actions/docker-publish@v2
36+
- name: Build and push image to GAR
37+
uses: nais/docker-build-push@v0
38+
id: docker-build-push
4939
with:
50-
TAG_LATEST: "true"
51-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
team: min-side
41+
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
42+
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
5243

5344
deploy:
45+
name: Deploy to NAIS
5446
runs-on: ubuntu-latest
5547
needs: build
48+
permissions:
49+
contents: read
50+
id-token: write
5651
strategy:
5752
matrix:
5853
cluster: [dev-gcp, prod-gcp]
5954
steps:
6055
- name: Sjekk ut koden
61-
uses: actions/checkout@v2
56+
uses: actions/checkout@v4
6257

6358
- name: 'Sjekk om deploy til ${{ matrix.cluster }} er mulig'
6459
run: echo "DEPLOY_CONFIG_DEFINED=$([[ -f ./nais/${{ matrix.cluster }}/nais.yaml ]] && echo 'true' || echo 'false')" >> $GITHUB_ENV
6560

6661
- name: 'Deploy-er til ${{ matrix.cluster }}'
6762
if: env.DEPLOY_CONFIG_DEFINED == 'true'
68-
uses: 'nais/deploy/actions/deploy@v1'
63+
uses: nais/deploy/actions/deploy@v2
6964
env:
70-
REF: ${{ github.sha }}
71-
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
7265
CLUSTER: ${{ matrix.cluster }}
7366
RESOURCE: ./nais/${{ matrix.cluster }}/nais.yaml
74-
VAR: version=${{ needs.build.outputs.image }}
75-
PRINT_PAYLOAD: true
67+
VAR: version=${{ needs.build.outputs.image }}

0 commit comments

Comments
 (0)