Skip to content

Commit

Permalink
dev: doc/template updates for initial setup
Browse files Browse the repository at this point in the history
* Adds a version of the same `pull_configs.sh` script added to Screens
  earlier. This replaces a couple "ask another engineer for this file"
  setup steps, and removes the requirement to have AWS credentials set
  up in environment variables for `fetch_places_and_screens.exs`.

* Provides (what I hope are) reasonable default values for URLs and
  other non-sensitive items in `.envrc.template`. This cuts down the
  values that must be filled in as part of setup to just a V3 API key.

* Remove the root `package.json` that "proxied" some `npm` commands to
  the one in `assets`. It doesn't appear this was widely used, since
  using it generates a `package-lock.json` that was never committed.
  • Loading branch information
digitalcora committed Apr 29, 2024
1 parent 7e7f207 commit 423027f
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 41 deletions.
24 changes: 13 additions & 11 deletions .envrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
# and fill in any additional values you need. Will be automatically loaded and
# unloaded by `direnv` if installed, or execute manually using `source .envrc`.

# export ALERTS_UI_URL=
export API_V3_KEY=
export API_V3_URL="https://api-v3.mbta.com"
# export AWS_ACCESS_KEY_ID=
# export AWS_SECRET_ACCESS_KEY=
# export ENVIRONMENT_NAME=
# export FULLSTORY_ORG_ID=
export GUARDIAN_SECRET_KEY="test_auth_secret"
export SCREENS_URL="https://screens.mbta.com"
export SECRET_KEY_BASE="local_secret_key_base_at_least_64_bytes_________________________________"
# export SFTP_HOST=
# export SFTP_USER=
# export SFTP_REMOTE_PATH=
# export SFTP_LOCAL_PATH=
# export SECRET_KEY_BASE=
# export GUARDIAN_SECRET_KEY=
# export API_V3_KEY=
# export API_V3_URL=
# export FULLSTORY_ORG_ID=
# export ENVIRONMENT_NAME=
# export SCREENS_URL=
# export SIGNS_UI_URL=
# export ALERTS_UI_URL=
# export SFTP_REMOTE_PATH=
# export SFTP_USER=
export SIGNS_UI_URL="https://signs.mbta.com"
59 changes: 41 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
# Screenplay

This tool enables PIOs to upload urgent messages to the Outfront signs in and outside stations.
Enables OIOs to view and manage screens that provide transit info to riders.

## Development

To start your Phoenix server:
## Setup

- Set required env variables with
- `export SECRET_KEY_BASE=`. You can use the value in `config.exs`.
- `export GUARDIAN_SECRET_KEY=test_auth_secret`
- URLs for other MBTA APIs that Screenplay communicates with. **Make sure to use the same environment for all!**
- `export API_V3_URL="https://api-v3.mbta.com"` (or another environment's URL if you want to fetch data from there instead)
- `export SCREENS_URL="https://screens.mbta.com"` (or another environment's URL if you want to fetch data from there instead)
- Add a `places_and_screens.json` file to the `priv/config` directory. You can generate this file by running `API_V3_KEY=<your_key_here> mix run scripts/fetch_places_and_screens.exs --environment dev`.
- Add a `screen_locations.json` file to the `priv/config` directory. You can either ask an engineer for a copy of the file, or enter an empty array as its contents (`[]`). The file just needs to exist and contain an array of 0 or more `{"id": "<screen ID>", "location": "<location description>"}` objects.
- Add a `place_descriptions.json` file to the `priv/config` directory. You can either ask an engineer for a copy of the file, or enter an empty array as its contents (`[]`). The file just needs to exist and contain an array of 0 or more `{"id": "<place ID>", "description": "<place description>"}` objects.
- Install dependencies with `mix deps.get`
- Install Node.js dependencies by running `npm run install`
- Start Phoenix endpoint with `API_V3_KEY=<your-key-here> mix phx.server`
#### Install tools

If you want to develop on Screenplay with a local version of the Screens app, just spin up Screens (which will be at http://localhost:4000) and change the dev baseUrl in ScreenDetail.tsx to use that port 4000 url.
1. Install [`asdf`](https://github.com/asdf-vm/asdf)
1. Install language build dependencies: `brew install coreutils`
1. `asdf plugin-add ...` for each tool listed in `.tool-versions`
1. `asdf install`

Now you can visit [`localhost:4444`](http://localhost:4444) from your browser.
#### Set up environment

You may want to add `export API_V3_KEY=<your-key-here>` to your shell config so that you don't have to specify it each time you run `mix phx.server`.
1. Install [`direnv`](https://direnv.net/)
1. `cp .envrc.template .envrc`
1. Fill in `API_V3_KEY` with a [V3 API key](https://api-v3.mbta.com/)
1. `direnv allow`

Note the various `_URL` values in `.envrc`, which default to the production
environments of the relevant apps — change these to e.g. point Screenplay to
your own local instances.

#### Copy configuration

1. Install the `aws` CLI and configure with your AWS credentials
- To verify everything works, try: `aws s3 ls mbta-ctd-config`
1. Run `scripts/pull_configs.sh prod`

To copy config files from a different Screenplay environment, replace `prod` in
the command above.

#### Start the server

1. `mix deps.get`
1. `npm install --prefix assets`
1. `mix phx.server`
1. Visit <http://localhost:4444>

#### Optional: AWS credentials

In deployed environments, the app uses S3 for its configuration. If you ever
want to replicate this behavior locally, you'll need to provide the environment
variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. For security reasons
these should only be [stored in 1Password][1] and not directly in your `.envrc`.

[1]: https://www.notion.so/mbta-downtown-crossing/Storing-Access-Keys-Securely-in-1Password-b89310bc67784722a5a218500f34443d?pm=c
12 changes: 0 additions & 12 deletions package.json

This file was deleted.

35 changes: 35 additions & 0 deletions scripts/pull_configs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh

# Copies live configuration from S3 to the local paths expected by `LocalFetch`
# modules.

set -eu

if [ $# -eq 0 ]; then
echo "Usage: $0 <screenplay-env-name>" >&2
exit 1
fi

case $1 in
prod | dev | dev-green) true;;
* )
echo "Environment should be: prod | dev | dev-green" >&2
exit 2
;;
esac

maybe_cp() {
if [ -e "$2" ]; then
printf '%s' "Overwrite $2? "
read -r answer
case $answer in
[Yy]* ) aws s3 cp "$1" "$2";;
* ) echo "Skipped.";;
esac
fi
}

maybe_cp s3://mbta-ctd-config/screenplay/"$1".json priv/alerts.json
maybe_cp s3://mbta-ctd-config/screenplay/"$1"/place_descriptions.json priv/config/place_descriptions.json
maybe_cp s3://mbta-ctd-config/screenplay/"$1"/places_and_screens.json priv/config/places_and_screens.json
maybe_cp s3://mbta-ctd-config/screenplay/"$1"/screen_locations.json priv/config/screen_locations.json

0 comments on commit 423027f

Please sign in to comment.