pub icon indicating copy to clipboard operation
pub copied to clipboard

Provide a way to ignore the workspace when running pub commands

Open kevmoo opened this issue 1 year ago • 5 comments

Scenario: you have a package that you want to use in docker.

You copy the package contents into docker and expect dart pub ... to work, but it fails because you haven't copied the entire repo.

I've had to create a hack script to delete the workspace property out of a pubspec to make things work. Not ideal.

kevmoo avatar Aug 19 '24 23:08 kevmoo

I can see the need for this.

However if we do this as a flag to pub get (such as --ignore-workspace) we have a problem that this will not "stick" when eg. dart run is doing automatic validation of the resolution.

We could make a command like dart pub workspace drop that removes resolution workspace from the pubspec.yaml.

@jonasfj any ideas?

sigurdm avatar Aug 20 '24 07:08 sigurdm

Talking with @jonasfj here are some options for consuming the package inside the docker image:

  • Instead of using the package directly in the docker file, make a dummy package that depends on that package, and use that for running the program inside the container
  • Or (more or less equivalently) use pub global activate -spath to consume the package.
  • Or just copy the entire workspace into the container.

Also if we really wanted to provide something like this, it should probably be as an environment variable, as that could stick between commands.

sigurdm avatar Aug 22 '24 11:08 sigurdm

@kevmoo do any of the above solutions work for you?

sigurdm avatar Aug 28 '24 09:08 sigurdm

I'd LOVE to have an environment variable that's just PUB_IGNORE_WORKSPACE

kevmoo avatar Aug 30 '24 21:08 kevmoo

Scenario: you have a package that you want to use in docker.

Copy the entire workspace into the container. Ideally, build an AOT snapshot and insert it into a docker image that only has the AOT-runtime (using docker multistage builds).

That said, I see how this is annoying, because docker build and similar tools can copy in files above Dockerfile.

How about using pubspec_override.yaml to specify resolution: null or resolution: root. It's a bit annoying to have to create such a file in a docker container after copying over the source files.


Do note that you actually run into one more problem. You are not copying over pubspec.lock, because it's sitting the workspace root. This means that: You'd be deploying untested code!.

Inside a Dockerfile one really should only ever use dart pub get --enforce-lockfile. So if you use workspaces, you'll need to copy over the entire workspace.

Or we'll need to:

  • Implement resolution: local; and;
  • Support a mechanism for opting out of workspace-resolution when resolution: local is present, but parent directories are not copied into the docker container.

jonasfj avatar Sep 04 '24 10:09 jonasfj

With: https://github.com/dart-lang/pub/pull/4400 you can drop a file called pubspec_overrides.yaml reading: resolution: (ie. resolution: null) next to the pubspec.yaml and make pub ignore the workspace.

@kevmoo does that work for you?

sigurdm avatar Sep 30 '24 12:09 sigurdm

@sigurdm – it'd be nice to just have a CLI option. But just adding a file and removing it is much more scriptable than trying to use sed in a Docker script 😄

kevmoo avatar Nov 03 '24 00:11 kevmoo

@sigurdm – it'd be nice to just have a CLI option. But just adding a file and removing it is much more scriptable than trying to use sed in a Docker script 😄

Ok - I'll close this issue for now then.

sigurdm avatar Nov 04 '24 08:11 sigurdm

Similar to what @jonasfj said, you really kind of want a command that "exports" a per-package lockfile that you can then copy into the docker container, rather than the behavior of just ignoring the workspace, since you end up deploying potentially different versions than you were testing with.

Seems like although this command is probably useful for other scenarios it doesn't really solve the docker problem, but maybe we have other (non-closed) bugs tracking the rest of the "how to use workspaces + monorepo + docker together" issue?

eseidel avatar Jun 02 '25 20:06 eseidel

If the issue with copying the entire workspace is disk space, you could copy just the "skeleton" of the workspace. (only copy the directory structure, and pubspec.yaml file of every workspace package except the one you want into the container...)

sigurdm avatar Jun 03 '25 07:06 sigurdm