Skip to content

Commit b27720e

Browse files
authored
Bruk GAR i build workflow (#842)
Ta i bruk docker-build-push/v0 for å publisere til GAR. Bruk artifact upload workaround for å kunne bruke docker-build-push output i deploy steget.
1 parent f53253e commit b27720e

File tree

1 file changed

+47
-32
lines changed

1 file changed

+47
-32
lines changed

.github/workflows/build.yml

+47-32
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ on:
88
- dev/**
99

1010
env:
11-
DOCKER_REGISTRY: ghcr.io
12-
DOCKER_IMAGE_PREFIX: ${{ github.repository }}/im-
1311
ORG_GRADLE_PROJECT_githubPassword: ${{ secrets.GITHUB_TOKEN }}
1412

1513
jobs:
@@ -73,6 +71,7 @@ jobs:
7371
runs-on: ubuntu-latest
7472
permissions:
7573
packages: write
74+
id-token: write
7675
needs: generate_vars
7776
if: needs.generate_vars.outputs.is_matrix_empty == 'false'
7877
strategy:
@@ -96,20 +95,29 @@ jobs:
9695
with:
9796
files: "apps/${{ matrix.project }}/build/libs/app.jar"
9897

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
10999
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() }}
110111
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"
113121

114122
deploy:
115123
runs-on: ubuntu-latest
@@ -123,37 +131,44 @@ jobs:
123131
concurrency:
124132
group: deploy-dev-${{ matrix.project }}
125133
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-
139134
- name: Determine app configuration file
140-
if: env.IMAGE_EXISTS == 'true'
141135
run: |
142136
CONFIG_FILE="config/${{ matrix.project }}/${{ matrix.cluster }}.yml"
143137
echo "VARS=$CONFIG_FILE" >> $GITHUB_ENV # VARS-variable is used by nais/deploy/actions/deploy
144138
145139
- name: Confirm app configuration file existence
146140
id: confirm_config_file
147-
if: env.IMAGE_EXISTS == 'true'
148141
uses: andstor/file-existence-action@v3
149142
with:
150143
files: "${{ env.VARS }}"
151144

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+
152167
- 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'
154169
uses: nais/deploy/actions/deploy@v2
155170
env:
156171
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 }}
158173
RESOURCE: config/nais.yml
159-
VAR: app=${{ matrix.project }}
174+
VAR: team=helsearbeidsgiver,app=${{ matrix.project }}

0 commit comments

Comments
 (0)