rebus-ink / ink-API

Hobb API Server: backend for the Rebus Reader system
GNU Affero General Public License v3.0
4 stars 5 forks source link

Get database working on DigitalOcean #727

Open Marie000 opened 2 years ago

Marie000 commented 2 years ago

The API is working on digitalOcean but not connecting to the database.

Some things to look at:

nicholasjhenry commented 2 years ago

I can confirm the droplet ink-API-dev is now connected to a managed instance of PostgreSQL.

Actions completed

  1. Created a managed postgres database cluster ink-api
  2. Secured by making open to connections from ink-API-dev and ink-API-prod only
  3. Created ink_dev and ink_prod databases
  4. Updated the DB configuration to use a connection string allowing to configure port and simplifies configuration by reducing five params to one; plus configuring a DB CA Certificate, used on Digitial Ocean.
  5. Move all configuration under /etc/rebus-ink-api; renamed .env to env and placed the DB certificate there too
  6. Tested migrations can be run with docker exec ink-api npx knex migrate:latest.
  7. Deleted the postgres-data volume now we are using a managed postgres cluster.

Useful commands

docker run -d -p 8080:8080 --restart=always --env-file /etc/rebus-ink-api/env -e DATABASE_CA_CERT="$(cat /etc/rebus-ink-api/ca-certificate.crt)" --name ink-api rebusink/ink-api

docker exec ink-api npx knex migrate:latest

Deployment Dev

Recommendation to start using tags e.g.

build (local):

git checkout dev
git pull
docker image build -t rebusink/ink-api:dev-20220629a .
docker image push rebusink/ink-api:dev-20220629a

release (ink-API-dev):

docker pull rebusink/ink-api:dev-20220629a
docker run  ink-api npx knex migrate:latest TODO ????

run (ink-API-dev):

docker restart ink-api

If environment vars have changed you'll need to stop and start the container.