-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
75 lines (63 loc) · 2.65 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
###########################################################################
# Create requirements from poetry
###########################################################################
FROM python:3.9-slim as requirements-stage
WORKDIR /app/
RUN pip install poetry
COPY ./pyproject.toml ./poetry.lock* /app/
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes
RUN poetry export --with dev -f requirements.txt --output requirements-dev.txt --without-hashes
###########################################################################
# Build dev base image
###########################################################################
FROM python:3.9-slim AS dev-base
# set working directory
WORKDIR /app/
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV LOG_LEVEL=debug
ENV PORT 8080
EXPOSE 8080
# install system dependencies
RUN apt-get update \
&& apt-get -y install --no-install-recommends \
curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY --from=requirements-stage /app/requirements.txt /opt/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /opt/requirements.txt
###########################################################################
# Build dev env image
###########################################################################
FROM dev-base AS dev-env
COPY --from=requirements-stage /app/requirements-dev.txt /opt/requirements-dev.txt
RUN pip install --no-cache-dir --upgrade -r /opt/requirements-dev.txt
COPY ./pyproject.toml /app/
COPY ./src /app
###########################################################################
# Build lint image
###########################################################################
FROM dev-env AS dev-linter
RUN ruff check .
RUN pylama app
###########################################################################
# Build utest coverage image
###########################################################################
FROM dev-env AS dev-coverage
RUN coverage run -m pytest -p no:warnings --junitxml=junit.xml --cov=app --cov-report html --cov-report xml
###########################################################################
# Build security check image
###########################################################################
FROM dev-env AS dev-security
RUN bandit -r /app/app
###########################################################################
# Build production image - api
###########################################################################
FROM dev-base AS prd
VOLUME [ "/data" ]
COPY ./src /app
# running a single Uvicorn process
RUN chmod +x /app/prestart.sh
RUN chmod +x /app/start-reload.sh
CMD /app/start-reload.sh