Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7

# ENVS RECOMENDATIONS
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# PREPARE FOLDER
WORKDIR /api
ENV VARIABLE_NAME APP

# COPY DEPENDENCIES
COPY requirements.txt ./

# COPY PROJECT
COPY ./app /app/app

# INSTALL DEPENDENCIES
RUN pip install --no-cache-dir -r requirements.txt

# COPY PROJECT
COPY . /api/

CMD ["uvicorn", "--host", "0.0.0.0", "app.main:APP"]
EXPOSE 80
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,17 @@ And don't despair if don't get the python setup working on the first try. No one

## Running / Development

For a live reloading on code changes.

* `pipenv run dev`
* Visit your app at [http://localhost:8000](http://localhost:8000).

Without live reloading.

* `pipenv run start`

Visit your app at [http://localhost:8000](http://localhost:8000).

Alternatively run our API with Docker.

### Running Tests
> [pytest](https://docs.pytest.org/en/latest/)
Expand Down Expand Up @@ -446,7 +455,22 @@ invoke generate-reqs

[Pipfile.lock](./Pipfile.lock) will be automatically updated during `pipenv install`.

### Building
### Docker

Our Docker image is based on [tiangolo/uvicorn-gunicorn-fastapi/](https://hub.docker.com/r/tiangolo/uvicorn-gunicorn-fastapi/).

```bash
invoke docker --build
```

Run with `docker run` or `docker-compose`

### Invoke

Additional developer commands can be run by calling them with the [python `invoke` task runner](http://www.pyinvoke.org/).
```bash
invoke --list
```

### Deploying

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.7'
version: "3.7"

services:
api:
Expand All @@ -8,6 +8,6 @@ services:
volumes:
- .:/api
ports:
- "8000:8000"
- "80:80"
stdin_open: true
tty: true
14 changes: 14 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
invoke sort
invoke check
"""
import random

import invoke

TARGETS_DESCRIPTION = "Paths/directories to format. [default: . ]"
Expand Down Expand Up @@ -71,3 +73,15 @@ def generate_reqs(ctx):
"""Generate requirements.txt"""
reqs = ["pipenv lock -r > requirements.txt", "pipenv lock -r --dev > requirements-dev.txt"]
[ctx.run(req) for req in reqs]


@invoke.task
def docker(ctx, build=False, run=False, tag="covid-tracker-api:latest", name=f"covid-api-{random.randint(0,999)}"):
"""Build and run docker container."""
if not any([build, run]):
raise invoke.Exit(message="Specify either --build or --run", code=1)
if build:
docker_cmds = ["build", "."]
else:
docker_cmds = ["run", "--publish", "80", "--name", name]
ctx.run(" ".join(["docker", *docker_cmds, "-t", tag]))