Skip to content

Latest commit

 

History

History
107 lines (66 loc) · 4.1 KB

README.md

File metadata and controls

107 lines (66 loc) · 4.1 KB

App Microservice

Deployment

Run in Postman

Development

Docker

Development can be done in Docker without any external dependencies using docker-compose.

For the first time running, you can bootstrap the local development environment with bin/bootstrap.sh.

After that, you can manage the environment with standard docker-compose commands. A few of the more common commands are listed below.

Action Command
Bootstrap environment $ bin/bootstrap.sh
Start environment $ docker-compose start
Stop environment $ docker-compose stop
Attach to logs $ docker-compose logs -f
Python shell $ docker-compose exec django ./manage.py shell
Apply DB Migrations $ docker-compose exec django ./manage.py migrate
Make DB Migrations $ docker-compose exec django ./manage.py makemigrations
Destroy environment $ docker-compose down -v

Native

If you prefer not to develop with Docker, you can run the app natively on your system.

Dependencies:

Steps:

  • $ brew install python pipenv
  • $ brew install mysql 1
  • $ brew install mysql-connector-c 2
  • $ export PIPENV_VENV_IN_PROJECT=1
  • $ pipenv sync --dev
  • $ pipenv run app_microservice/manage.py runserver

1 Make sure the MySQL service is running, and configure an appropriate database.

2There is a bug with the MySQL python bindings on Mac OSX. See: https://pypi.org/project/mysqlclient/

Editor Setup

To install the pre-commit hooks that check and fix:

  • trailing whitespaces
  • file endings (forcing new lines)
  • PE8 compliance
  • style guide compliance

please run:

$ pipenv run pre-commit install

For VSCode, an appropriate settings.json is shipped as part of this repository.

Deployment

This project includes a GitHub workflow for deployment to Google Cloud Run. To do so, perform the following steps:

  1. Create a new service account (SA) via: IAM & Admin > Service Accounts > Create Service Account

  2. Grant permissions via IAM & Admin > IAM > Permissions > Edit SA (from above) > Add another role

  • Service Account User
  • Cloud Run Admin
  1. Generate a service account key via IAM & Admin > Service Accounts > Actions > Create key > type: JSON

  2. Add GitHub secrets

  • GCP_PROJECT_ID: <your-project>
  • GCP_SA_KEY: <JSON-contents-from-above>
  1. Enable the Google Cloud Run Admin API

  2. Deploy via GitHub Actions

  3. Allow public access via Cloud Run > app-api service > Permissions > Add > members: allUsers / role: Cloud Run Invoker

Persistence

This project relies on a relational database for permanently storing data. To provision such a database on Google Cloud:

  1. Enable the Cloud SQL Admin API

  2. Create a new Cloud SQL instance via: SQL > Create Instance > MySQL v8 with a public IP

  3. Create a new database via: SQL > Select previously created instance > Databases > Create database

  4. Update the app.service.yaml deployment specification accordingly:

  • Environment variables starting with DJANGO_DATABASE_
  • run.googleapis.com/cloudsql-instances metadata annotation