Booking microservice for BookBNB
This project was built with poetry in mind as the means to manage dependencies. You can follow their install guide to install it.
Having poetry installed, the following command will install the project into a new environment.
poetry install
Keep in mind that this will by default install the base requirements as well as the dev requirements.
To install the testing
extras, run:
poetry install -E testing
Remember to commit to the repo the poetry.lock
file generated by poetry install
.
We use pre-commit to run several code scans and hooks that make the development cycle easier.
pre-commit install
pre-commit install -t push
Check the full poetry docs, but here goes a quick reminder,
poetry add <dependency> [--dev]
Always remember to commit changes to poetry.lock
!
We use SemVer. To keep things easy, dev dependencies include bump2version . Running poetry run bump2version minor
will bump the minor version.
poetry run bump2version <part>
In order to bootstrap dependencies and run several actions, we are using nox. This way, dependencies are isolated and you get environment replicability.
To run all sessions,
nox
To run tests session,
nox --sessions tests [-- pylint arguments]
To run linting session,
nox --sessions cop
To run bandit session,
nox --sessions bandit
To run pyreverse session,
nox --sessions pyreverse
booking_microservice follows PEP8.
If you installed the pre-commit hooks you shouldn't worry too much about style, since they will fix it for you or warn you about styling errors. We use the following hooks:
- black: An opinionated code formatting tool that ensures consistency across all projects using it
- flake8: a tool to enforce style guide
- mypy: a static type checker for Python
- pylint: a source code, bug and quality checker
We use either numpy style or google style docstring formatting. It's usually good to include the following docstrings:
- module level docstring giving a general overview of what it does.
- class dosctrings explaining what it is
- method/functions to explain what it does and what it's parameters are
We use the pytest framework to test booking_microservice. The easiest way to run tests it through nox
with nox --sessions tests
.
Get everything up and running.
cd docker-compose
docker-compose build
docker-compose up
You will need to have the heroku cli installed and correctly configured for the following steps.
Prior to the actual deploy, make sure to commit your changes.
heroku create booking_microservice
heroku addons:create heroku-postgresql:hobby-dev
heroku stack:set container
git push heroku master
- The first step initializes a new heroku app
- The second step provisions a postgres addon
- The third step sets the app to use a docker image. Instead of using a Procfile, we will use a
heroku.yml
. Heroku does not yet support a poetry buildpack and exporting arequirements.txt
from poetry is pretty cumbersome. - Deploy 🚀
You can fetch logs from the app using heroku logs --tail
.
Go to the app on the Heroku Dashboard. On the deploy tab, select "Connect to github" under the "Deployment method" section. Select your repo and you're good to go. Pushes to master will deploy a new version.
Free dynos sleep after 30 min if no incoming web traffic is received. It might take a while, but you should be able to see the app's swagger the root URL. Use the "Open App" button on the dashboard.
The heroku Dockerfile includes the DataDog agent. Create a new DataDog API Key from here. Remember to set the following config vars:
heroku config:set DD_API_KEY=<your_api_key>
heroku config:set DD_DYNO_HOST=false
heroku config:set HEROKU_APP_NAME=bookbnb5-bookings
heroku config:set DD_TAGS=service:booking_microservice
A few pipelines have been set to run on github actions to ensure code quality.
This workflow runs linters and tests.
You can visit the swagger docs at 127.0.0.1:5000
.