Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uv sync in workspace during docker build doesn't install dependencies #8460

Open
VVoruganti opened this issue Oct 22, 2024 · 1 comment
Open
Labels
needs-mre Needs more information for reproduction

Comments

@VVoruganti
Copy link

VVoruganti commented Oct 22, 2024

I have a project that is making use of the uv workspaces feature. It has the following structure

.
├── pyproject.toml
├── uv.lock
├── bot/
│   └── pyproject.toml
├── api/
│   └── pyproject.toml
└── agent/
    ├── agent/
    ├── pyroject.toml
    └── dist/

This is my root pyproject.toml

[project]
name = "tutor-gpt"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
    "honcho-ai>=0.0.15",
    "python-dotenv>=1.0.1",
]

[tool.uv.sources]
agent = { workspace = true }
api = { workspace = true }
bot = { workspace = true }

[tool.uv.workspace]
members = ["agent/", "api/", "bot/"]
exclude = ["www/*"]

The agent package is installed by the other two apps.

I need to build a docker image that setups up the api package so I modified the cached example in the docs.

FROM python:3.11-slim-bullseye

COPY --from=ghcr.io/astral-sh/uv:0.4.9 /uv /bin/uv

# Set Working directory
WORKDIR /app

RUN addgroup --system app && adduser --system --group app
RUN chown -R app:app /app
USER app

# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1

# Copy from the cache instead of linking since it's a mounted volume
ENV UV_LINK_MODE=copy

# Install the project's dependencies using the lockfile and settings
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-workspace --no-dev

# Copy only requirements to cache them in docker layer
COPY --chown=app:app pyproject.toml uv.lock  /app/

# Place executables in the environment at the front of the path
ENV PATH="/app/.venv/bin:$PATH"

EXPOSE 8000

COPY --chown=app:app agent/ /app/agent/
COPY --chown=app:app bot/ /app/bot/
COPY --chown=app:app api/ /app/api/

RUN --mount=type=cache,target=/root/.cache/uv \
      uv sync --frozen --package api

CMD ["fastapi", "run", "--host", "0.0.0.0", "api/main.py"]

When I run my container I'm getting the following error which indicated to me that none of the packages installed.

docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "fastapi": executable file not found in $PATH: unknown.

I verified this by opening a shell in the container

app@612b3a28fa65:/app$ uv pip list
app@612b3a28fa65:/app$ uv sync --package api
Resolved 54 packages in 2ms
Audited in 0.00ms
app@612b3a28fa65:/app$

I've noticed that I can force the container to install packages if I remove the uv.lock and the --frozen tag, but that not desirable for having truly reproducible builds.

@charliermarsh
Copy link
Member

Do you mind providing a reproduction with code, like a Git repo I can clone? I'm happy to help but it's time consuming to scaffold this stuff.

@charliermarsh charliermarsh added the needs-mre Needs more information for reproduction label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-mre Needs more information for reproduction
Projects
None yet
Development

No branches or pull requests

2 participants