Skip to content

Commit df4724c

Browse files
authored
Improve version check during deployment (#4285)
1 parent c71c178 commit df4724c

File tree

2 files changed

+68
-76
lines changed

2 files changed

+68
-76
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: 'Wait for deployment'
2+
description: 'Wait fr deployment'
3+
inputs:
4+
url:
5+
description: 'URL'
6+
required: true
7+
githash:
8+
description: 'Githash'
9+
required: true
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Wait for deployment
14+
run: |
15+
import requests
16+
import os
17+
import time
18+
19+
attempts = 0
20+
new_version_live_counter = 0
21+
while new_version_live_counter < 3:
22+
response = requests.get(os.getenv('URL'))
23+
try:
24+
commit = response.json()['version']
25+
if commit == os.getenv('GITHASH'):
26+
print('New version live')
27+
new_version_live_counter = new_version_live_counter + 1
28+
time.sleep(1)
29+
continue
30+
else:
31+
print('Commit hash does not match. Retrying...')
32+
except Exception as e:
33+
print('Failed to get version', e)
34+
35+
attempts += 1
36+
37+
if attempts > 30:
38+
print('Failed to get new version')
39+
exit(1)
40+
41+
time.sleep(attempts)
42+
shell: python
43+
env:
44+
URL: ${{ inputs.url }}
45+
GITHASH: ${{ inputs.githash }}

.github/workflows/deploy.yml

Lines changed: 23 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,6 @@ env:
1212
TF_WORKSPACE: ${{ fromJSON('["pastaporto", "production"]')[github.ref == 'refs/heads/main'] }}
1313

1414
jobs:
15-
create-db:
16-
runs-on: ubuntu-24.04
17-
defaults:
18-
run:
19-
working-directory: ./infrastructure/applications
20-
steps:
21-
- uses: actions/checkout@v4
22-
if: github.ref != 'refs/heads/main'
23-
with:
24-
ref: ${{ github.ref }}
25-
fetch-depth: 0
26-
- name: Configure AWS credentials
27-
if: github.ref != 'refs/heads/main'
28-
uses: aws-actions/configure-aws-credentials@v4
29-
with:
30-
aws-access-key-id: ${{ secrets.aws_access_key_id }}
31-
aws-secret-access-key: ${{ secrets.aws_secret_access_key }}
32-
aws-region: eu-central-1
33-
- uses: hashicorp/setup-terraform@v3
34-
if: github.ref != 'refs/heads/main'
35-
with:
36-
terraform_version: 1.2.4
37-
- name: Terraform Init
38-
if: github.ref != 'refs/heads/main'
39-
run: terraform init
40-
env:
41-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
43-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
44-
- name: Terraform apply
45-
if: github.ref != 'refs/heads/main'
46-
run: terraform apply -target module.database -no-color -auto-approve &> /dev/null
47-
env:
48-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
50-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
51-
AWS_DEFAULT_REGION: eu-central-1
52-
5315
build-pretix:
5416
runs-on: [self-hosted]
5517
steps:
@@ -128,6 +90,8 @@ jobs:
12890
permissions:
12991
packages: write
13092
contents: read
93+
outputs:
94+
githash: ${{ steps.git.outputs.githash }}
13195

13296
steps:
13397
- uses: actions/checkout@v4
@@ -190,7 +154,7 @@ jobs:
190154

191155
deploy-be:
192156
runs-on: ubuntu-24.04
193-
needs: [build-be, build-pretix, create-db]
157+
needs: [build-be, build-pretix]
194158
environment:
195159
name: ${{ fromJSON('["pastaporto", "production"]')[github.ref == 'refs/heads/main'] }}
196160
defaults:
@@ -224,34 +188,26 @@ jobs:
224188

225189
wait-be-update:
226190
runs-on: ubuntu-24.04
227-
needs: [deploy-be]
191+
needs: [deploy-be, build-be]
228192
steps:
193+
- uses: actions/checkout@v4
194+
with:
195+
ref: ${{ github.ref }}
196+
fetch-depth: 0
229197
- name: Wait stable deployment
230-
run: |
231-
while true; do
232-
response=$(curl -s "https://${{ fromJSON('["pastaporto-", ""]')[github.ref == 'refs/heads/main'] }}admin.pycon.it/health")
233-
commit=$(echo $response | jq -r '.commit')
234-
if [ "$commit" == "${{ steps.git.outputs.githash }}" ]; then
235-
echo "New version live"
236-
break
237-
else
238-
echo "Commit hash does not match. Retrying..."
239-
sleep 3
240-
fi
241-
done
242-
shell: bash
243-
env:
244-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
245-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
246-
AWS_DEFAULT_REGION: eu-central-1
198+
uses: ./.github/actions/wait-for-deployment
199+
with:
200+
url: https://${{ fromJSON('["pastaporto-", ""]')[github.ref == 'refs/heads/main'] }}admin.pycon.it/health/
201+
githash: ${{ needs.build-be.outputs.githash }}
247202

248203
build-fe:
249204
needs: [wait-be-update]
250205
runs-on: [self-hosted]
251206
permissions:
252207
packages: write
253208
contents: read
254-
209+
outputs:
210+
githash: ${{ steps.git.outputs.githash }}
255211
steps:
256212
- uses: actions/checkout@v4
257213
with:
@@ -367,23 +323,14 @@ jobs:
367323

368324
wait-fe-update:
369325
runs-on: ubuntu-24.04
370-
needs: [deploy-fe]
326+
needs: [deploy-fe, build-fe]
371327
steps:
328+
- uses: actions/checkout@v4
329+
with:
330+
ref: ${{ github.ref }}
331+
fetch-depth: 0
372332
- name: Wait stable deployment
373-
run: |
374-
while true; do
375-
response=$(curl -s "https://${{ fromJSON('["pastaporto-frontend", "frontend"]')[github.ref == 'refs/heads/main'] }}.pycon.it/api/health")
376-
commit=$(echo $response | jq -r '.commit')
377-
if [ "$commit" == "${{ steps.git.outputs.githash }}" ]; then
378-
echo "New version live"
379-
break
380-
else
381-
echo "Commit hash does not match. Retrying..."
382-
sleep 3
383-
fi
384-
done
385-
shell: bash
386-
env:
387-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
388-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
389-
AWS_DEFAULT_REGION: eu-central-1
333+
uses: ./.github/actions/wait-for-deployment
334+
with:
335+
url: https://${{ fromJSON('["pastaporto-frontend", "frontend"]')[github.ref == 'refs/heads/main'] }}.pycon.it/api/health
336+
githash: ${{ needs.build-fe.outputs.githash }}

0 commit comments

Comments
 (0)