-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
77 lines (59 loc) · 2.57 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
73
74
75
76
77
#########################################################################################################
# Python compile image
#########################################################################################################
FROM python:3.12.7-slim-bookworm AS app-compiler
ENV PYTHONUNBUFFERED=1
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
# dependencies for building Python packages
build-essential
# Install uv
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
ENV UV_LINK_MODE=copy \
UV_COMPILE_BYTECODE=1
# Create a virtual environment and make it relocatable
RUN uv venv .venv --relocatable
# Install uv
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-editable --no-group dev --no-install-project
#########################################################################################################
# Python build image
#########################################################################################################
FROM python:3.12.7-slim-bookworm AS python-builder
LABEL maintainer="[email protected]"
ARG APP_UID=1001 # Default application UID, override during build or run
ARG APP_GID=1001 # Default application GID, override during build or run
ARG DOCKER_GID=991 # Default docker GID, override during build or run
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
# Used on healthcheckers
curl \
# Cleaning up unused files
&& apt-get purge -y --auto-remove \
-o APT::AutoRemove::RecommendsImportant=0 \
-o APT::Autoremove::SuggestsImportant=0 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /var/cache/* \
# Create docker group to allow docker socket access
&& addgroup --gid $DOCKER_GID docker \
# Create aplication specific user
&& addgroup --system --gid $APP_GID app \
&& adduser --system --ingroup app --uid $APP_UID --home /home/app app \
&& adduser app docker
ENV PATH="/home/app/.venv/bin:$PATH"
ENV PYTHONPATH="$PYTHONPATH:/home/app/daiv_sandbox/"
ENV PYTHONUNBUFFERED=1
# Copy python compiled requirements
COPY --chown=app:app --from=app-compiler /.venv /home/app/.venv
# Copy application code
COPY --chown=app:app ./daiv_sandbox /home/app/daiv_sandbox
USER app
WORKDIR /home/app
RUN python -m compileall daiv_sandbox
HEALTHCHECK --interval=10s \
CMD curl --fail http://127.0.0.1:8000/-/health/ || exit 1
EXPOSE 8000
CMD ["python", "daiv_sandbox/main.py"]