-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
65 lines (49 loc) · 1.98 KB
/
Dockerfile
File metadata and controls
65 lines (49 loc) · 1.98 KB
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
FROM python:13-slim AS base
ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
POETRY_VIRTUALENVS_IN_PROJECT=true \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VERSION=2.1.3
# Install system dependencies
RUN apt-get update && apt-get install python3-dev gcc build-essential libpq-dev git curl sudo -y
# Create user first
RUN groupadd user && useradd --create-home --home-dir /home/user -g user user
RUN usermod -aG sudo user
RUN echo 'user ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
# Create directories and set permissions
RUN mkdir -p /home/user/.local/bin
RUN mkdir -p /home/user/.local/poetry
RUN mkdir -p /home/user/app
RUN chown user:user -Rf /home/user
# Switch to user for the remaining operations
USER user
# Install poetry as user
# use official curl to respect $POETRY_VERSION & $POETRY_HOME
# (pip install poetry doesn't respect $POETRY_HOME)
RUN curl -sSL https://install.python-poetry.org | python3 -
ENV PATH="$POETRY_HOME/bin:$PATH"
# install python dependencies
COPY --chown=user:user pyproject.toml /home/user/app/
COPY --chown=user:user *poetry.lock /home/user/app/
WORKDIR /home/user/app/
RUN poetry install --no-root --no-interaction --no-ansi --with=dev -v
# Set the PATH to include the virtual environment
ENV PATH="/home/user/app/.venv/bin:$PATH"
ENV PYTHONPATH="/home/user/app/.venv/bin"
# -----------------------------------------------------------------------------
FROM python:3.13-slim as final
RUN groupadd user && useradd --create-home --home-dir /home/user -g user user
USER user
WORKDIR /home/user/app/
# Copy the virtual environment
COPY --chown=user:user --from=base /home/user/venv /home/user/venv
# Copy the source code
COPY --chown=user:user . /home/user/app/
# Set the PATH to include the virtual environment
ENV PATH="/home/user/app/.venv/bin:$PATH"
ENV PYTHONPATH="/home/user/app/.venv/bin"
# Run the app
CMD poetry run gunicorn vinta_schedule_api.wsgi --log-file - -b 0.0.0.0:8000 --reload