Backend RESTful API implemented using FastAPI framework deployed using DevOps style CI/CD to AWS with Serverless Framework IaaC tool to multiple envs (dev, test, staging, prod) according to Git Flow rules. Fully automated Continuous Delivery.
CI/CD status:
This simple RESTful API project based on FastAPI is demonstration of multiple modern technologies/methodologies/principles:
make lint
)make security
)make unittest
)make cov
)make deploy
)make e2e-tests
)make load-tests
)make destroy
)make deploy ENV=SIT
)This app template is based on a Serverless Application Framework
make deps
make run
make serverless
command from root directory of this project (or sudo make serverless
if you see EACCES: permission denied
).make deploy
You can work with app on specified stage (environment) ex. dev
, uat
, prd
by passing ENV variable into the
make
commands ex.:
make deploy ENV=dev
make deploy ENV=uat
make deploy ENV=prd
or export ENV
variable in your terminal and use default commands ex.
export ENV=dev
make deploy run
The default stage for the app is equal to current branch name ex. master.
make deploy
will build and deploy infrastructure and code as defined in serverless.yml file:
By default resources are deployed to the default
stage
(environment) based on current branch name ex. master
. Thanks to that multiple users working on separate branches can deploy to
separate AWS resources to avoid resources conflicts.
We have following level of tests in the application:
make code-checks
- checks code syntax using flake8
, black
, isort
and security using bandit
make unittest cov
- trigger all unit tests of the code and show code coveragemake e2e-tests
(NOT IMPLEMETED YET) - behave-based tests runned after deploymentmake schema-tests
- schemathesis-based API schema testsmake contract-tests
- pact-based API contract testsmake load-tests
- locust-based load testsThe CI/CD is based on Makefile targets and is integrated with GitHub Actions to
trigger (however it could be easly integrated with any other CI/CD tool ex.
Jenkins, BitBucket pipelines, GitLab, TravisCI, Bamboo or any other)
It consists of following steps:
You can run all the below steps/commands using one make ci
command
make lint
=> check code syntax using pylint
toolmake security
=> check code security breaches using bandit
toolmake unittest
=> trigger unit tests and show reportmake cov
=> show unit tests code coverageYou can run all the below steps/commands using one make cd
command:
make deploy
=> deploys app to AWSmake e2e-tests
=> run End to End tests on deployed appmake load-tests
=> run Load tests on deployed appmake destroy
=> (optional: works only on GitFlow feature branches) destroy AWSCurrently CI/CD is integrated with GitHub Actions. However you can set it up
quickly with any other CI/CD tool and see pipelines and actions similar to the
ones below.
To run CI/CD pipelines you need to export AWS_KEY
and AWS_SECRET
to the
Secrets
section of your GitHub project:
You can see CI/CD pipelines of project here
Pipelines of GitHub Actions looks like on this picture:
Pipeline steps are configured in pipeline config file
Sample pipeline processing with details of each step can be found when you
click on some of the pipelines in Actions tab.
It should look like on this picture:
We can automatically reformat the code according to black and isort rules:
make format
To create Pull Request, go to Pull Requests and
fo following steps:
develop
(NOT master
)When you follow above actions, the CI/CD pipeline will be triggered automatically and perform all checkings described in CI/CD section above.
When everything will be finished you should see results like here and if
everything is green you can ask your colleague for Code Review.
If something is not green, you should fix it before asking Code Review.
When you Code is reviewed you can click ‘Merge pull request’ and merge it into
develop
branch.