Skip to content

Dev Workflow

Jordan Lees edited this page May 15, 2024 · 15 revisions

Devcontainer (recommended workflow)

To use the new Docker workflow, make sure to have Visual Studio Code and Docker Desktop installed. (MongoDB Compass is additionally recommended but not required.)

Special note: If you only have 8GB of RAM (as opposed to 16 or more), it's recommended that you specifically instruct WSL (Windows Subsystem for Linux) to use fixed amounts of memory - see the ** note at the bottom of this page.

Next:

  1. Start VS Code and run Dev Containers: Clone Repository in Named Container Volume... from the Command Palette (F1). [name it Scoutradioz]
  2. And then enter the repo url
  3. It'll take a while for the container to set up. Once it's ready, open a new terminal window (Ctrl + `) and then run yarn dev. It may take a while to get started, but the website should launch and be accessible at http://localhost:3000.

As part of the docker setup process, a trimmed-down snapshot of the Scoutradioz database will be imported into a new volume on your local machine. This snapshot has data originally recorded from The Gearheads, but with all personal information removed and randomized usernames. The default org password is password. All users except for 00 Dev Account are set to the Scouter permission level. Log in to 00 Dev Account and choose a password, and then that account will have Global Admin permission levels.

The one major feature missing in the database snapshot is an API key for The Blue Alliance, so you will not be able to fetch data from TBA until you do the following:

  1. Create a TBA account: https://www.thebluealliance.com/account
  2. After signing in, navigate to Read API Keys. Create a new key and then copy the key (should look something like Eejoa6qcahNOAhgMyMtkbU5cNt4bvPmt2r5XAl2a8f0XNdmNbYsLnosZnlOQijST)
  3. Add the TBA Auth key to the database by doing the following:
    1. While the database is running, connect to mongodb://localhost:27017 and navigate to the app database.

    2. Click on the + button to create a collection. Name it passwords. image

    3. Next, click Add Data -> Insert document.

    4. Delete the existing { _id } junk and paste this in, but inserting the TBA key you copied earlier:

    {
        "name": "tba-api-headers",
        "headers": {
            "accept": "application/json",
            "X-TBA-Auth-Key": "(PASTE IN YOUR KEY HERE)"
        }
    }
    
    1. And lastly, press Insert. (MongoDB will still automatically create a new _id field for that entry anyways.)

Check *Info on the developer script at the bottom for more info on what happens behind the scenes with yarn dev.

Visual Studio Code

  1. Open Visual Studio Code
  2. If ScoringApp-Serverless is not already open: File > Open Folder or Ctrl + K, Ctrl + O; then open the folder containing this repository
  3. Ctrl + ` to open terminal
    1. Make sure either PowerShell or cmd is selected in the dropdown
    2. If this is the first time setting up, enter yarn setup (in the background, it runs yarn install in the project root and all 3 main Express functions)
    3. If this is NOT the first time setting up, Enter yarn update to update the internal packages linked within this repository (scoutradioz-utilities, etc.)
    4. Enter yarn dev to run the developer script*.
  4. To edit files, browse in the Explorer tab (Ctrl + Shift + E) and open by left-clicking once.

For developers with access to the production database:

If you need to update your local database from prod

  1. Make sure mongod is running
  2. In Compass, connect to mongodb://127.0.0.1:27017/
  3. In Compass, drop the app database
  4. Open PowerShell or bash in some temporary folder that is NOT connected to an automatic cloud backup service
  5. Enter mongodump --uri "{Full connection string to prod database}" --db prod
  6. Enter mongorestore ./dump/prod --db app
  7. Close cmd or PowerShell

If you need to update QA or Test from Prod

  1. Open PowerShell or bash in some temporary folder that is NOT connected to an automatic cloud backup service
  2. Delete ./dump/prod and ./dump/qa / ./dump/test if they exist
  3. Back up QA or Test:
    • mongodump --uri "{Full connection string to qa or test database}"
  4. Download prod:
    • mongodump --uri "{Full connection string to prod database}"
  5. Connect to the remote database cluster in Compass
  6. Drop the QA or Test database
  7. Back in PowerShell or bash, enter mongorestore --uri "{Full connection string to QA or Test database}" --db {qa or test} ./dump/prod to upload the contents of ./dump/prod (the prod database download) to the QA or Test database

* Info on the developer script:

  1. It will run all necessary scripts and commands inside child threads:
    • MongoDB
    • Compilation of static TS->JS files, in watch mode
    • Compilation of static LESS->CSS files, in watch mode
    • The two main Express functions (Primary and Upload)
  2. If you get an MongoDB error: Check C:\data\db. If it does not exist, create it.
    • If you wish to change where your database is located, set an environment variable MONGODB_PATH to specify where the database should be opened.
  3. To restart Primary and Upload, simply type rs into the console and press enter.

** If you only have 8GB of RAM:

  1. Open File Explorer and navigate to C:\Users\{yourWindowsUsername}
  2. Create a file called .wslconfig (NB, it must start with a period '.' character!)
  3. In this file put the following contents:
[wsl2]
memory=5GB
processors=4
swap=6GB

(tune as needed)