Skip to content

Deployment and Build Processes

Kyle Goodwin edited this page Aug 1, 2022 · 4 revisions

Deployment Notes

The project is composed of 6 services defined in the docker-compose.yml file on the backend repo tb-foudation.

bucket client redis web sidekiq db

Service name Description
bucket Minio File Server
client React build served by Apache
redis Redis object database
web Rails API
sidekiq Rails Background Worker
db Postgres Database

Spin Up Documentation

  1. Clone uwcirg/tb-foundation code into the relevant folder on the CIRG servers filesystem
    1. Ask a CIRG team member ( Ivan or John ) about how the filesystem on the server works
    2. The folder will be based on the TLD (ie. /srv/www/samocare.id )
  2. Create a .env file with all of necessary environment variables declared
    1. TODO: document these in a table somewhere
    2. Ensure that the ports are matched up to the ones that the CIRG team has defined for their TLD mappings in the Apache configuration
  3. Spin up the Docker Compose instance
    1. docker-compose pull ( updates to the latest images )
    2. docker-compose up -d ( attempts to spin up the containers )
  4. Initialize the Rails application
    1. docker-compose exec web bash -c "bundle exec rails db:create” ( creates database )
    2. docker-compose exec web bash -c "bundle exec rails db:schema:load” ( creates tables needed for the application )
  5. Add accounts that are needed for your deployment

Environment Variable Definitions

Example .env file using these definitions can be found here: .sample.env

Variable System Component Explanation Example Value: Possible Values
DEFAULT_LOCALE Shared Sets the default language for text translations in the frontend, and for notification translations on the backend id [en,es-Ar,id]
COMPOSE_FILE Docker-Compose https://docs.docker.com/compose/reference/envvars/#compose\_file
API_DOCKER_TAG Docker-Compose Tag of the image that you want to use for this deployment. Allows you to use images build from specific named branches. develop Images listed here https://hub.docker.com/repository/docker/uwcirg/tb-foundation
PORT_CLIENT Docker-Compose System port to expose client container to 3000
PORT_API Docker-Compose System port to expose Rails API container to 3001
PORT_MINIO Docker-Compose System port to expose Minio to 3002
PORT_REDIS Docker-Compose Internal port for Redis 3003
URL_API Docker-Compose Final base url for API https://api.domain.com
URL_CLIENT Docker-Compose Final base url for Client https://domcain.com
REDCAP_EOT_SURVEY_LINK Front End Link to end of trial survey
MANIFEST_NAME Front End Name to display in app manifest. This is modified in the entrypoint for the client container
MANIFEST_ICONS_FOLDER Front End Path to a folder in the public folder that contains icons used when installing a PWA on a users device home-screen. Set at container up time, outside of the React build process /logos/id [/logos/id,/logos/ar]
HTML_APP_TITLE Front End Set the HTML title tag at container up time, outside of the React build process
INDONESIA_PILOT_FLAG Front End Used to filter out certain features that are only available in Spanish, or enable features only used by the Papua study
POSTGRES_PASSWORD Back End
ENVIRONMENT Back End
MINIO_ACCESS_KEY Back End
MINIO_SECRET_KEY Back End
RAILS_BASE_PASS Back End
VAPID_PUBLIC_KEY Back End
VAPID_PRIVATE_KEY Back End
DEPLOY_TIME_ZONE Back End
CORS_ORIGINS Back End
SECRET_KEY_BASE Back End

Docker Build Process

The React app has been dockerized to make deployment work more easily with docker-compose. Here is an article that explains why we use a multi-stage build, please note that this project uses Apache instead of Nginx so the Dockerfile is a bit different.

Some additions have been made to this process to add dynamic environment variables that depend on the docker-compose env of the deployment. This makes it possible to have multiple deployments with different settings without baking those variables into the image at build time.

Visual Explanation ( In progress need to update )

Environment Documentation

Stage One: Node Container

  • yarn build is run in the dockerfile
  • Some env variables are baked into the build
    • REACT_APP_BUILD_NUMBER
    • REACT_APP_GITHUB_VERSION

These are used to show a meaningful version within the app that is linked to git commit and tags Files output to /build folder

Stage Two: Apache Container

  • Files from stage one /build are copied into the default apache folder for serving
  • When the container is spun up ( ie. docker-compose up client ) the entrypoint command allows you to run scripts before the container goes up.