-
Notifications
You must be signed in to change notification settings - Fork 4
/
Dockerfile
101 lines (80 loc) · 2.78 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Use a multi-stage build to first get uv
FROM ghcr.io/astral-sh/uv:0.4.28 AS uv
FROM ubuntu:noble AS build
RUN apt-get update -qy && \
apt-get install -qyy \
-o APT::Install-Recommends=false \
-o APT::Install-Suggests=false \
ca-certificates \
clang \
gcc \
git \
libgdal-dev \
libpq-dev \
make
# We need to set this environment variable so that uv knows where
# the virtual environment is to install packages
ENV UV_LINK_MODE=copy \
UV_COMPILE_BYTECODE=1 \
UV_PROJECT_ENVIRONMENT=/app/.venv \
VIRTUAL_ENV=/app/.venv
#RUN mkdir -p /app
# Create a user and group for the application
#RUN groupadd -r app && \
# useradd -r -d /app -g app -N app
#
#RUN chown -R app:app /app
#
#USER app
# Create a virtual environment with uv inside the container
RUN --mount=type=cache,target=/app/.cache \
--mount=from=uv,source=/uv,target=./uv \
/uv python install 3.10 && \
/uv venv $VIRTUAL_ENV
# Make sure that the virtual environment is in the PATH so
# we can use the binaries of packages that we install such as pip
# without needing to activate the virtual environment explicitly
ENV PATH=$VIRTUAL_ENV/bin:/usr/local/bin:$PATH
RUN --mount=type=cache,target=/app/.cache \
--mount=from=uv,source=/uv,target=./uv \
/uv pip install setuptools wheel
# Copy pyproject.toml and uv.lock to a temporary directory
COPY pyproject.toml /_lock/
COPY uv.lock /_lock/
# Install the packages with uv using --mount=type=cache to cache the downloaded packages
RUN --mount=type=cache,target=/app/.cache \
--mount=from=uv,source=/uv,target=./uv \
cd /_lock && \
/uv sync --locked --no-install-project
# Start the runtime stage
FROM ubuntu:noble
SHELL ["sh", "-exc"]
ENV PATH=$VIRTUAL_ENV/bin:/usr/local/bin:$PATH
RUN apt-get update -qy && \
apt-get install -qyy \
-o APT::Install-Recommends=false \
-o APT::Install-Suggests=false \
libgdal-dev \
postgresql-client \
expat
# Create a user and group for the application
#RUN groupadd -r app && \
# useradd -r -d /app -g app -N app
COPY --chmod=777 wait_for_postgres.sh /usr/local/bin/wait_for_postgres.sh
# Set the entry point and signal handling
ENTRYPOINT [ "/app/start.sh" ]
#ENTRYPOINT [ "/bin/bash" ]
STOPSIGNAL SIGINT
# Copy the pre-built `/app` directory from the build stage
COPY --from=build --chmod=777 /app /app
COPY --from=build --chmod=777 /root /root
COPY newrelic.ini /app/newrelic.ini
COPY alembic.ini /app/alembic.ini
COPY --chmod=777 app/settings/prestart.sh /app/prestart.sh
COPY --chmod=777 app/settings/start.sh /app/start.sh
# If your application is NOT a proper Python package that got
# pip-installed above, you need to copy your application into
# the container HERE:
COPY ./app /app/app
#USER app
WORKDIR /app