Skip to content

MariaShears/time_to_planet

Repository files navigation

Time To Planet API

An api for that calculates the time it would take for a message sent from Earth to a planet in our solar system.

you can check the CHANGELOG to see all the releases

Tech

time_to_planet is a micro python flask api

Currently the api is basically a wrapper over the http:https://astronomyapi.org. In the future we may calculate the distance from earth to planets ourselves.

Dev

Links

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=time_to_planet.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

Running mock astronomyapi server:

Currently we get out distance numbers to calculate time from an external api. To mock this on local we use a node module, json-server.

$ npx json-server --watch astronomy_api_mock.json

Install existing packages:

$ pipenv sync

Format Code:

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

How to deploy

  1. bump version in deploy/deployment.yml
diff --git a/deploy/deployment.yml b/deploy/deployment.yml
index 4595860..0ae4bfe 100644
--- a/deploy/deployment.yml
+++ b/deploy/deployment.yml
@@ -43,7 +43,7 @@ spec:
             configMapKeyRef:
               key: ASTRONOMYAPI_URL
               name: time-to-planet-config
-        image: registry.gitlab.com/btbtravis/time_to_planet:0.0.1
+        image: registry.gitlab.com/btbtravis/time_to_planet:0.0.2
         imagePullPolicy: IfNotPresent
         name: time-to-planet-api
         ports:
  1. build docker image
$ docker build -t registry.gitlab.com/btbtravis/time_to_planet:0.0.2 -f ./deploy/Dockerfile .
  1. push docker image to container repository
$ docker push registry.gitlab.com/btbtravis/time_to_planet:0.0.2
  1. update image in live deployment
$ kubectl create -f ./deploy/deployment.yml