Skip to content

Altering editable sources when building a docker image #12681

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

Open
gibsondan opened this issue Apr 4, 2025 · 8 comments
Open

Altering editable sources when building a docker image #12681

gibsondan opened this issue Apr 4, 2025 · 8 comments
Labels
question Asking for clarification or support

Comments

@gibsondan
Copy link

Question

I'm trying to build a Docker image using uv that incorporates other packages from elsewhere in a monorepo, installing them editably. These packages are not part of the Docker context where the build command is being run.

The way that I would have done this before with pip is pretty gross, but worked:

  • Copy in all the packages from elsewhere into the repo into the folder with the Dockerfile
  • pip install them all together editably

I'm struggling to map that pattern onto the Dockerfile in the uv docker example: https://github.com/astral-sh/uv-docker-example which uses uv sync and relies on tool.uv.sources to locate the editable packages.

Specifically I have a pyproject.toml that looks like this:

[tool.uv.sources]
dagster-test = { path = '/Users/dgibson/dagster/python_modules/dagster-test', editable = true }
dagster-graphql = { path = '/Users/dgibson/dagster/python_modules/dagster-graphql', editable = true }

referencing paths outside of the Docker context.

The only option I can think of is modifying the contents of the pyproject.toml during the build to reference the new editable location after I copy it into the final folder with the Docker context.

Curious if this has come up before or if you have any other suggestions on how we might approach this. I could imagine heavy solutions like having different 'profiles' available for tool.uv.sources and being able to switch between them, but that seems like a lot.

Platform

No response

Version

No response

@gibsondan gibsondan added the question Asking for clarification or support label Apr 4, 2025
@gibsondan
Copy link
Author

Altering the Dockerfile is also entirely fair game here, but ideally it would still be using uv sync under the hood. I wouldn't be opposed to manually passing in a long list of editable overrides to the tool.uv.sources values into the uv sync command, for example.

@zanieb
Copy link
Member

zanieb commented Apr 4, 2025

Can you use relative paths instead of absolute paths?

Perhaps you could use a symlinked directory to the absolute paths outside the container then replace the symlink with a real directory with the packages copied in when inside the container?

Do you still need them to be editable?

@heathkh-recursion
Copy link

I'm also struggling with this. I was able to use relative paths for tools.uv.sources... and set the docker build context to include them. But I get back to a situation where a code change in the editable packages invalidates the uv sync layer meant to just install remote packages. Seems we need a way to have uv sync filter down to just install the remote deps in one layer, the local / editable packages in a subsequent layer.

@charliermarsh
Copy link
Member

You mean something like --no-install-workspace, but for path sources?

@zanieb
Copy link
Member

zanieb commented Apr 18, 2025

If what Charlie suggests, that'd be like #12845, e.g., --no-install-source path?

@JuR-0
Copy link

JuR-0 commented Apr 28, 2025

Just to be sure I understood what you all said above. As of right now, the only way to build a dockerfile for a project referencing local packages (that are not part of the same workspace), would be to include all of these packages in the docker context when running export --frozen?

@charliermarsh
Copy link
Member

No, if you're using --frozen, you don't need to include anything other than the root pyproject.toml and uv.lock.

@JuR-0
Copy link

JuR-0 commented Apr 28, 2025

No, if you're using --frozen, you don't need to include anything other than the root pyproject.toml and uv.lock.

I was getting an error of distribution not found for the local dependency.
I solved it by copying the pyproject.toml, lock of all the local dependencies with the same folder structure. Not sure if it's the best though?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for clarification or support
Projects
None yet
Development

No branches or pull requests

5 participants