From 71ba4d229b2fba6f6886f3101a84942127e5600a Mon Sep 17 00:00:00 2001 From: rednafi Date: Tue, 15 Oct 2024 22:33:03 +0200 Subject: [PATCH] Faster docker container --- README.md | 2 +- bin/Dockerfile-template | 11 +++++++++-- dockerfiles/python311/Dockerfile | 11 +++++++++-- dockerfiles/python312/Dockerfile | 11 +++++++++-- dockerfiles/python313/Dockerfile | 8 ++++++-- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 067405f..ca1e210 100755 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ If you want to run the app locally, without using Docker, then: - Install the dependencies. Run: ```sh - uv sync + uv sync --frozen ``` - Start the app. Run: diff --git a/bin/Dockerfile-template b/bin/Dockerfile-template index 744c0b0..b1ba518 100644 --- a/bin/Dockerfile-template +++ b/bin/Dockerfile-template @@ -5,13 +5,17 @@ ARG PYTHON_VERSION=bleh FROM python:${PYTHON_VERSION}-slim AS builder COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ +# Show the currently running commands +SHELL ["sh", "-exc"] + # Set working directory WORKDIR /app # Install dependencies -COPY pyproject.toml uv.lock /app/ RUN --mount=type=cache,target=/root/.cache/uv \ - uv sync --frozen --no-install-project --no-editable --no-dev + --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + uv sync --no-install-project --locked --no-dev # Copy the project source code into the builder stage COPY . /app @@ -22,6 +26,9 @@ FROM python:${PYTHON_VERSION}-slim # Set the working directory in the final image WORKDIR /app +# See . +STOPSIGNAL SIGINT + # Copy the virtual environment and the source code from the builder stage COPY --from=builder /app/.venv /app/.venv COPY --from=builder /app /app diff --git a/dockerfiles/python311/Dockerfile b/dockerfiles/python311/Dockerfile index 8141354..46cae56 100644 --- a/dockerfiles/python311/Dockerfile +++ b/dockerfiles/python311/Dockerfile @@ -5,13 +5,17 @@ ARG PYTHON_VERSION=3.11 FROM python:${PYTHON_VERSION}-slim AS builder COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ +# Show the currently running commands +SHELL ["sh", "-exc"] + # Set working directory WORKDIR /app # Install dependencies -COPY pyproject.toml uv.lock /app/ RUN --mount=type=cache,target=/root/.cache/uv \ - uv sync --frozen --no-install-project --no-editable --no-dev + --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + uv sync --no-install-project --locked --no-dev # Copy the project source code into the builder stage COPY . /app @@ -22,6 +26,9 @@ FROM python:${PYTHON_VERSION}-slim # Set the working directory in the final image WORKDIR /app +# See . +STOPSIGNAL SIGINT + # Copy the virtual environment and the source code from the builder stage COPY --from=builder /app/.venv /app/.venv COPY --from=builder /app /app diff --git a/dockerfiles/python312/Dockerfile b/dockerfiles/python312/Dockerfile index db08742..6409815 100644 --- a/dockerfiles/python312/Dockerfile +++ b/dockerfiles/python312/Dockerfile @@ -5,13 +5,17 @@ ARG PYTHON_VERSION=3.12 FROM python:${PYTHON_VERSION}-slim AS builder COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ +# Show the currently running commands +SHELL ["sh", "-exc"] + # Set working directory WORKDIR /app # Install dependencies -COPY pyproject.toml uv.lock /app/ RUN --mount=type=cache,target=/root/.cache/uv \ - uv sync --frozen --no-install-project --no-editable --no-dev + --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + uv sync --no-install-project --locked --no-dev # Copy the project source code into the builder stage COPY . /app @@ -22,6 +26,9 @@ FROM python:${PYTHON_VERSION}-slim # Set the working directory in the final image WORKDIR /app +# See . +STOPSIGNAL SIGINT + # Copy the virtual environment and the source code from the builder stage COPY --from=builder /app/.venv /app/.venv COPY --from=builder /app /app diff --git a/dockerfiles/python313/Dockerfile b/dockerfiles/python313/Dockerfile index ec27f4f..602f556 100644 --- a/dockerfiles/python313/Dockerfile +++ b/dockerfiles/python313/Dockerfile @@ -12,9 +12,10 @@ SHELL ["sh", "-exc"] WORKDIR /app # Install dependencies -COPY pyproject.toml uv.lock /app/ RUN --mount=type=cache,target=/root/.cache/uv \ - uv sync --frozen --no-install-project --no-editable --no-dev + --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + uv sync --no-install-project --locked --no-dev # Copy the project source code into the builder stage COPY . /app @@ -25,6 +26,9 @@ FROM python:${PYTHON_VERSION}-slim # Set the working directory in the final image WORKDIR /app +# See . +STOPSIGNAL SIGINT + # Copy the virtual environment and the source code from the builder stage COPY --from=builder /app/.venv /app/.venv COPY --from=builder /app /app