1- name : Test & Deploy Grading Script to AWS Lambda
1+ name : Test & Deploy Evaluation Function to AWS Lambda
22
33on :
44 push :
2020 run :
2121 working-directory : app/
2222
23+ env :
24+ REQUEST_SCHEMA_URL : https://raw.githubusercontent.com/lambda-feedback/request-response-schemas/master/request.json
25+ RESPONSE_SCHEMA_URL : https://raw.githubusercontent.com/lambda-feedback/request-response-schemas/master/responsev2.json
26+
2327 steps :
2428 - name : Checkout
2529 uses : actions/checkout@v2
3337 run : |
3438 python -m pip install --upgrade pip
3539 python -m pip install flake8 pytest
36- python -m pip install -r tools/tools_requirements.txt
3740 python -m pip install -r requirements.txt
3841
3942 - name : Lint with flake8
@@ -43,29 +46,109 @@ jobs:
4346 # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
4447 flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
4548
46- - name : Test Handler functions
49+ - name : Test Evaluation Function
4750 run : |
48- pytest -v tests/handling.py::TestHandlerFunction
49- - name : Test JSON schema
51+ pytest -v evaluation_tests.py::TestEvaluationFunction
52+
53+ deploy-staging :
54+ name : Deploy Staging
55+ needs : test
56+ runs-on : ubuntu-latest
57+ environment : production
58+ env :
59+ ECR_REPOSITORY : lambda-feedback-staging-functions-repository
60+
61+ steps :
62+ - name : Checkout
63+ uses : actions/checkout@v2
64+
65+ - name : Set config.json output
66+ id : set_config_var
5067 run : |
51- pytest -v tests/validation.py::TestSchemaValidation
52- - name : Test Grading functions
68+ content=`cat ./config.json`
69+ # the following lines are only required for multi line json
70+ content="${content//'%'/'%25'}"
71+ content="${content//$'\n'/'%0A'}"
72+ content="${content//$'\r'/'%0D'}"
73+ # end of optional handling for multi line json
74+ echo "::set-output name=configJson::$content"
75+
76+ - name : set Evaluation Function Name
77+ id : set_function_name
5378 run : |
54- pytest -v tests/grading.py::TestGradingFunction
79+ functionName="${{fromJson(steps.set_config_var.outputs.configJson).EvaluationFunctionName}}"
80+ [[ -z "$functionName" ]] && { echo "Add EvaluationFunctionName to config.json" ; exit 1; }
81+ echo "::set-output name=function_name::$functionName"
5582
56- deploy :
57- name : Deploy
58- needs : test
83+ - name : Configure AWS credentials
84+ uses : aws-actions/configure-aws-credentials@v1
85+ with :
86+ aws-access-key-id : ${{ secrets.LAMBDA_CONTAINER_PIPELINE_AWS_ID }}
87+ aws-secret-access-key : ${{ secrets.LAMBDA_CONTAINER_PIPELINE_AWS_SECRET }}
88+ aws-region : eu-west-2
89+
90+ - name : Login to Amazon ECR
91+ id : login-ecr
92+ uses : aws-actions/amazon-ecr-login@v1
93+
94+ - name : Build, tag, and push image to Amazon ECR
95+ id : build-image
96+ env :
97+ ECR_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
98+ IMAGE_TAG : ${{ steps.set_function_name.outputs.function_name }}
99+ run : |
100+ # Build docker image from algorithm, schema and requirements
101+ docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG app/
102+ # Push image to ECR
103+ docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
104+ echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
105+
106+ - name : deploy evaluation function
107+ id : deploy-evaluation-function
108+ env :
109+ BACKEND_API_URL : https://hytqbudf4a.eu-west-1.awsapprunner.com
110+ API_KEY : ${{ secrets.FUNCTION_ADMIN_API_KEY }}
111+ ECR_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
112+ IMAGE_TAG : ${{ steps.set_function_name.outputs.function_name }}
113+ run : |
114+ curl --location --request POST "$BACKEND_API_URL/grading-function/ensure" \
115+ --header 'content-type: application/json' \
116+ --data-raw "{
117+ \"apiKey\": \"$API_KEY\",
118+ \"dockerImageUri\": \"$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG\",
119+ \"functionName\": \"$IMAGE_TAG\"
120+ }"
121+
122+ deploy-production :
123+ name : Deploy Production
124+ needs : deploy-staging
59125 runs-on : ubuntu-latest
60126 environment : production
61127 env :
62- ECR_REPOSITORY : is-exact-equal
63- LAMBDA_FUNCTION_NAME : isExactEqual
128+ ECR_REPOSITORY : lambda-feedback-production-functions-repository
64129
65130 steps :
66131 - name : Checkout
67132 uses : actions/checkout@v2
68133
134+ - name : Set config.json output
135+ id : set_config_var
136+ run : |
137+ content=`cat ./config.json`
138+ # the following lines are only required for multi line json
139+ content="${content//'%'/'%25'}"
140+ content="${content//$'\n'/'%0A'}"
141+ content="${content//$'\r'/'%0D'}"
142+ # end of optional handling for multi line json
143+ echo "::set-output name=configJson::$content"
144+
145+ - name : set Evaluation Function Name
146+ id : set_function_name
147+ run : |
148+ functionName="${{fromJson(steps.set_config_var.outputs.configJson).EvaluationFunctionName}}"
149+ [[ -z "$functionName" ]] && { echo "Add EvaluationFunctionName to config.json" ; exit 1; }
150+ echo "::set-output name=function_name::$functionName"
151+
69152 - name : Configure AWS credentials
70153 uses : aws-actions/configure-aws-credentials@v1
71154 with :
@@ -81,17 +164,26 @@ jobs:
81164 id : build-image
82165 env :
83166 ECR_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
84- IMAGE_TAG : latest
167+ IMAGE_TAG : ${{ steps.set_function_name.outputs.function_name }}
85168 run : |
86169 # Build docker image from algorithm, schema and requirements
87170 docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG app/
88171 # Push image to ECR
89172 docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
90173 echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
91174
92- - name : Update lambda function image
175+ - name : deploy evaluation function
176+ id : deploy-evaluation-function
93177 env :
178+ BACKEND_API_URL : https://vnfapgr7gv.eu-west-1.awsapprunner.com
179+ API_KEY : ${{ secrets.FUNCTION_ADMIN_API_KEY }}
94180 ECR_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
95- IMAGE_TAG : latest
181+ IMAGE_TAG : ${{ steps.set_function_name.outputs.function_name }}
96182 run : |
97- aws lambda update-function-code --function-name $LAMBDA_FUNCTION_NAME --image-uri $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
183+ curl --location --request POST "$BACKEND_API_URL/grading-function/ensure" \
184+ --header 'content-type: application/json' \
185+ --data-raw "{
186+ \"apiKey\": \"$API_KEY\",
187+ \"dockerImageUri\": \"$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG\",
188+ \"functionName\": \"$IMAGE_TAG\"
189+ }"
0 commit comments