## Getting Started

### Installation

Make sure you are using 
**Python 3.11**

### Fork original repository and create local clone
Fork [https://github.com/theorchard/feed-status-monitor](https://github.com/theorchard/feed-status-monitor) into your own Github account
```shell script
$ git clone git@github.com:YOUR_GITHUB_USERNAME/feed-status-monitor.git
```

### Setting up Python virtual environment
#### Create virtual environment
This project uses *pipenv* to manage python virtual environments. All dependencies are installed from `Pipfile.lock` file.

```shell script
$ pip install pipenv
```

#### Install required libraries
##### For development 
```shell script
$ make install_from_lock_include_dev
```

##### For production
```shell script
$ make install_from_lock
```

*Note:* To see executed commands and keys check out `Makefile` internals.

#### Configure `.env` file
Template `.env.shadow` file contains all environment variables needed for successful connectivity, authentication, etc. Copy this file to `.env` and add values to required variables. If a `.env` file is present in your project, `$ pipenv shell` and `$ pipenv run` will automatically load it, for you.

```shell
$ cp .env.shadow .env
```

Development SWF domain must be assigned to `SWF_DOMAIN=` env variable in the `.env` file.

Next generate AWS keys/tokens using [aws-creds-generator](https://github.com/theorchard/collab/tree/master/jcarrion/aws-creds-generator) (please follow the link and read README.md to correctly setup the script). The script will automatically generate temporary credentials that will last for 12 hours.

Example usage:
```shell
$ ./generate.sh dev
```

To verify temp credentials were created run

```
$ cat ~/.aws/credentials
```

### Running backend

When all dependencies have been installed, you can run the flask application
on your local instance by running:

```shell
~$ pipenv run python dev.py
```

#### Using docker compose for local development (both backend and frontend)

Run `docker compose` only after you install `node_modules`. Please see the example:

```bash
cd fronend && yarn install && cd -
docker compose up --build
```

### How to build Frontend

Please read `frontend/README.md` in order to find out how build frontend locally 

### Streamlit frontend

Monty ships a second frontend built with [Streamlit](https://streamlit.io/).
The source lives in `feed_status/ui/` and is a thin client that fetches data
from the existing Flask REST API.

Run it locally against a backend already serving on `localhost:5000`:

```shell
$ MONTY_API_BASE_URL=http://localhost:5000 \
    pipenv run python -m streamlit run feed_status/ui/app.py
```

see:
```
make 
```

Env vars:

- `MONTY_API_BASE_URL` — base URL of the Flask backend that serves feed data. Defaults to `http://localhost:5000`.

### Selecting the UI in the production image (`MONTY_UI`)

The production runtime image runs nginx, uwsgi (Flask) and Streamlit
side-by-side under supervisord. nginx decides which UI to serve at `/`
based on the `MONTY_UI` env var (read at container start by
`conf/nginx-entrypoint.py`):

Supported values:

- `vue` *(default)* — `/` routes to the Flask / Vue dashboard (legacy).
- `streamlit` — `/` routes to the Streamlit dashboard. Streamlit fetches data from Flask in-container on `127.0.0.1:8000`.

Any other value causes nginx to fail to start with a clear error in the
container logs.


## Using docker-compose

All docker-compose profiles use single multi-staged Dockerfile.

### Pre-requisites

Before you start working with docker you will need:

```bash
$ awsume dev
$ make docker_login
```
### DEV

For development purposes created 'dev' docker-compose profile.

Command:
```bash
$ docker compose up --build
or
$ make docker_run_dev
```

This command will build from source and expose development servers.

Services:
* backend http://localhost:5000/
* frontend http://localhost:8080/

### PROD

You can build and start application in production mode.
In this mode it uses uwsgi app-server.

```bash
$ awsume dev
$ docker compose up production --build
or
$ make docker_run_prod

```

Services:
* production http://localhost/

## TEST

Test profile created for CI.

```bash
$ docker compose up unit-lint --build
or
$ make docker_unit_lint
```

It runs unit tests and linter.
It saves `build/coverage.xml` file for cubertura report in Jenkins.