Skip to content

Commit

Permalink
Faster docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
rednafi committed Oct 15, 2024
1 parent 62fe443 commit 71ba4d2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 9 additions & 2 deletions bin/Dockerfile-template
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +26,9 @@ FROM python:${PYTHON_VERSION}-slim
# Set the working directory in the final image
WORKDIR /app

# See <https://hynek.me/articles/docker-signals/>.
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
Expand Down
11 changes: 9 additions & 2 deletions dockerfiles/python311/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +26,9 @@ FROM python:${PYTHON_VERSION}-slim
# Set the working directory in the final image
WORKDIR /app

# See <https://hynek.me/articles/docker-signals/>.
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
Expand Down
11 changes: 9 additions & 2 deletions dockerfiles/python312/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +26,9 @@ FROM python:${PYTHON_VERSION}-slim
# Set the working directory in the final image
WORKDIR /app

# See <https://hynek.me/articles/docker-signals/>.
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
Expand Down
8 changes: 6 additions & 2 deletions dockerfiles/python313/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,6 +26,9 @@ FROM python:${PYTHON_VERSION}-slim
# Set the working directory in the final image
WORKDIR /app

# See <https://hynek.me/articles/docker-signals/>.
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
Expand Down

0 comments on commit 71ba4d2

Please sign in to comment.