-
Notifications
You must be signed in to change notification settings - Fork 26
198 lines (181 loc) · 8.07 KB
/
tests-django.yml
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: Django Tutorial Tests
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
push:
branches: [main]
paths:
[
'.github/workflows/tests-django.yml',
'examples/**',
'src/**',
'test/tutorials/**',
'package.json',
'yarn.lock',
'Dockerfile',
]
pull_request:
branches: [main]
paths:
[
'.github/workflows/tests-django.yml',
'examples/**',
'src/**',
'test/tutorials/**',
'package.json',
'yarn.lock',
'Dockerfile',
]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
setup:
runs-on: ubuntu-latest
outputs:
region: ${{ steps['set-region'].outputs['region'] }}
steps:
- name: Set AWS region
id: set-region
run: |
# pick aws region at random and append it to the repository name
# since public ecr always works out of us-east-1
regions=("ap-northeast-1" "ap-northeast-2" "ap-northeast-3" "ap-south-1" "ap-southeast-1" "ap-southeast-2" "ca-central-1" "eu-central-1" "eu-north-1" "eu-west-1" "eu-west-2" "eu-west-3" "sa-east-1" "us-east-1" "us-east-2" "us-west-1" "us-west-2")
regionslen=${#regions[@]}
index=$(($RANDOM % $regionslen))
echo "region=$(echo ${regions[$index]})" >> $GITHUB_OUTPUT
deploy:
runs-on: ubuntu-latest
needs:
- setup
steps:
- uses: actions/checkout@v3
- name: Use Python 3.9
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
push: false
load: true
cache-from: type=gha
cache-to: type=gha
tags: iasql:latest
- name: Start local iasql container
run: |
# Temporarily export the server port until it's only the Postgres port needed
docker run -p 5432:5432 -e IASQL_ENV=ci --name iasql iasql &
while ! psql postgres://postgres:test@localhost:5432/iasql_metadata -b -q -c "SELECT iasql_engine_health()"; do sleep 1 && echo -n .; done;
- name: Determine Test Account To Use
id: determine-test-account
env:
SECRET_HEADER: ${{ secrets.SECRET_HEADER }}
LAMBDA_FUNCTION: 'https://22quullhnmsrttacexxc74uium0nndzo.lambda-url.us-east-2.on.aws/'
run: |
RESPONSE=$(curl -X POST -H "Content-Type: text/plain" -H "${SECRET_HEADER}" -d '1' ${LAMBDA_FUNCTION} 2>/dev/null)
echo $RESPONSE
ACCOUNT_INDEX=$(echo $RESPONSE | jq '.[0]' || exit 1)
echo "account_index=$(echo ${ACCOUNT_INDEX})" >> $GITHUB_OUTPUT
- name: Setup IaSQL database
id: set-up-database
run: |
export AWS_ACCESS_KEY_ID=$(echo "${ACCESS_KEY_IDS}" | jq -r ".[${ACCOUNT_INDEX}]")
export AWS_SECRET_ACCESS_KEY=$(echo "${SECRET_ACCESS_KEYS}" | jq -r ".[${ACCOUNT_INDEX}]")
source ./src/scripts/setup-iasql-db.sh
echo "iasql_username=$IASQL_USERNAME" >> $GITHUB_ENV
echo "iasql_password=$IASQL_PASSWORD" >> $GITHUB_ENV
env:
ACCOUNT_INDEX: ${{ steps['determine-test-account'].outputs['account_index'] }}
AWS_REGION: ${{ needs.setup.outputs['region'] }}
ACCESS_KEY_IDS: ${{ secrets.ACCESS_KEY_IDS }}
SECRET_ACCESS_KEYS: ${{ secrets.SECRET_ACCESS_KEYS }}
- name: Pre-clean with cleaning script
uses: nick-fields/retry@v2
with:
max_attempts: 2
retry_on: error
timeout_minutes: 30
command: |
export AWS_ACCESS_KEY_ID=$(echo "${ACCESS_KEY_IDS}" | jq -r ".[${ACCOUNT_INDEX}]")
export AWS_SECRET_ACCESS_KEY=$(echo "${SECRET_ACCESS_KEYS}" | jq -r ".[${ACCOUNT_INDEX}]")
# Remove delete protection from clusters
echo "\nStarting transaction..."
psql "postgres://$IASQL_USERNAME:$IASQL_PASSWORD@localhost:5432/iasql" -c "select * from iasql_begin();"
# Remove delete protection
echo "\nDisable delete protection..."
psql "postgres://$IASQL_USERNAME:$IASQL_PASSWORD@localhost:5432/iasql" -c "UPDATE db_cluster SET delete_protection=FALSE;"
echo "\nApply removal..."
psql $PSQL_CONN -c "select * from iasql_commit();"
echo "\nStart transaction..."
psql "postgres://$IASQL_USERNAME:$IASQL_PASSWORD@localhost:5432/iasql" -c "select * from iasql_begin();"
echo "\nDelete all records..."
psql "postgres://$IASQL_USERNAME:$IASQL_PASSWORD@localhost:5432/iasql" -c "select * from delete_all_records();"
echo "\nApply..."
psql $PSQL_CONN -c "select * from iasql_commit();"
env:
ACCOUNT_INDEX: ${{ steps['determine-test-account'].outputs['account_index'] }}
AWS_REGION: ${{ needs.setup.outputs['region'] }}
ACCESS_KEY_IDS: ${{ secrets.ACCESS_KEY_IDS }}
SECRET_ACCESS_KEYS: ${{ secrets.SECRET_ACCESS_KEYS }}
IASQL_USERNAME: ${{ env.iasql_username }}
IASQL_PASSWORD: ${{ env.iasql_password }}
PSQL_CONN: postgres://postgres:test@localhost:5432/iasql
- name: Run deploy script
uses: nick-fields/retry@v2
with:
max_attempts: 2
retry_on: error
timeout_minutes: 40
command: |
export AWS_ACCESS_KEY_ID=$(echo "${ACCESS_KEY_IDS}" | jq -r ".[${ACCOUNT_INDEX}]")
export AWS_SECRET_ACCESS_KEY=$(echo "${SECRET_ACCESS_KEYS}" | jq -r ".[${ACCOUNT_INDEX}]")
./test/tutorials/django-ci.sh
env:
ACCOUNT_INDEX: ${{ steps['determine-test-account'].outputs['account_index'] }}
AWS_REGION: ${{ needs.setup.outputs['region'] }}
ACCESS_KEY_IDS: ${{ secrets.ACCESS_KEY_IDS }}
SECRET_ACCESS_KEYS: ${{ secrets.SECRET_ACCESS_KEYS }}
DB_NAME: iasql
DB_USER: ${{ env.iasql_username }}
DB_PASSWORD: ${{ env.iasql_password }}
DB_HOST: '127.0.0.1'
DB_PORT: 5432
GH_PAT: ${{ secrets.GH_PAT }}
IASQL_USERNAME: ${{ env.iasql_username }}
IASQL_PASSWORD: ${{ env.iasql_password }}
- name: Run cleaning script
uses: nick-fields/retry@v2
with:
max_attempts: 2
retry_on: error
timeout_minutes: 30
command: |
export AWS_ACCESS_KEY_ID=$(echo "${ACCESS_KEY_IDS}" | jq -r ".[${ACCOUNT_INDEX}]")
export AWS_SECRET_ACCESS_KEY=$(echo "${SECRET_ACCESS_KEYS}" | jq -r ".[${ACCOUNT_INDEX}]")
echo "\nStart transaction..."
psql "postgres://$IASQL_USERNAME:$IASQL_PASSWORD@localhost:5432/iasql" -c "select * from iasql_begin();"
echo "\nDelete all records..."
psql "postgres://$IASQL_USERNAME:$IASQL_PASSWORD@localhost:5432/iasql" -c "select * from delete_all_records();"
echo "\nApply..."
psql $PSQL_CONN -c "select * from iasql_commit();"
env:
ACCOUNT_INDEX: ${{ steps['determine-test-account'].outputs['account_index'] }}
AWS_REGION: ${{ needs.setup.outputs['region'] }}
ACCESS_KEY_IDS: ${{ secrets.ACCESS_KEY_IDS }}
SECRET_ACCESS_KEYS: ${{ secrets.SECRET_ACCESS_KEYS }}
IASQL_USERNAME: ${{ env.iasql_username }}
IASQL_PASSWORD: ${{ env.iasql_password }}
PSQL_CONN: postgres://postgres:test@localhost:5432/iasql
- name: Return test account
if: always()
env:
SECRET_HEADER: ${{ secrets.SECRET_HEADER }}
ACCOUNT_INDEX: ${{ steps['determine-test-account'].outputs['account_index'] }}
LAMBDA_FUNCTION: 'https://22quullhnmsrttacexxc74uium0nndzo.lambda-url.us-east-2.on.aws/'
run: |
curl -X POST -H "Content-Type: application/json" -H "${SECRET_HEADER}" -H "x-iasql-drop: true" -d "[${ACCOUNT_INDEX}]" ${LAMBDA_FUNCTION}
- name: Local engine logs
if: always()
run: docker logs iasql