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

Provide a way to ignore the workspace when running pub commands #4357

Closed
kevmoo opened this issue Aug 19, 2024 · 8 comments
Closed

Provide a way to ignore the workspace when running pub commands #4357

kevmoo opened this issue Aug 19, 2024 · 8 comments
Labels
type-enhancement A request for a change that isn't a bug

Comments

@kevmoo
Copy link
Member

kevmoo commented Aug 19, 2024

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 added a commit to GoogleCloudPlatform/functions-framework-dart that referenced this issue Aug 19, 2024
@sigurdm sigurdm added the type-enhancement A request for a change that isn't a bug label Aug 20, 2024
@sigurdm
Copy link
Contributor

sigurdm commented Aug 20, 2024

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
Copy link
Contributor

sigurdm commented Aug 22, 2024

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
Copy link
Contributor

sigurdm commented Aug 28, 2024

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

@kevmoo
Copy link
Member Author

kevmoo commented Aug 30, 2024

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

@jonasfj
Copy link
Member

jonasfj commented Sep 4, 2024

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.

@sigurdm
Copy link
Contributor

sigurdm commented Sep 30, 2024

With: #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?

@kevmoo
Copy link
Member Author

kevmoo commented Nov 3, 2024

@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 😄

@sigurdm
Copy link
Contributor

sigurdm commented Nov 4, 2024

@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 sigurdm closed this as completed Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants