-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
72 lines (51 loc) · 1.48 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
FROM python:3.12-slim AS builder
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
ENV APP_DIR=/app
ENV \
# OS
PORT=8000 \
# uv
UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
UV_PYTHON_DOWNLOADS=never \
UV_CACHE_DIR="$APP_DIR/.uv_cache" \
# Python
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONIOENCODING=utf-8 \
LANG=en_US.UTF-8 \
LANGUAGE=en_US.UTF-8 \
# LC_ALL=en_US.UTF-8 \
# pip
PIP_DISABLE_PIP_VERSION_CHECK=on \
# venv and requirements path
VIRTUAL_ENV="$APP_DIR/.venv" \
PYTHONPATH="$APP_DIR/apps:$PYTHONPATH"
WORKDIR $APP_DIR
# Cache and bind mounts for uv
RUN \
--mount=type=cache,target=$UV_CACHE_DIR \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project --no-dev
ADD . .
# Cache mount again for uv sync
RUN \
--mount=type=cache,target=$UV_CACHE_DIR \
uv sync --frozen --no-dev
CMD ["bash"]
FROM builder AS development
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
COPY --from=builder $APP_DIR $APP_DIR
RUN chmod -R +x $APP_DIR/*.sh
EXPOSE $PORT
VOLUME /data
FROM development AS production
ENV USERNAME=nonroot
RUN useradd -ms /bin/bash $USERNAME
USER $USERNAME
COPY --from=development --chown=$USERNAME:$USERNAME $APP_DIR $APP_DIR
HEALTHCHECK \
--interval=10s --timeout=5s --start-period=10s --retries=5 \
CMD curl localhost:${PORT}/health || exit 1
CMD ["./entrypoint.sh"]