# apollo-api

## Running application with Docker

**1.** Install [Docker](https://www.docker.com/).

**2.** Build Docker image.

```bash
$ cd /path/to/application/directory/
$ docker build --tag=apollo-api .
```

**3.** Run the application

```bash
$ docker run -p 5000:8000 --env-file=/path/to/env-file apollo-api
```

Application will be up and running on port 5000. This port can be changed if necessary.

Several environment variables must be set:

* Python module with Flask configuration: ``FLASK_CONFIG_MODULE``. There are separate modules for each environment:
``config.local``, ``config.dev``, ``config.staging``, ``config.production``.
* Database connection details: ``MYSQL_DB_HOST``, ``MYSQL_DB_PORT``, ``MYSQL_DB_NAME``, ``MYSQL_DB_USER``,
``MYSQL_DB_PASS``.
* Redis connection details: ``REDIS_HOST``, ``REDIS_PORT``. Port is optional, default is ``6379``.
* URLs of other Filtr APIs and corresponding authorization credentials: ``ADMIN_ACCOUNTS_API``, ``ADMIN_ACCOUNTS_USER``,
``ADMIN_ACCOUNTS_PASS``,  ``CONSUMER_ANALYTICS_API``, ``CONSUMER_ANALYTICS_USER``, ``CONSUMER_ANALYTICS_PASS``.
* Username and password for basic authentication: ``BASIC_AUTH_USER``, ``BASIC_AUTH_PASS``.
* Auth0 Management API connection details: ``AUTH0_DOMAIN``, ``AUTH0_CLIENT_ID``, ``AUTH0_CLIENT_SECRET``, ``RATE_LIMIT_RETRY_COUNT``, ``RATE_LIMIT_WAIT_MULTIPLIER``. Count and Multiplier are optional, default values are ``3`` and ``2`` accordingly.

**4.** Run the application with docker-compose and mysql.

It will run application on port 8000 with local database.

```bash
$ docker-compose -f docker-compose.yml -f docker-compose.mysql.yml up
```

**5.** To install private apollo libs to local virtualenv.

```bash
$ mkdir ~/.config/pip
$ cp configs/pip.conf ~/.config/pip/
$ cp configs/.pypirc ~/
$ pip install -r requirements/base.txt
```

**6.** Run tests

```bash
$ make test
```

**7.** Run code style checkers

```bash
$ make checkstyle
```

**8.** Run security checkers

```bash
$ make security
```

**9.** Run code prettifier

```bash
$ make prettify
```

**10.** Run pre-commit script (prettifier, code style & security checkers, tests)
```bash
$ make pre-commit
```

