-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
52 lines (39 loc) · 1.36 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
# Builder stage
FROM python:3.11-slim AS builder
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV POETRY_VERSION=1.5.1
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
&& pip install --upgrade pip \
&& pip install "poetry==$POETRY_VERSION"
WORKDIR /app
COPY pyproject.toml poetry.lock /app/
# Use poetry to install dependencies
RUN poetry export -f requirements.txt --without-hashes --output /app/requirements.txt
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r /app/requirements.txt
# Final stage
FROM python:3.11-slim AS final
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
COPY --from=builder /app/wheels /wheels
COPY --from=builder /app/requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir --no-index --find-links=/wheels -r /tmp/requirements.txt \
&& rm -rf /wheels /tmp/requirements.txt
# Cleanup and setup app user and directory
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libpq-dev \
libmagic1 \
&& rm -rf /var/lib/apt/lists/* \
&& useradd -U liara \
&& install -d -m 0755 -o liara -g liara /app/staticfiles \
&& install -d -m 0755 -o liara -g liara /app/media
WORKDIR /app
COPY --chown=liara:liara . .
USER liara:liara
RUN chmod +x ./entrypoint.sh
ENTRYPOINT [ "./entrypoint.sh" ]
CMD [ "server" ]