-"# syntax=docker/dockerfile:1\n\nFROM ubuntu:24.04 AS builder\n\nWORKDIR /app\n\nENV \\\n PYTHONUNBUFFERED=true \\\n UV_PYTHON_INSTALL_DIR=/opt/uv/python \\\n UV_LINK_MODE=copy\n\nRUN : \\\n && apt-get update \\\n && apt-get install -y --no-install-recommends \\\n build-essential \\\n curl \\\n ca-certificates \\\n libssl-dev \\\n pkg-config \\\n software-properties-common \\\n && add-apt-repository ppa:deadsnakes/ppa \\\n && apt-get update \\\n && apt-get install -y --no-install-recommends \\\n python3.11 \\\n python3.11-venv \\\n && apt-get clean \\\n && rm -rf /var/lib/apt/lists/*\n\n# Install uv\nADD https://astral.sh/uv/install.sh /uv-installer.sh\n\nRUN sh /uv-installer.sh && rm /uv-installer.sh\n\n# Install rust\nRUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable --profile minimal\n\nENV PATH=\"/root/.local/bin:/root/.cargo/bin:$PATH\"\n\n# Create virtual environment\nRUN python3.11 -m venv .venv\n\nCOPY pyproject.toml Cargo.toml Cargo.lock README.md LICENSE ./\nCOPY src/ ./src\nRUN mkdir my_project\n\nRUN --mount=type=cache,target=/app/target/ \\\n --mount=type=cache,target=/usr/local/cargo/git/db \\\n --mount=type=cache,target=/usr/local/cargo/registry/ \\\n uv tool run maturin develop -r\n\nCOPY requirements.txt ./\n\nRUN --mount=type=cache,target=/root/.cache/uv \\\n .venv/bin/python -m pip install -r requirements.txt\n\nCOPY . /app\n\n\nRUN --mount=type=cache,target=/usr/local/cargo/git/db \\\n --mount=type=cache,target=/usr/local/cargo/registry/ \\\n .venv/bin/python -m pip install -r requirements.txt \\\n && uv tool run maturin develop -r\n\n\n# Build production stage\nFROM ubuntu:24.04 AS prod\n\nRUN useradd appuser\n\nWORKDIR /app\n\nRUN chown appuser:appuser /app\n\nENV \\\n PYTHONUNBUFFERED=true \\\n PATH=\"/app/.venv/bin:$PATH\" \\\n PORT=\"8000\"\n\nRUN : \\\n && apt-get update \\\n && apt-get install -y --no-install-recommends \\\n software-properties-common \\\n && add-apt-repository ppa:deadsnakes/ppa \\\n && apt-get update \\\n && apt-get install -y --no-install-recommends \\\n python3.11 \\\n && apt-get clean \\\n && rm -rf /var/lib/apt/lists/*\n\nCOPY --from=builder /app/.venv /app/.venv\nCOPY --from=builder /app/my_project /app/my_project\nCOPY ./scripts/entrypoint.sh /app\n\nRUN chmod +x /app/entrypoint.sh\n\nEXPOSE 8000\n\nUSER appuser\n\nENTRYPOINT [\"./entrypoint.sh\"]\n"
0 commit comments