This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (83 loc) · 3.14 KB
/
deploy-revision-dispatch.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: Deploy revision
on:
repository_dispatch:
types: deploy-revision
env:
COMMIT_SHA: ${{ github.event.client_payload.commit }}
jobs:
setup:
runs-on: ubuntu-latest
outputs:
docker_image: ${{ env.IMAGE_FULL_NAME }}
should_build_image: ${{ env.SHOULD_BUILD_IMAGE }}
steps:
- name: 'Sjekk ut ønsket commit'
uses: 'actions/checkout@v3'
with:
ref: ${{ env.COMMIT_SHA }}
- name: 'Utled navn på docker-image basert på siste commit'
run: |
APP_NAME=$(echo $GITHUB_REPOSITORY | rev | cut -f1 -d"/" | rev )
TAG_NAME="$(git log -1 --pretty='%ad' --date=format:'%Y%m%d%H%M%S')-$(git log -1 --pretty='%h')"
IMAGE_BASE="ghcr.io/$GITHUB_REPOSITORY/$APP_NAME"
echo "IMAGE_FULL_NAME=$IMAGE_BASE:$TAG_NAME" >> $GITHUB_ENV
echo "IMAGE_TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
- name: 'Sjekker om docker-image eksisterer fra før av'
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_REPOSITORY --password-stdin
RESULT=$(docker manifest inspect ${{ env.IMAGE_FULL_NAME }} > /dev/null 2> /dev/null ; echo $?)
echo "SHOULD_BUILD_IMAGE=$([[ $RESULT == 0 ]] && echo 'false' || echo 'true' )" >> $GITHUB_ENV
build-docker-image:
needs: setup
if: needs.setup.outputs.should_build_image == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.COMMIT_SHA }}
- name: 'Setup java'
uses: actions/setup-java@v1
with:
java-version: '17.x'
- name: 'Finn cache-variabler'
uses: navikt/pb-common-gh-actions/cache-prep@v2
- name: 'Sett opp cache'
uses: actions/cache@v2
with:
path: |
${{ env.CACHE_PATHS }}
key: ${{ runner.os }}${{ env.CACHE_KEY_NAMESPACE }}${{ hashFiles(env.CACHE_KEY_HASHED_PATH) }}
- name: 'Bygg prosjekt'
uses: navikt/pb-common-gh-actions/build@v2
with:
SKIP_TESTS: "true"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: 'Bygg, tag og push Docker image'
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_REPOSITORY --password-stdin
docker build --tag ${{ needs.setup.outputs.docker_image }} .
docker push ${{ needs.setup.outputs.docker_image }}
deploy:
needs:
- setup
- build-docker-image
runs-on: ubuntu-latest
if: |
always() &&
( needs.build-docker-image.result == 'success' || needs.build-docker-image.result == 'skipped' )
strategy:
matrix:
cluster: ${{ github.event.client_payload.clusters }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ env.COMMIT_SHA }}
- name: 'Deployer til ${{ matrix.CLUSTER }}'
uses: 'nais/deploy/actions/deploy@v1'
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: ${{ matrix.CLUSTER }}
RESOURCE: ./nais/${{ matrix.CLUSTER }}/nais.yaml
VAR: version=${{ needs.setup.outputs.docker_image }}
PRINT_PAYLOAD: true
REF: ${{ env.COMMIT_SHA }}