diff --git a/Dockerfile b/Dockerfile index 1650cc8..64b5512 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,21 @@ +# Multi-stage Dockerfile for Python Template Server +# Stage 1: Build stage - build wheel using uv +FROM python:3.12-slim AS builder + +WORKDIR /build + +# Install uv +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ + +# Copy project files +COPY python_template_server/ ./python_template_server/ +COPY configuration ./configuration/ +COPY pyproject.toml .here LICENSE README.md ./ + +# Build the wheel +RUN uv build --wheel + +# Stage 2: Runtime stage FROM python:3.12-slim # Build arguments for environment-specific config @@ -10,14 +28,15 @@ WORKDIR /app RUN useradd -m -u 1000 template_server_user && \ chown -R template_server_user:template_server_user /app -# Install Git for dependency resolution -RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* - # Install uv in runtime stage COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ -# Install dependencies -RUN uv pip install --system git+https://github.com/javidahmed64592/python-template-server.git +# Copy the built wheel from builder +COPY --from=builder /build/dist/*.whl /tmp/ + +# Install the wheel +RUN uv pip install --system --no-cache /tmp/*.whl && \ + rm /tmp/*.whl # Create configuration directory RUN mkdir -p /app/configuration && \ diff --git a/pyproject.toml b/pyproject.toml index 7ed8115..980f12c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,6 +47,9 @@ python-template-server = "python_template_server.main:run" generate-certificate = "python_template_server.certificate_handler:generate_self_signed_certificate" generate-new-token = "python_template_server.authentication_handler:generate_new_token" +[tool.hatch.metadata] +allow-direct-references = true + [tool.hatch.build] include = [ "configuration/**",