ows-sound-recordings
=====================================

Service for the management of sound recordings.

## Getting Started


### Setup

#### Install
* Install [docker](https://docs.docker.com/get-docker/)
* Clone this repository

#### Configure
* Copy over `.env.shadow` to `.env`

`config.py` will try to access aws secrets manager to obtain some values if you use the env `qa` (which is often easiest).
The container will use your `default` profile from `~/.aws/credentials` so make sure they are up to date.  Note that running `awsume` will `not` achieve this.
Rather you need to ensure your `awsume` generated creds are in that location e.g. 
```bash
awsume prod # or awsume default depending on your set up
env | grep AWS
# highlight and copy the AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN and paste them under
# the [default] profile in ~/.aws/credentials, removing old values. 
vi ~/.aws/credentials 
```
If you're using the `dev` environment, you should supply your own credentials to the `.env` file. 

#### Authenticate
In order to pull down the base image to build containers, you need to authenticate with the AWS **shared-ecr** account using MFA, then register that login via docker app on your host machine.
* Login to **shared-ecr** ECR so the base image can be fetched
* Use `awsume` to load credentials for our prod account
* Run the command below to achieve this
```bash
$ aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 086679231553.dkr.ecr.us-east-1.amazonaws.com
```

:bulb: This process should not need to be repeated if a digest is used in your `FROM` image tag! The image will be cached locally and only updated if the digest changes.


### Permissions

In PROD and QA environments, to accept and authorize incoming and outgoing
requests, make sure you have the right DynamoDB permissions, as highlighted
in the corresponding [tech design](https://docs.google.com/document/d/1eHoI_BddTFMi15yCaHS6KvhSSoTrMEd3WwJINIpgNpM/edit).

### Running

`docker compose up --build dev`

:zap: dev server will automatically restart on code changes due to code being mounted into the container as a volume, there is no need to restart the container manually!

:warning: `ERROR [internal] load metadata for 086679231553.dkr.ecr.us-east-1.amazonaws.com/docker-parent-images:python38` means you need to re-authenticate with **dev** AWS using MFA and login to ECR (see setup-authenticate above)

### Linting and Unit Testing

`docker compose up --build unit-lint`

#### Set pytest Options
Sometimes you may want to customize how tests run using [pytest options](https://docs.pytest.org/en/stable/usage.html) when doing development locally, only running a subset of tests using `-k` for example. Simply edit `TEST_ARGS` value in `.env`, to set the options you need.


#### Skip Linting
When developing locally, you might not want to worry about linting when working to make tests pass. Simple edit the `SKIP_LINT` value in `.env` to be `1`.
