-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
79 lines (63 loc) · 2.5 KB
/
Dockerfile
File metadata and controls
79 lines (63 loc) · 2.5 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Inspired by https://github.com/astral-sh/uv-docker-example/blob/main/standalone.Dockerfile
# First, build the application in the `/app` directory
FROM ghcr.io/astral-sh/uv:bookworm-slim AS builder
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy UV_NO_DEV=1
# Configure the Python directory so it is consistent, only use managed version
ENV UV_PYTHON_INSTALL_DIR=/python UV_PYTHON_PREFERENCE=only-managed
# Install Python before the project for caching
RUN uv python install 3.12
# Download and install dependencies
WORKDIR /app
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 --locked --no-install-project
# Install project
COPY . /app
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
# Install generic dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
software-properties-common \
build-essential \
libxrender1 \
libxtst6 \
netcat \
ncbi-blast+ \
wget && \
rm -rf /var/lib/apt/lists/*
# Setup a non-root user
RUN groupadd --system --gid 999 nonroot \
&& useradd --system --gid 999 --uid 999 --create-home nonroot
# Copy the Python version
COPY --from=builder --chown=nonroot:nonroot /python /python
# Copy the application from the builder
COPY --from=builder --chown=nonroot:nonroot /app /app
# Place executables in the environment at the front of the path
ENV PATH="/app/.venv/bin:$PATH"
# Prevent Python from writing .pyc files
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
# Use `/app` as the working directory
WORKDIR /app
# Download data to be baked in if no data present
ARG DATA=""
ARG EXTRAS=""
RUN set -eux; \
if [ -d "data" ]; then \
echo "Using existing data directory - skip download from Zenodo"; \
elif [ -n "$DATA" ] && [ -n "$EXTRAS" ]; then \
echo "Downloading data from Zenodo records $DATA and $EXTRAS"; \
python scripts/prepare_data.py "$DATA" "$EXTRAS" ; \
python -m scripts.create_db ; \
else \
echo "No data directory found and no $DATA and $EXTRAS provided"; \
echo " Either populate ./data or pass --build-arg $DATA=..." "$EXTRAS"; \
exit 1; \
fi
# Use the non-root user to run our application
USER nonroot
# Run the FastAPI application by default
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers", "--forwarded-allow-ips=*"]