-
Notifications
You must be signed in to change notification settings - Fork 0
executable file
·197 lines (171 loc) · 7.18 KB
/
test-and-deploy.yml
File metadata and controls
executable file
·197 lines (171 loc) · 7.18 KB
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
name: Test & Deploy Grading Script to AWS Lambda
on:
push:
branches:
- master
workflow_dispatch:
jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [3.8]
defaults:
run:
working-directory: app/
env:
REQUEST_SCHEMA_URL: https://raw.githubusercontent.com/lambda-feedback/request-response-schemas/master/request.json
RESPONSE_SCHEMA_URL: https://raw.githubusercontent.com/lambda-feedback/request-response-schemas/master/response.json
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install -r backend/requirements.txt
python -m pip install -r requirements.txt
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test Grading functions
run: |
pytest -v grading_tests.py::TestGradingFunction
- name: Test Request/Response Schema validation
run: |
pytest -v backend/tests/requests.py::TestRequestValidation
pytest -v backend/tests/responses.py::TestResponseValidation
- name: Test Handler functions
run: |
pytest -v backend/tests/handling.py::TestHandlerFunction
deploy-staging:
name: Deploy Staging
needs: test
runs-on: ubuntu-latest
environment: production
env:
ECR_REPOSITORY: lambda-feedback-staging-functions-repository
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set config.json output
id: set_config_var
run: |
content=`cat ./config.json`
# the following lines are only required for multi line json
content="${content//'%'/'%25'}"
content="${content//$'\n'/'%0A'}"
content="${content//$'\r'/'%0D'}"
# end of optional handling for multi line json
echo "::set-output name=configJson::$content"
- name: set Grading Function Name
id: set_function_name
run: |
functionName="${{fromJson(steps.set_config_var.outputs.configJson).GradingFunctionName}}"
[[ -z "$functionName" ]] && { echo "Add GradingFunctionName to config.json" ; exit 1; }
echo "::set-output name=function_name::$functionName"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.LAMBDA_CONTAINER_PIPELINE_AWS_ID }}
aws-secret-access-key: ${{ secrets.LAMBDA_CONTAINER_PIPELINE_AWS_SECRET }}
aws-region: eu-west-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.set_function_name.outputs.function_name }}
run: |
# Build docker image from algorithm, schema and requirements
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG app/
# Push image to ECR
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: deploy grading function
id: deploy-grading-function
env:
BACKEND_API_URL: https://hytqbudf4a.eu-west-1.awsapprunner.com
API_KEY: ${{ secrets.FUNCTION_ADMIN_API_KEY }}
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.set_function_name.outputs.function_name }}
run: |
curl --location --request POST "$BACKEND_API_URL/grading-function/ensure" \
--header 'content-type: application/json' \
--data-raw "{
\"apiKey\": \"$API_KEY\",
\"dockerImageUri\": \"$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG\",
\"functionName\": \"$IMAGE_TAG\"
}"
deploy-production:
name: Deploy Production
needs: deploy-staging
runs-on: ubuntu-latest
environment: production
env:
ECR_REPOSITORY: lambda-feedback-production-functions-repository
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set config.json output
id: set_config_var
run: |
content=`cat ./config.json`
# the following lines are only required for multi line json
content="${content//'%'/'%25'}"
content="${content//$'\n'/'%0A'}"
content="${content//$'\r'/'%0D'}"
# end of optional handling for multi line json
echo "::set-output name=configJson::$content"
- name: set Grading Function Name
id: set_function_name
run: |
functionName="${{fromJson(steps.set_config_var.outputs.configJson).GradingFunctionName}}"
[[ -z "$functionName" ]] && { echo "Add GradingFunctionName to config.json" ; exit 1; }
echo "::set-output name=function_name::$functionName"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.LAMBDA_CONTAINER_PIPELINE_AWS_ID }}
aws-secret-access-key: ${{ secrets.LAMBDA_CONTAINER_PIPELINE_AWS_SECRET }}
aws-region: eu-west-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.set_function_name.outputs.function_name }}
run: |
# Build docker image from algorithm, schema and requirements
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG app/
# Push image to ECR
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: deploy grading function
id: deploy-grading-function
env:
BACKEND_API_URL: https://vnfapgr7gv.eu-west-1.awsapprunner.com
API_KEY: ${{ secrets.FUNCTION_ADMIN_API_KEY }}
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.set_function_name.outputs.function_name }}
run: |
curl --location --request POST "$BACKEND_API_URL/grading-function/ensure" \
--header 'content-type: application/json' \
--data-raw "{
\"apiKey\": \"$API_KEY\",
\"dockerImageUri\": \"$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG\",
\"functionName\": \"$IMAGE_TAG\"
}"