Skip to content

Commit c6e3617

Browse files
authored
Docker fix & invoke tasks (#13)
* Use gunicorn * add docker build + run invoke tasks
1 parent 9eba6a7 commit c6e3617

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

Dockerfile

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7
22

3-
# ENVS RECOMENDATIONS
4-
ENV PYTHONDONTWRITEBYTECODE 1
5-
ENV PYTHONUNBUFFERED 1
6-
7-
# PREPARE FOLDER
8-
WORKDIR /api
3+
ENV VARIABLE_NAME APP
94

105
# COPY DEPENDENCIES
116
COPY requirements.txt ./
127

8+
# COPY PROJECT
9+
COPY ./app /app/app
10+
1311
# INSTALL DEPENDENCIES
1412
RUN pip install --no-cache-dir -r requirements.txt
1513

16-
# COPY PROJECT
17-
COPY . /api/
18-
19-
CMD ["uvicorn", "--host", "0.0.0.0", "app.main:APP"]
14+
EXPOSE 80

tasks.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
invoke sort
1010
invoke check
1111
"""
12+
import random
13+
1214
import invoke
1315

1416
TARGETS_DESCRIPTION = "Paths/directories to format. [default: . ]"
@@ -71,3 +73,17 @@ def generate_reqs(ctx):
7173
"""Generate requirements.txt"""
7274
reqs = ["pipenv lock -r > requirements.txt", "pipenv lock -r --dev > requirements-dev.txt"]
7375
[ctx.run(req) for req in reqs]
76+
77+
78+
@invoke.task
79+
def docker(
80+
ctx, build=False, run=False, tag="covid-tracker-api:latest", port=80, name=f"covid-api-{random.randint(0,999)}"
81+
): # pylint: disable=too-many-arguments
82+
"""Build and run docker container."""
83+
if not any([build, run]):
84+
raise invoke.Exit(message="Specify either --build or --run", code=1)
85+
if build:
86+
docker_cmds = ["build", "."]
87+
else:
88+
docker_cmds = ["run", "-p", str(port), "--name", name]
89+
ctx.run(" ".join(["docker", *docker_cmds, "-t", tag]))

0 commit comments

Comments
 (0)