#uv: No such file or directory

1 messages · Page 1 of 1 (latest)

vestal granite
#

Hi, I want to reproduce this Dockerfile (for tutorial purpose).
The error is related to the copy of the executable uv from one image to another.

I have this error

│ ✘ .withExec(args: ["uv", "sync", "--frozen", "--no-install-project"]): Container! 1.8s
│ ┃ [dumb-init] uv: No such file or directory                                                
│ ! process "uv sync --frozen --no-install-project" did not complete successfully: exit code: 2
#

with something like this :

from typing import Annotated, Optional

import dagger
from dagger import Doc, dag, function, object_type
@object_type
class HelloDagger:
    @function
    async def build_discipline(
        self,
        source: Optional[Annotated[dagger.Directory, Doc("Source directory")]] = None,
    ) -> dagger.Container:
        """Builds the discipline service container using the specified configuration"""
        # Get uv from its container
        uv_container = dag.container().from_("ghcr.io/astral-sh/uv:0.5.8")

        base = (
            dag.container()
            .from_("python:3.13")
            .with_workdir("/app/")
            # Explicitly copy uv binary to a directory in PATH
            .with_file(
                "/usr/local/bin/uv",
                uv_container.file("/uv"),
                permissions=0o755,  # Executable permissions
            )
            # Verify uv is installed and executable
            .with_exec(["sh", "-c", "uv --version"])
            # Configure environment
            .with_env_variable("PATH", "/app/.venv/bin:$PATH")
            .with_env_variable("UV_COMPILE_BYTECODE", "1")
            .with_env_variable("UV_LINK_MODE", "copy")
            .with_env_variable("PYTHONPATH", "/app")
        )

        if source:
            # Mount required files and directories if source is provided
            base = (
                base.with_file("/app/pyproject.toml", source.file("pyproject.toml"))
                .with_file("/app/uv.lock", source.file("uv.lock"))
                .with_file("/app/alembic.ini", source.file("alembic.ini"))
                .with_mounted_directory("/app/app", source.directory("./app"))
            )
        return (
            base
            # Install dependencies
            .with_exec(["uv", "sync", "--frozen", "--no-install-project"])
            # 
        )
#

the dockerfile :

FROM python:3.10

WORKDIR /app/

# Install uv
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
COPY --from=ghcr.io/astral-sh/uv:0.4.15 /uv /bin/uv

# Place executables in the environment at the front of the path
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#using-the-environment
ENV PATH="/app/.venv/bin:$PATH"

# Compile bytecode
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode
ENV UV_COMPILE_BYTECODE=1

# uv Cache
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#caching
ENV UV_LINK_MODE=copy

# Install dependencies
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers
RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=bind,source=uv.lock,target=uv.lock \
    --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
    uv sync --frozen --no-install-project

ENV PYTHONPATH=/app

COPY ./pyproject.toml ./uv.lock ./alembic.ini /app/

COPY ./app /app/app

# Sync the project
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync

CMD ["fastapi", "run", "--workers", "4", "app/main.py"]

buoyant chasm
#

Just a quick glance but I think the problem may be in:

.with_env_variable("PATH", "/app/.venv/bin:$PATH")

Env variables don't expand by default, you have to pass this option:

.with_env_variable("PATH", "/app/.venv/bin:$PATH", expand=True)
vestal granite
#

Okay ! I will have a look.