Docker and docker compose development - CDCgov/prime-simplereport GitHub Wiki

Caution

If you are using a Mac with an M1 chip, this setup will not work, as first noticed on 07/13/2022. When trying to start the frontend, backend, and Nginx containers, it will throw a Function not implemented error. However, the database container will still work.

Intro

For ease of local setup, we have created a docker compose setup, which builds docker images for all the necessary components. It also uses Nginx and mkcert to host the app locally over HTTPS. This setup more closely replicates the code deployed to production and is preferred for testing code in production. DevOps engineers prefer this setup.

Prerequisites

  1. Install docker and docker compose.
  2. Install mkcert
  3. Install Node.js 18 using nvm or your preferred method. This is used for yarn scripts and pre-commit hooks.
  4. Install AdoptOpenJDK 17 using jabba or your preferred method. This is useful for IDE integration (IntelliJ, VS Code, etc.)
  5. Install yarn by running npm install --global yarn.

Starting the app

  1. Clone this repository: git clone [email protected]:CDCgov/prime-simplereport.git
  2. Run yarn install in the root of the repository to install pre-commit hooks using lefthook
  3. Run cp .env.sample .env in the repository's root, then obtain the needed secrets from Azure or another developer. Be sure to set the OKTA_API_KEY environment variable. You can generate an API token for yourself by logging into the Okta Preview admin panel and going into Security > API > Tokens.
  4. Run sudo vim /etc/hosts (or use your editor of choice) and add a line to the bottom with the following contents and save: 127.0.0.1 localhost.simplereport.gov
  5. Follow these steps from GitHub for authenticating to the container registry.
  6. Run yarn start in the root of the repository to start the app
  7. Make your user a support admin by assigning yourself the SR-DEV-ADMINS group in Okta Preview.
  8. When the frontend and backend builds are complete, visit https://localhost.simplereport.gov/app

You should see the support admin page. The application does not yet start with any seed data, so you'll need to add your own organization and facilities. You can create your first org at https://localhost.simplereport.gov/app/sign-up.

Notes

Make sure docker has access to enough resources on your local machine. You'll know it doesn't if you get an error from any of your containers similar to this:

"The build failed because the process exited too early. This probably means the system ran out of memory or someone called `kill -9` on the process."

How to update resource limits on your Mac, and Windows machines.