Skip to content

Commit

Permalink
Add design review script for eCR Viewer (#2298)
Browse files Browse the repository at this point in the history
* add design review script for eCR Viewer

* modify script to work for ecr-viewer and add is-non-integrated env var

* clean design review script and modify README

* respond to code review

* testing execute permissions

* update initial setup command and update readme for clarification
  • Loading branch information
angelathe authored Aug 2, 2024
1 parent 7632e9f commit aa6012f
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
31 changes: 31 additions & 0 deletions containers/ecr-viewer/design-review/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Design Review Script

A bash script intended to allow designers and members of the team to easily spin up an instance of the eCR Viewer on their local machines for UI/UX review. Currently only MacOS is supported.

## Initial Setup

In order to use this script a copy must be downloaded onto your computer from GitHub. To do this follow these instructions.
1. Open the Terminal application.
2. Copy and paste the following command into the Terminal prompt and press enter.
```
curl https://raw.githubusercontent.com/CDCgov/phdi/main/containers/ecr-viewer/design-review/design-review.sh -O && chmod +x design-review.sh
```
- The first command uses the wget program to download a copy the `design-review.sh` file from this directory to the root level of your user directory e.g. `Users/johndoe`.
- The second command (`chmod +x design-review.sh`) assigns executable permissions to `design-review.sh` allowing it to be run.


## Usage

Follow these steps to run script and spin up a local instance of the eCR Viewer.

1. Ensure you have completed the initial setup instructions.
2. Open the Terminal application.
3. Copy and paste `./design-review.sh <MY-BRANCH> <IS_NON_INTEGRATED>` into the Terminal prompt.
4. Replace `<MY-BRANCH>` with the name of the GitHub branch you would like to conduct a review on.
- For example, `./design-review.sh main` will spin up an instance of the eCR Viewer based on the current state of the `main` branch of repository.
5. Replace `<IS_NON_INTEGRATED>` with either `true` or `false`.
- Setting it to `true` will show the non-integrated version of the eCR Viewer, while setting it to `false` will show the integrated version.
- If any other text is used for this second argument, an error message will be displayed: `Invalid value for IS_NON_INTEGRATED. It must be 'true' or 'false'`.
6. Press enter. The script will now ensure that all required dependencies are installed on your machine, build and run the eCR Viewer, and finally navigate to the landing page in your system's default browser. Please note that because certain dependencies may need to be installed the script make take a few minutes the first time it is run on a machine. Additionally, depending on what needs to be installed you may be prompted at points during installation of dependencies to provide a password or click through some installation screens.
- Note: If the landing page of the eCR Viewer displays `Something went wrong!`, try reloading the page to resolve the error.
7. When you are done with your review to shut the eCR Viewer down return to Terminal and press enter.
91 changes: 91 additions & 0 deletions containers/ecr-viewer/design-review/design-review.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash

# Check if branch name is provided
if [ -z "$1" ]; then
echo "Usage: $0 <branch-name>"
exit 1
fi

BRANCH_NAME=$1

# Check if the value indicating whether to view the non-integrated viewer is provided/valid
if [ -n "$2" ]; then
if [[ "$2" == "true" || "$2" == "false" ]]; then
IS_NON_INTEGRATED=$2
else
echo "Invalid value for IS_NON_INTEGRATED. It must be 'true' or 'false'."
exit 1
fi
else
IS_NON_INTEGRATED=true
fi

# Function to check if a command exists
command_exists() {
command -v "$1" &> /dev/null
}

# Install Homebrew if it's not already installed
if ! command_exists brew; then
echo "Homebrew not found, installing it now..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi

# Update Homebrew
brew update

# Install Git if it's not already installed
if ! command_exists git; then
brew install git
fi

# Install Docker if it's not already installed
if ! command_exists docker; then
brew install --cask docker
fi

# Start Docker
open /Applications/Docker.app
echo "Waiting for Docker to launch..."
while ! docker system info > /dev/null 2>&1; do
sleep 1
done

# Clone the repository if it doesn't exist, otherwise pull the latest changes
REPO_URL="https://github.com/CDCgov/phdi.git"
REPO_DIR="phdi"

if [ ! -d "$REPO_DIR" ]; then
git clone $REPO_URL
cd $REPO_DIR
else
cd $REPO_DIR
git pull
fi

cd ./containers/ecr-viewer

# Checkout the specified branch
git checkout $BRANCH_NAME

# Write env vars to .env.local
echo "APP_ENV=test" > .env.local
echo "DATABASE_URL=postgres://postgres:pw@db:5432/ecr_viewer_db" >> .env.local
echo "NEXT_PUBLIC_NON_INTEGRATED_VIEWER=$IS_NON_INTEGRATED" >> .env.local

# Build and run docker compose
docker compose --env-file .env.local up -d ecr-viewer db --build

# Wait for eCR Viewer to be available
URL="http://localhost:3000/"
while ! curl -s -o /dev/null -w "%{http_code}" "$URL" | grep -q "200"; do
echo "Waiting for $URL to be available..."
sleep 5
done

# Open in default browser
open http://localhost:3000/

# Prompt to end review session
read -p "Press enter to end review"
docker compose down -v

0 comments on commit aa6012f

Please sign in to comment.