forked from AndyGrant/OpenBench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.prod
66 lines (51 loc) · 1.95 KB
/
Dockerfile.prod
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
############################################################
# Builder
############################################################
FROM --platform=$BUILDPLATFORM python:3.11-slim-buster AS builder
WORKDIR /usr/src/app
# Set environment variables
# Prevents Python from writing pyc files to disc (equivalent to python -B option)
ENV PYTHONDONTWRITEBYTECODE 1
# Prevents Python from buffering stdout and stderr (equivalent to python -u option)
ENV PYTHONUNBUFFERED 1
# Install system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc
# Install python dependencies
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
############################################################
# Setup OpenBench
############################################################
FROM --platform=$BUILDPLATFORM python:3.11-slim-buster
WORKDIR /app
# Create directory for the app user
RUN mkdir -p /home/app
# Create the app user
RUN addgroup --system app && adduser --system --group app
# Create the appropriate directories
# We need to create /staticfiles now or `collectstatic` won't work as a non-root user with volumes created as root
ENV HOME=/home/app
ENV APP_HOME=/home/app/web
RUN mkdir $APP_HOME
RUN mkdir $APP_HOME/staticfiles
RUN mkdir $APP_HOME/mediafiles
WORKDIR $APP_HOME
# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends netcat
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install --upgrade pip
RUN pip install --no-cache /wheels/*
# Copy entrypoint.prod.sh
COPY ./entrypoint.prod.sh .
RUN sed -i 's/\r$//g' $APP_HOME/entrypoint.prod.sh
RUN chmod +x $APP_HOME/entrypoint.prod.sh
# Copy project
COPY . $APP_HOME
# chown all the files to the app user
RUN chown -R app:app $APP_HOME
# Change to the app user
USER app
# run entrypoint.prod.sh
ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"]