-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
52 lines (37 loc) · 1.54 KB
/
Copy pathDockerfile
File metadata and controls
52 lines (37 loc) · 1.54 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
FROM debian:13.1-slim
ENV DEBIAN_FRONTEND=noninteractive
ENV APPLICATION_PATH=/opt
# Only use the managed Python version
ENV UV_PYTHON_PREFERENCE=only-managed
# Allow bytecode compilation
ENV UV_COMPILE_BYTECODE=1
# The uv installer requires curl and certificates to download the release archive
RUN apt-get update && \
apt-get install -y --no-install-recommends curl ca-certificates && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Create a non-root user
RUN groupadd --system --gid 999 nonrootuser && \
useradd --system --gid 999 --uid 999 --create-home nonrootuser
WORKDIR ${APPLICATION_PATH}
RUN chown nonrootuser:nonrootuser ${APPLICATION_PATH}
# Download uv installer
ADD --chown=nonrootuser:nonrootuser https://astral.sh/uv/0.8.22/install.sh /tmp/uv-installer.sh
# Use the non-root user to install uv, install and run the application
USER nonrootuser
RUN sh /tmp/uv-installer.sh && rm /tmp/uv-installer.sh
# Ensure the installed binary is on the `PATH`
ENV PATH="/home/nonrootuser/.local/bin/:$PATH"
# Copy necessary files
COPY ./pyproject.toml .
COPY ./uv.lock .
COPY ./app ./app
COPY ./templates ./templates
COPY --chown=nonrootuser:nonrootuser ./static ./static
COPY ./database.db .
# Create a virtual environment and install dependencies
RUN uv sync --locked --no-dev
# Place executables in the environment at the front of the path
#ENV PATH="/opt/.venv/bin:$PATH"
# Run the FastAPI application
# by defaut, FastAPI runs on port 8000
CMD ["uv", "run", "fastapi", "dev", "app/main.py", "--host", "0.0.0.0", "--proxy-headers"]