-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
45 lines (34 loc) · 1.49 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
FROM python:3.12 AS build
RUN python3 -m venv /venv
# example of a development library package that needs to be installed
# RUN apt-get -qy update && apt-get -qy install libldap2-dev && \
# rm -rf /var/cache/apt/* /var/lib/apt/lists/*
# install requirements separately to prevent pip from downloading and
# installing pypi dependencies every time a file in your project changes
ADD ./requirements /project/requirements
ARG REQS=requirements
RUN /venv/bin/pip install -r project/requirements/$REQS.txt
# install the project, basically copying its code, into the virtualenv.
# this assumes the project has a functional setup.py
# ADD . ./project
# WORKDIR /project
ADD . /project
RUN /venv/bin/pip install /project
# this won't have any effect on our production image, is only meant for
# if we want to run commands like pytest in the build image
# WORKDIR /project
# the second, production stage can be much more lightweight:
FROM python:3.12-slim AS production
COPY --from=build /venv /venv
ENV PATH="/venv/bin:$PATH"
# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
# install runtime libraries (different from development libraries!)
# RUN apt-get -qy update && apt-get -qy install libldap-2.4-2 && \
# rm -rf /var/cache/apt/* /var/lib/apt/lists/*
# remember to run python from the virtualenv
# CMD exec gunicorn --bind :$PORT --workers 1 --timeout 0 app:server
# specifically for docker-compose
CMD exec gunicorn --bind 0.0.0.0:8000 --workers 4 --timeout 0 app:server