-
Notifications
You must be signed in to change notification settings - Fork 0
98 lines (86 loc) · 3.38 KB
/
main.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
name: FastAPI CI/CD
on:
push:
branches:
- main
jobs:
CI:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install Python Virtual ENV
run: pip3.9 install virtualenv
- name: Virtual ENV
uses: actions/cache@v2
id: cache-venv
with:
path: venv
key: ${{ runner.os }}-venv-${{ hashFiles('**/requirements*.txt') }}
restore-keys: |
${{ runner.os }}-venv-
# - name: Run Tests
# run: >
# python3 -m venv venv && source venv/bin/activate &&
# python3 -m pip install --upgrade pip &&
# python3 -m pip install pytest && python3 -m pip install pytest-cov &&
# python3 -m pytest -s -vv -m "not slow" --cov=tests --cov=balancelib -W ignore::DeprecationWarning --cov-report term-missing:skip-covered
- name: Activate Virtual ENV
run: >
python3 -m venv venv && source venv/bin/activate &&
python3 -m pip install --upgrade pip &&
pip3 install -r requirements.txt --only-binary=:all: --no-deps
--platform manylinux2010_x86_64 --target=dependencies --python 3.9
- name: Install Cryptography
run: >
python3 -m venv venv && source venv/bin/activate &&
python3 -m pip install --upgrade pip &&
pip3 install --platform manylinux2014_x86_64 --target=dependencies
--implementation cp --python 3.9 --only-binary=:all: --upgrade cryptography==38.0.0
- name: Create archive of dependencies
run: |
cd ./venv/lib/python3.9/site-packages
zip -r9 ../../../../api.zip .
- name: Add API files to Zip file
run: >
zip -g ./api.zip -r balancelib &&
zip -g ./api.zip -r database &&
zip -g ./api.zip -r main.py &&
cd dependencies && zip -g ../api.zip -r . && cd ..
- name: Upload zip file artifact
uses: actions/upload-artifact@v2
with:
name: api
path: api.zip
CD:
runs-on: ubuntu-latest
needs: [CI]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Install AWS CLI
uses: unfor19/install-aws-cli-action@v1
with:
version: 1
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_SECRET_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Download Lambda api.zip
uses: actions/download-artifact@v2
with:
name: api
- name: Upload to S3
run: aws s3 cp api.zip s3://${{ secrets.AWS_BUCKET_FASTAPI }}/api.zip
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_SECRET_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Deploy new Lambda
run: aws lambda update-function-code --function-name ${{ secrets.AWS_FUNCTION_NAME }} --s3-bucket ${{ secrets.AWS_BUCKET_FASTAPI }} --s3-key api.zip
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_SECRET_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}