8
8
- dev/**
9
9
10
10
env :
11
- DOCKER_REGISTRY : ghcr.io
12
- DOCKER_IMAGE_PREFIX : ${{ github.repository }}/im-
13
11
ORG_GRADLE_PROJECT_githubPassword : ${{ secrets.GITHUB_TOKEN }}
14
12
15
13
jobs :
73
71
runs-on : ubuntu-latest
74
72
permissions :
75
73
packages : write
74
+ id-token : write
76
75
needs : generate_vars
77
76
if : needs.generate_vars.outputs.is_matrix_empty == 'false'
78
77
strategy :
@@ -96,20 +95,29 @@ jobs:
96
95
with :
97
96
files : " apps/${{ matrix.project }}/build/libs/app.jar"
98
97
99
- - name : Create docker tag
100
- if : steps.app_jar.outputs.files_exists == 'true'
101
- run : |
102
- echo "IMAGE=$DOCKER_REGISTRY/${DOCKER_IMAGE_PREFIX}${{ matrix.project }}:${{ needs.generate_vars.outputs.short_sha }}" >> $GITHUB_ENV
103
-
104
- - name : Build docker image
105
- if : steps.app_jar.outputs.files_exists == 'true'
106
- run : docker build apps/${{ matrix.project }} --pull -t $IMAGE -f Dockerfile
107
-
108
- - name : Push docker image
98
+ - name : build docker image
109
99
if : steps.app_jar.outputs.files_exists == 'true'
100
+ uses : nais/docker-build-push@v0
101
+ id : docker-build-push
102
+ with :
103
+ team : helsearbeidsgiver
104
+ image_suffix : im-${{ matrix.project }}
105
+ tag : ${{ needs.generate_vars.outputs.short_sha }}
106
+ dockerfile : Dockerfile
107
+ docker_context : apps/${{ matrix.project }}
108
+
109
+ - name : lag build fil
110
+ if : ${{ always() }}
110
111
run : |
111
- echo ${{ secrets.GITHUB_TOKEN }} | docker login --username $GITHUB_REPOSITORY --password-stdin https://$DOCKER_REGISTRY
112
- docker push $IMAGE
112
+ echo ${{ steps.docker-build-push.outputs.image }} > "${{ matrix.project }}_build_${{ steps.docker-build-push.outcome }}.txt"
113
+ - name : laste opp build-fil
114
+ if : ${{ always() }}
115
+ uses : actions/upload-artifact@v4
116
+ with :
117
+ overwrite : true
118
+ retention-days : 1
119
+ name : " ${{ matrix.project }}_build_result"
120
+ path : " ${{ matrix.project }}_build_${{ steps.docker-build-push.outcome }}.txt"
113
121
114
122
deploy :
115
123
runs-on : ubuntu-latest
@@ -123,37 +131,44 @@ jobs:
123
131
concurrency :
124
132
group : deploy-dev-${{ matrix.project }}
125
133
steps :
126
- - name : Check if docker image exists
127
- run : |
128
- LAYERS=$(curl -X GET https://$DOCKER_REGISTRY/${DOCKER_IMAGE_PREFIX}${{ matrix.project }}/manifests/${{ needs.generate_vars.outputs.short_sha }} -u $GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }} | jq '.layers')
129
- if [ "$LAYERS" == 'null' ]; then
130
- echo "IMAGE_EXISTS=false" >> $GITHUB_ENV
131
- else
132
- echo "IMAGE_EXISTS=true" >> $GITHUB_ENV
133
- fi
134
-
135
- - name : Fetch sources
136
- if : env.IMAGE_EXISTS == 'true'
137
- uses : actions/checkout@v4
138
-
139
134
- name : Determine app configuration file
140
- if : env.IMAGE_EXISTS == 'true'
141
135
run : |
142
136
CONFIG_FILE="config/${{ matrix.project }}/${{ matrix.cluster }}.yml"
143
137
echo "VARS=$CONFIG_FILE" >> $GITHUB_ENV # VARS-variable is used by nais/deploy/actions/deploy
144
138
145
139
- name : Confirm app configuration file existence
146
140
id : confirm_config_file
147
- if : env.IMAGE_EXISTS == 'true'
148
141
uses : andstor/file-existence-action@v3
149
142
with :
150
143
files : " ${{ env.VARS }}"
151
144
145
+ - name : Fetch sources
146
+ uses : actions/checkout@v4
147
+ - name : create env vars
148
+ run : |
149
+ # VARS og IMAGE er miljøvariabler som leses automatisk av nais/deploy/actions/deploy
150
+ VARS_FILE="config/${{ matrix.project }}/${{ matrix.cluster }}.yml"
151
+ echo "VARS=$VARS_FILE" >> $GITHUB_ENV
152
+
153
+ - name : laste ned build-fil
154
+ uses : actions/download-artifact@v4
155
+ with :
156
+ name : " ${{ matrix.project }}_build_result"
157
+ - name : ser om vi har nais config og at bygget gikk bra
158
+ id : deploy-files
159
+ uses : andstor/file-existence-action@v3
160
+ with :
161
+ files : " ${{ env.VARS }}, ${{ matrix.project }}_build_success.txt"
162
+
163
+ - name : Sett docker image som env-var
164
+ id : sett_docker_image_var
165
+ run : echo "docker_image=$(cat ${{ matrix.project }}_build_success.txt)" >> $GITHUB_ENV
166
+
152
167
- name : Deploy
153
- if : env.IMAGE_EXISTS == 'true' && steps.confirm_config_file .outputs.files_exists == 'true'
168
+ if : steps.deploy-files .outputs.files_exists == 'true'
154
169
uses : nais/deploy/actions/deploy@v2
155
170
env :
156
171
CLUSTER : ${{ matrix.cluster }}
157
- IMAGE : ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_PREFIX }}${{ matrix.project }}:${{ needs.generate_vars.outputs.short_sha }}
172
+ IMAGE : ${{ env.docker_image }}
158
173
RESOURCE : config/nais.yml
159
- VAR : app=${{ matrix.project }}
174
+ VAR : team=helsearbeidsgiver, app=${{ matrix.project }}
0 commit comments