Skip to content

Dockerfile with a workspace project #6867

@Afoucaul

Description

@Afoucaul

The doc proposes the following Dockerfile to build a project into a Dockerfile while caching intermediate layers (uv version 0.4.0):

# Install uv
FROM python:3.12-slim
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv

# Change the working directory to the `app` directory
WORKDIR /app

# Copy the lockfile and `pyproject.toml` into the image
ADD uv.lock /app/uv.lock
ADD pyproject.toml /app/pyproject.toml

# Install dependencies
RUN uv sync --frozen --no-install-project

# Copy the project into the image
ADD . /app

# Sync the project
RUN uv sync --frozen

However, when the project is a worskpace, uv sync --frozen --no-install-project won't do anything unless the workspace members are there. As a result, if a workspace contains libs in a libs/ dir, one has to also ADD all libs/*/pyproject.toml files so uv sync --frozen --no-install-project actually installs 3rd party dependencies.
We could easily COPY the whole libs/ dir, but then the cache would be invalidated every time sources change.

Is there a workaround? Or a workspace-specific strategy for building Docker images?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAsking for clarification or support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions