Last minute fixes #63
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: FastAPI CI/CD | |
on: | |
# Trigger the workflow on push | |
push: | |
branches: | |
# Push events on main branch | |
- master | |
# The Job defines a series of steps that execute on the same runner. | |
jobs: | |
CI: | |
# Define the runner used in the workflow | |
runs-on: ubuntu-latest | |
steps: | |
# Check out repo so our workflow can access it | |
- uses: actions/checkout@v2 | |
# Step-1 Setup Python | |
- name: Set up Python | |
# This action sets up a Python environment for use in actions | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.8 | |
# optional: architecture: x64 x64 or x86. Defaults to x64 if not specified | |
# Step-2 Install Python Virtual ENV | |
- name: Install Python Virtual ENV | |
run: pip3 install virtualenv | |
#ddd | |
# Step-3 Setup Virtual ENV | |
# https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows | |
- name: Virtual ENV | |
uses: actions/cache@v2 | |
id: cache-venv | |
with: | |
path: venv # what we cache: the Virtual ENV | |
## The cache key depends on requirements.txt | |
key: ${{ runner.os }}-venv-${{ hashFiles('**/requirements*.txt') }} | |
restore-keys: | | |
${{ runner.os }}-venv- | |
# Step-4 Build a Virtual ENV, but only if it doesn't already exist | |
- name: Activate Virtual ENV | |
run: python -m venv venv && source venv/bin/activate && pip3 install -r requirements.txt | |
if: steps.cache-venv.outputs.cache-hit != 'true' | |
- name: remove psycopg2 | |
run: cd ./venv/lib/python3.8/site-packages && rm -r psycopg2 && cd | |
- name: copy custom build psycopg2 | |
run: cd ./psycop2-fix && cp -r psycopg2 ../venv/lib/python3.8/site-packages | |
- name: Create archive of dependencies | |
run: | | |
cd ./venv/lib/python3.8/site-packages | |
zip -r9 ../../../../app.zip . | |
- name: Add API files to Zip file | |
run: cd ./app && zip -g ../app.zip -r . | |
- name: Upload zip file artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: app | |
path: app.zip | |
CD: | |
runs-on: ubuntu-latest | |
needs: [CI] | |
if: github.ref == 'refs/heads/master' && 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 app.zip | |
uses: actions/download-artifact@v2 | |
with: | |
name: app | |
- name: Upload to S3 | |
run: aws s3 cp app.zip s3://fastapifunctions/app.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 MonitorBotApi --s3-bucket fastapifunctions --s3-key app.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 }} |