Skip to content

Commit e927b68

Browse files
Initial commit
0 parents  commit e927b68

File tree

13 files changed

+626
-0
lines changed

13 files changed

+626
-0
lines changed
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
name: Test & Deploy Evaluation Function to AWS Lambda
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
name: Test
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
python-version: [3.8]
19+
20+
defaults:
21+
run:
22+
working-directory: app/
23+
24+
env:
25+
SCHEMAS_URL: https://raw.githubusercontent.com/lambda-feedback/request-response-schemas/master/
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v2
30+
31+
- name: Set up Python ${{ matrix.python-version }}
32+
uses: actions/setup-python@v2
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
36+
- name: Install dependencies
37+
run: |
38+
python -m pip install --upgrade pip
39+
python -m pip install flake8 pytest
40+
python -m pip install -r requirements.txt
41+
42+
- name: Lint with flake8
43+
run: |
44+
# stop the build if there are Python syntax errors or undefined names
45+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
46+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
47+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
48+
49+
- name: Test Evaluation Function
50+
run: |
51+
pytest -v evaluation_tests.py::TestEvaluationFunction
52+
53+
- name: Test Preview Function
54+
run: |
55+
pytest -v preview_tests.py::TestPreviewFunction
56+
57+
deploy-staging:
58+
name: Deploy Staging
59+
needs: test
60+
runs-on: ubuntu-latest
61+
environment: production
62+
env:
63+
ECR_REPOSITORY: lambda-feedback-staging-functions-repository
64+
65+
steps:
66+
- name: Checkout
67+
uses: actions/checkout@v2
68+
69+
- name: Set config.json output
70+
id: set_config_var
71+
run: |
72+
content=`cat ./config.json`
73+
# the following lines are only required for multi line json
74+
content="${content//'%'/'%25'}"
75+
content="${content//$'\n'/'%0A'}"
76+
content="${content//$'\r'/'%0D'}"
77+
# end of optional handling for multi line json
78+
echo "::set-output name=configJson::$content"
79+
80+
- name: set Evaluation Function Name
81+
id: set_function_name
82+
run: |
83+
functionName="${{fromJson(steps.set_config_var.outputs.configJson).EvaluationFunctionName}}"
84+
[[ -z "$functionName" ]] && { echo "Add EvaluationFunctionName to config.json" ; exit 1; }
85+
echo "::set-output name=function_name::$functionName"
86+
87+
- name: Configure AWS credentials
88+
uses: aws-actions/configure-aws-credentials@v1
89+
with:
90+
aws-access-key-id: ${{ secrets.LAMBDA_CONTAINER_PIPELINE_AWS_ID }}
91+
aws-secret-access-key: ${{ secrets.LAMBDA_CONTAINER_PIPELINE_AWS_SECRET }}
92+
aws-region: eu-west-2
93+
94+
- name: Login to Amazon ECR
95+
id: login-ecr
96+
uses: aws-actions/amazon-ecr-login@v1
97+
98+
- name: Build, tag, and push image to Amazon ECR
99+
id: build-image
100+
env:
101+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
102+
IMAGE_TAG: ${{ steps.set_function_name.outputs.function_name }}
103+
run: |
104+
# Build docker image from algorithm, schema and requirements
105+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG app/
106+
# Push image to ECR
107+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
108+
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
109+
110+
- name: deploy evaluation function
111+
id: deploy-evaluation-function
112+
env:
113+
BACKEND_API_URL: https://staging-api.lambdafeedback.com
114+
API_KEY: ${{ secrets.FUNCTION_ADMIN_API_KEY }}
115+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
116+
IMAGE_TAG: ${{ steps.set_function_name.outputs.function_name }}
117+
run: |
118+
curl --location --request POST "$BACKEND_API_URL/grading-function/ensure" \
119+
--header 'content-type: application/json' \
120+
--data-raw "{
121+
\"apiKey\": \"$API_KEY\",
122+
\"dockerImageUri\": \"$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG\",
123+
\"functionName\": \"$IMAGE_TAG\"
124+
}"
125+
126+
deploy-production:
127+
name: Deploy Production
128+
needs: deploy-staging
129+
runs-on: ubuntu-latest
130+
environment: production
131+
env:
132+
ECR_REPOSITORY: lambda-feedback-production-functions-repository
133+
134+
steps:
135+
- name: Checkout
136+
uses: actions/checkout@v2
137+
138+
- name: Set config.json output
139+
id: set_config_var
140+
run: |
141+
content=`cat ./config.json`
142+
# the following lines are only required for multi line json
143+
content="${content//'%'/'%25'}"
144+
content="${content//$'\n'/'%0A'}"
145+
content="${content//$'\r'/'%0D'}"
146+
# end of optional handling for multi line json
147+
echo "::set-output name=configJson::$content"
148+
149+
- name: set Evaluation Function Name
150+
id: set_function_name
151+
run: |
152+
functionName="${{fromJson(steps.set_config_var.outputs.configJson).EvaluationFunctionName}}"
153+
[[ -z "$functionName" ]] && { echo "Add EvaluationFunctionName to config.json" ; exit 1; }
154+
echo "::set-output name=function_name::$functionName"
155+
156+
- name: Configure AWS credentials
157+
uses: aws-actions/configure-aws-credentials@v1
158+
with:
159+
aws-access-key-id: ${{ secrets.LAMBDA_CONTAINER_PIPELINE_AWS_ID }}
160+
aws-secret-access-key: ${{ secrets.LAMBDA_CONTAINER_PIPELINE_AWS_SECRET }}
161+
aws-region: eu-west-2
162+
163+
- name: Login to Amazon ECR
164+
id: login-ecr
165+
uses: aws-actions/amazon-ecr-login@v1
166+
167+
- name: Build, tag, and push image to Amazon ECR
168+
id: build-image
169+
env:
170+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
171+
IMAGE_TAG: ${{ steps.set_function_name.outputs.function_name }}
172+
run: |
173+
# Build docker image from algorithm, schema and requirements
174+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG app/
175+
# Push image to ECR
176+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
177+
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
178+
179+
- name: deploy evaluation function
180+
id: deploy-evaluation-function
181+
env:
182+
BACKEND_API_URL: https://prod-api.lambdafeedback.com
183+
API_KEY: ${{ secrets.FUNCTION_ADMIN_API_KEY }}
184+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
185+
IMAGE_TAG: ${{ steps.set_function_name.outputs.function_name }}
186+
run: |
187+
curl --location --request POST "$BACKEND_API_URL/grading-function/ensure" \
188+
--header 'content-type: application/json' \
189+
--data-raw "{
190+
\"apiKey\": \"$API_KEY\",
191+
\"dockerImageUri\": \"$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG\",
192+
\"functionName\": \"$IMAGE_TAG\"
193+
}"

.gitignore

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/
130+
131+
# VSCode configuration
132+
.vscode

0 commit comments

Comments
 (0)