diff --git a/README.md b/README.md index 0b0342805..322908085 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,26 @@ The [Notify API](https://github.com/GSA/notifications-api) provides the UI's bac ## Local setup -If you are using VS Code, there are also instructions for [running inside Docker](./docs/docker-remote-containers.md) +### Common steps + +1. Install pre-requisites for setup: + * [jq](https://stedolan.github.io/jq/): `brew install jq` + * [terraform](https://www.terraform.io/): `brew install terraform` or `brew install tfenv` and use `tfenv` to install `terraform ~> 1.4.0` + * [cf-cli@8](https://docs.cloudfoundry.org/cf-cli/install-go-cli.html): `brew install cloudfoundry/tap/cf-cli@8` +1. [Log into cloud.gov](https://cloud.gov/docs/getting-started/setup/#set-up-the-command-line): `cf login -a api.fr.cloud.gov --sso` +1. Ensure you have access to the `notify-local-dev` and `notify-staging` spaces in cloud.gov +1. Run the API setup steps +1. Run the development terraform with: + + ``` + $ cd terraform/development + $ ./run.sh + ``` + +1. If you want to send data to New Relic from your local develpment environment, set `NEW_RELIC_LICENSE_KEY` within `.env` +1. Follow the instructions for either `Direct installation` or `Docker installation` below + +### Direct installation 1. Get the API running @@ -23,19 +42,16 @@ If you are using VS Code, there are also instructions for [running inside Docker `make bootstrap` -1. Create the .env file - - ``` - cp sample.env .env - # follow the instructions in .env - ``` - 1. Run the Flask server `make run-flask` 1. Go to http://localhost:6012 +### Docker installation + +If you are using VS Code, there are also instructions for [running inside Docker](./docs/docker-remote-containers.md) + ## To test the application From a terminal within the running devcontainer: diff --git a/docs/docker-remote-containers.md b/docs/docker-remote-containers.md index 50d30a863..22099c870 100644 --- a/docs/docker-remote-containers.md +++ b/docs/docker-remote-containers.md @@ -4,12 +4,7 @@ If you're working in VS Code, you can also leverage Docker for a containerized d 1. Get the API running, including the Docker network -1. Create the .env file - - ``` - cp sample.env .env - # follow the instructions in .env - ``` +1. Uncomment the `Local Docker setup` lines in `.env` and comment out the `Local direct setup` lines. 1. Install the Remote-Containers plug-in in VS Code @@ -23,4 +18,4 @@ If you're working in VS Code, you can also leverage Docker for a containerized d 1. Go to http://localhost:6012 -NOTE: when you change .env in the future, you'll need to rebuild the devcontainer for the change to take effect. VS Code _should_ detect the change and prompt you with a toast notification during a cached build. If not, you can find a manual rebuild in command pallette or just `docker rm` the notifications-api container. \ No newline at end of file +NOTE: when you change .env in the future, you'll need to rebuild the devcontainer for the change to take effect. VS Code _should_ detect the change and prompt you with a toast notification during a cached build. If not, you can find a manual rebuild in command pallette or just `docker rm` the notifications-api container. diff --git a/sample.env b/sample.env index edb32dc7b..2f83e2c20 100644 --- a/sample.env +++ b/sample.env @@ -1,15 +1,4 @@ -# STEPS TO SET UP -# -# 1. Copy this file to `.env` -# -# 2. If trying to send data to New Relic in development (monitor_mode: true), -# pull down NEW_RELIC_LICENSE_KEY from cloud.gov using `cf env`, then update New Relic section -# -# 3. Uncomment either the Docker setup or the direct setup -# -# 4. Comment out the other setup -# -# 5. Run `cd terraform/development; ./run.sh` to include service credentials in `.env` +# See README.md for local setup instructions # ## REBUILD THE DEVCONTAINER WHEN YOU MODIFY .ENV ### diff --git a/terraform/create_service_account.sh b/terraform/create_service_account.sh index cee07591e..b4c44e705 100755 --- a/terraform/create_service_account.sh +++ b/terraform/create_service_account.sh @@ -19,14 +19,15 @@ Options: Notes: * OrgManager is required for terraform to create -egress spaces -* Requires cf-cli@8 +* Requires cf-cli@8 & jq " cf_version=`cf --version | cut -d " " -f 3` if [[ $cf_version != 8.* ]]; then - echo "$usage" + echo "$usage" >&2 exit 1 fi +command -v jq >/dev/null || { echo "$usage" >&2; exit 1; } set -e set -o pipefail @@ -61,17 +62,17 @@ while getopts ":hms:u:r:o:" opt; do done if [[ $space = "" || $service = "" ]]; then - echo "$usage" + echo "$usage" >&2 exit 1 fi -cf target -o $org -s $space 1>&2 +cf target -o $org -s $space >&2 # create user account service -cf create-service cloud-gov-service-account $role $service 1>&2 +cf create-service cloud-gov-service-account $role $service >&2 # create service key -cf create-service-key $service service-account-key 1>&2 +cf create-service-key $service service-account-key >&2 # output service key to stdout in secrets.auto.tfvars format creds=`cf service-key $service service-account-key | tail -n +2 | jq '.credentials'` @@ -79,7 +80,7 @@ username=`echo $creds | jq -r '.username'` password=`echo $creds | jq -r '.password'` if [[ $org_manager = "true" ]]; then - cf set-org-role $username $org OrgManager 1>&2 + cf set-org-role $username $org OrgManager >&2 fi cat << EOF diff --git a/terraform/development/run.sh b/terraform/development/run.sh index 08ad326a0..72dab6bb0 100755 --- a/terraform/development/run.sh +++ b/terraform/development/run.sh @@ -46,11 +46,15 @@ set -e service_account="$username-terraform" -if [[ ! -f "secrets.auto.tfvars" ]]; then +if [[ ! -s "secrets.auto.tfvars" ]]; then # create user in notify-local-dev space to create s3 buckets ../create_service_account.sh -s notify-local-dev -u $service_account > secrets.auto.tfvars fi +if [[ ! -f "../../.env" ]]; then + cp ../../sample.env ../../.env +fi + set +e terraform init