greenelab / word-lapse

Explore how a word changes over time
https://greenelab.github.io/word-lapse/
Other
6 stars 3 forks source link

Server dockerization #11

Closed falquaddoomi closed 2 years ago

falquaddoomi commented 2 years ago

This PR adds the following to the ./server directory:

The PR also adds a GH action to build and deploy the Docker image to the Word Lapse API VM when a push to main affects the ./server folder. The action relies on the secrets GCE_PROJECT and GCP_CREDENTIALS, both of which have been registered as secrets in the GitHub project settings.

The entrypoint script does the following:

  1. If /app/data is empty, clones https://github.com/greenelab/word-lapse-models into that folder. If it's not empty it performs an LFS pull in that folder. (This behavior can be disabled by setting the env var UPDATE_DATA to 0.)
  2. If /etc/letsencrypt/ is empty, uses Let's Encrypt to create a certificate for api-wl.greenelab.com. If it's not empty, it attempts to renew the certificate, which is a no-op if the certificate doesn't need renewal. (This behavior can be disabled by setting the env var USE_HTTPS to 0.)
  3. Starts uvicorn, a performant WSGI-hosting webserver, to serve the API. If USE_HTTPS is unspecified, runs the server on port 443 with SSL using the certificate; if USE_HTTPS is 0, runs the server on port 80 without SSL.

The build script does the following:

  1. If the env var BUILD_LOCAL is 1, builds the image locally and pushes it to gcr.io/word-lapse/word-lapse-api-image:${COMMIT_SHA}, where COMMIT_SHA is the latest commit hash in the server folder.
  2. If BUILD_LOCAL is unspecified, performs a remote build using Google's Cloud Build service, then deploys the image to the Word Lapse API server, restarting it if it's running or updating its metadata without starting it if it's stopped.
    • If the env var SKIP_BUILD is set for a remote build, the Cloud Build step is skipped.
    • If SKIP_DEPLOY is 1, skips updating the API VM.

Data notes: