Skip to content

dagger project CLI - #5308

Merged
sipsma merged 3 commits into
dagger:mainfrom
sipsma:project-cli
Jun 21, 2023
Merged

sipsma merged 3 commits into
dagger:mainfrom
sipsma:project-cli

Conversation

@sipsma

@sipsma sipsma commented Jun 13, 2023 •

Copy link
Copy Markdown
Contributor

This adds dagger project as a new CLI subcommand for managing a project (whereas dagger do is for invoking a command in a project).

It's extremely barebones right now, but should also be the foundation for more interesting stuff like initializing projects from templates in the future.

Examples

After pulling down this PR, run ./hack/dev to build the new cli to ./bin/dagger

Reading project metadata

sipsma@dagger_dev:~/repo/github.com/sipsma/dagger$ ./bin/dagger project --project core/integration/testdata/projects/go/basic
{
  "root": "../../../../../../",
  "name": "basic",
  "sdk": "go"
}
  • Can also add support for retrieving individual field (i.e. dagger project -p foo --sdk) if need arises
  • We can later add sugar for autodetermining the root value if not set based on the sdk. E.g. for go it could autoset to the parent dir containing go.mod.

Initializing new project

sipsma@dagger_dev:~/repo/github.com/sipsma/dagger$ ./bin/dagger project init --project /tmp/proj --sdk go --name testproj
sipsma@dagger_dev:~/repo/github.com/sipsma/dagger$ ls -la /tmp/proj/
total 52
drwxr-xr-x  2 sipsma sipsma  4096 Jun 14 16:04 .
drwxrwxrwt 14 root   root   40960 Jun 14 16:04 ..
-rw-r--r--  1 sipsma sipsma    53 Jun 14 16:04 dagger.json
sipsma@dagger_dev:~/repo/github.com/sipsma/dagger$ ./bin/dagger project -p /tmp/proj
{
  "root": "",
  "name": "testproj",
  "sdk": "go"
}

Changes to --project and --config

I realized as I started trying more corner cases that it got extremely confusing whether --config should be considered relative to --project or relative to the caller's workdir; there was no obvious way to always follow the intuitively desired behavior.

I then realized the simplest way of fixing this is to just do the simplification I've been planning anyways:

  • Removing --config. Only --project is supported now and it should point to either a dagger.json or a dir containing dagger.json
  • Adding a new optional root field to dagger.json which points to the root context that needs to be loaded in order to run the project (i.e. the dir containing go.mod or similar)

This means that you now call dagger do slightly differently, e.g.

  • ./bin/dagger do --project core/integration/testdata/projects/go/basic testFile --prefix hi
  • ./bin/dagger do -p 'git://github.com/sipsma/dagger?ref=project-cli&subpath=core/integration/testdata/projects/go/basic' --output /tmp/subdir/hi.txt testFile

TODO

  • This currently also has all the commits from Host export support for project commands #5157 in order to pick up the integ test tooling added there, should be rebased before merge
  • Basic usage docs
    • Just making the PR description the "docs" for now again, user-facing experimental docs are tracked here
  • rest of commands (probably just init for now to help create a new dagger.json)
  • tests
    • there's a few more error cases I want to add still

@sipsma sipsma changed the title WIP: dagger project CLI dagger project CLI Jun 13, 2023
@sipsma
sipsma force-pushed the project-cli branch 5 times, most recently from ac60794 to f9518c6 Compare June 14, 2023 23:38
@sipsma
sipsma requested review from d3rp3tt3, shykes and vito June 14, 2023 23:57

@TomChv TomChv left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love these changes, I think we shall merge this PR before #5305 because there will few things I need to update to make it compatible with these changes.

Overall LGTM, I left on comments about the coding style but it's definitely not blocking the merge

Comment thread cmd/dagger/project.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code can be cleaned up a bit to enhance maintainability but we shall do that later.

Few things that can be done:

  • Some comments
  • Some breaking line between code block
  • Some formatting

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some renaming and added a couple more comments and doc strings to the parts that stuck out to me as potentially most confusing, but let me know what else you would like clarified. Happy to update here or in followups.

@helderco helderco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread cmd/dagger/project.go Resolved
Comment thread core/integration/suite_test.go Resolved
@d3rp3tt3

Copy link
Copy Markdown
Contributor

I created a UX PoC of an interactive UX for the CLI. This would accompany using flags. This approach could help make adopting Dagger by new users easier. This shows how we might use templates too. This example is from a few weeks ago, so it doesn't map up totally with the latest. For instance, this doesn't show setting up the project entrypoint.

sipsma added 2 commits June 20, 2023 16:28
This simplifies dagger project and dagger do by getting rid of the
--config flag and only asking for a --project flag.

The previous need for the two was that project specified the "root"
which needed to be loaded in order for the project to run, whereas
config specified the path to the dagger.json.

This is inherently confusing, but gets even more confusing when you
start needing to deal with corner cases around whether the config path
should be considered relative to the caller's workdir or relative to the
project dir.

Now, we have a new "root" field in dagger.json that, if set, will be
loaded as the root context for the project. This allows us to get rid of
the config flag and just use --project to point to dagger.json (or its
parent dir).

For git projects, we now consolidate all settings, including the newly
added "subdir" as query parameters on the "git://" URI. Query params are
not beautiful, but it's probably an upgrade from the previous use of
fragments, which break shells due to interpretation of "#" as a comment.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma

sipsma commented Jun 20, 2023

Copy link
Copy Markdown
Contributor Author

@d3rp3tt3 yeah I totally agree we should have some UX polish just like that! It could be very nice when integrated with the interactive TUI especially.

I do think that we will want to also keep the "low-tech" solution of being able to just pass with flags like dagger project init --sdk python in order to enable it to be called programmatically. That also happens to be much easier to implement, which is the real reason why I've done it here 😄

Do you want to create a Linear issue for what you are imagining here? Or I'm happy too also. I just think it's probably best left for a follow-up since it requires some design.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma

sipsma commented Jun 21, 2023

Copy link
Copy Markdown
Contributor Author

This PR is a dependency on a few others, so I'm going to merge this as is for now since all the functionality is hidden away and not public yet anyways. Please feel free to provide more feedback though, happy to address in follow ups.

@sipsma
sipsma merged commit 7c90345 into dagger:main Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants