~travisshears/corona-cal-api

Python + Flask + Redis Backend for my Online Events Calendar Project
75cb947b — Travis Shears 3 years ago
docs: add LICENSE and update main docs
74ac4ed5 — Travis Shears 3 years ago
feat(deploy): add helm chart
b473b4ca — Travis Shears 3 years ago
fix(app): update for work with new version of k8s

clone

read-only
https://git.sr.ht/~travisshears/corona-cal-api
read/write
git@git.sr.ht:~travisshears/corona-cal-api

You can also use your local clone with git send-email.

#Corona Cal API

An api wrapper over an airtable that stores online events to do in times of Corona. The api is called by the Svelte frontend app on my personal site.

*note I'm no longer activity working on this project so the source code here acts as an archive

#Tech

Corona Cal is a micro python flask api that utilizes redis as a caching layer.

#Dev

Helpful links:

#Versioning

This api is visioned with following the Semantic Versioning convention. Versions can be seen in the CHANGELOG or under tags. In order to make this possible we ask our developers to:

  • Follow conventionalcommits convention when committing
    • ex. feat(caching): add second cache key
    • ex. fix(time_calc): multiple to get seconds
    • ex. docs: init README.md
    • ex. refactor: init pprint module for printing json
    • ex. test(remote_api): test valid cache flow
    • ex. deploy(0.0.1): ship mvp
  • If PR makes significant changes bump version
  • When bumping version make sure to update CHANGELOG and apply tag to deploy commit that updates deployment.yml
    • ex. deploy(0.0.1): ship mvp

#Generate API documentation

The API documentation lives right here in the repo under the docs folder.

It is based off our open_api_doc.yaml file and generated with the following command:

openapi-generator generate -i open_api_doc.yaml -g markdown -o ./docs

Documentation tooling links:

#CLI Commands

Run app:

$ FLASK_APP=corona_cal.py flask run

Virtual Env:

Init virtual env with:

$ python3 -m venv venv

Then to activate it

$ source ./venv/bin/activate

Unit Testing:

Run Unit tests with:

$ python -m unittest

Installing new packages:

$ pipenv install requests

Then afterward update the requirements.txt with

$ pip freeze > requirements.txt

Install existing packages:

$ pipenv sync

Format Code:

$ autopep8 --in-place --aggressive --aggressive ./app/**/*.py

#How to deploy

This project deploys docker + k8s.

  1. First build a docker image
$ docker build -t registry.gitlab.com/btbtravis/corona_cal:0.4.0 -f deploy/Dockerfile .
  1. Then push the image to a container registry
$ docker push registry.gitlab.com/btbtravis/corona_cal:0.4.0
  1. Now that the image is available the k8s resources can be installed via the helm chart
$ helm install corona-cal ./corona-cal-chart --set version=0.4.0
  1. To upgrade it is easy
$ helm upgrade corona-cal ./corona-cal-chart --set version=0.4.1

Thats it you should have the needed deployment and service resources. One still needs to configure ingress of course but that is highly dependent on how your cluster is setup.

In the event you want to remove the resources that can be done all at once via:

$ corona_cal git:(master)  helm uninstall corona-cal
release "corona-cal" uninstalled