Skip to content

Implements dagger do#1648

Merged
talentedmrjones merged 1 commit intodagger:mainfrom
talentedmrjones:dagger-do-help
Mar 1, 2022
Merged

Implements dagger do#1648
talentedmrjones merged 1 commit intodagger:mainfrom
talentedmrjones:dagger-do-help

Conversation

@talentedmrjones
Copy link
Copy Markdown

@talentedmrjones talentedmrjones commented Feb 22, 2022

dagger do is an evolution of what was dagger up -t. By organizing related actions under a single key, dagger do let's you easily target that part of the plan, making dagger very similar to and a modern replacement for make

$ dagger do --help -p ./actions.cue          
dagger [OPTIONS] do <ACTION> [SUB ACTION]

Execute a Dagger action

Global options:
-p, --project   PATH|ADDRESS           Specify a project (default: current directory)
-l, --log-level ...
--with OVERRIDE            Apply a Cue expression as override.

Actions available in plan loaded from ./actions.cue:

actions:
  core-integration      Run core integration tests
  dagger-debug          Build a debug version of the dev dagger binary
  doc-test              Test docs
  europa-universe-test  Run Europa universe tests
  universe-test         Run universe tests
  cuefmt                Format all cue files
  cuelint               Lint and format all cue files
  dagger                Build a dev dagger binary
  docs                  Generate docs
  docslint              Generate & lint docs
  frontend              Frontend actions
  golint                Go lint
  help                  Show how to get started & what targets are available
  install               Install a dev dagger binary
  integration           Run all integration tests
  lint                  Lint everything
  shellcheck            Run shellcheck
  test                  Run all tests
  todo                  Find all TODO items

The actions listed here are pulled from the actions: key of the plan, and the description is pulled from the comment associated with the field. The actions positional arguments allow you to target subactions (and have no limit to depth):

$ dagger do --help -p ./actions.cue frontend
dagger [OPTIONS] do <ACTION> [SUB ACTION]

Execute a Dagger action

Global options:
-p, --project   PATH|ADDRESS           Specify a project (default: current directory)
-l, --log-level ...
--with OVERRIDE            Apply a Cue expression as override.

Actions available in plan loaded from ./actions.cue:

actions.frontend:
  build  Build via yarn
  test   Test via headless browser

Signed-off-by: Richard Jones

@talentedmrjones
Copy link
Copy Markdown
Author

@shykes here ya go!

@talentedmrjones talentedmrjones mentioned this pull request Feb 22, 2022
@shykes
Copy link
Copy Markdown
Contributor

shykes commented Feb 22, 2022

Nice! Based on your implementation work so far, does it seem doable in a robust way? Anything notable that you noticed? Design tradeoffs, feasability issues?

@shykes
Copy link
Copy Markdown
Contributor

shykes commented Feb 22, 2022

One question in particular: how should we (and can we?) handle multiple levels of depth? For example in this case:

actions: {
  frontend: {
    build: {
      ...
    }
    test: {
      ...
    }
}

Ideally dagger help do would output only one command: frontend.

Then dagger help frontend would, in turn output two commands: build and test.

Do you see any obstacles to implementing it this way?

@talentedmrjones
Copy link
Copy Markdown
Author

I don't see any issues right now but will try and report back. Until then it's worth noting that the form dagger help do panics where dagger do --help does not. It will take me a bit to figure that one out, but will try the multiple levels with the latter form.

@talentedmrjones talentedmrjones linked an issue Feb 23, 2022 that may be closed by this pull request
@aluzzardi
Copy link
Copy Markdown
Contributor

POC looks good to me.

Some suggestions regarding the architecture: one outstanding issue I see is we have a custom "actions scanner" within cmd/do which is separate from the "core actions scanner" we have in the runtime (e.g. cue flow).

Knowing about actions is not only useful to dagger do but will also be useful to the rest of the runtime (e.g. structuring logs, error messages, etc).

The Actions API proposal helps formalizing that, but in the meantime, I think we can achieve something very similar by leveraging cue flow (credits to @shykes for the idea).

In a nutshell:

  • plan.Plan could expose an Actions() function, returning the list of actions in the plan
  • Each Action would have a Children(), containing sub-actions
  • To scan for actions, we can use flow -- the same instance we use for executing
  • Flow provides some nice introspection capabilities.,Tasks() returns the list of detected tasks. Each Task provides a list of Dependencies() along with the task Value (e.g. can be used to introspect the docstring)

The naive implementation (without Actions API) would be to use flow to scan for "core actions" (e.g. tasks) and then assume every parent in the tree is an action as well.

To illustrate:

actions: {
		web: frontend: {
 			// Build via yarn
 			build: yarn.#Build & { ... }
...
  • flow would list actions.web.frontend.build.container._exec as a "core action" (_exec task somewhere down yarn.#Build)
  • We use this to build a "graph" of Actions, assuming (for now) parents are actions. In this case, "web" is an action with "frontend" as a child, and so on and so forth until web.frontend.build.container._exec
  • While we're building this graph, we can add additional metadata from CUE values. Docstring is an example. The package import path is another (e.g. which package defines the CUE value)
  • We can then use this information for display in dagger do -- for instance, skip actions that are defined in external packages (e.g. we'd show web, frontend and build, but skip container and _exec since they're defined outside)

Once we move forward with the Actions API, we'd only need to update the core logic in plan.Actions and it will be reflected in dagger do and other usages.

@talentedmrjones talentedmrjones changed the title [POC] prototype of dagger do help Implementes dagger do Feb 28, 2022
@talentedmrjones talentedmrjones changed the title Implementes dagger do Implements dagger do Feb 28, 2022
@talentedmrjones talentedmrjones force-pushed the dagger-do-help branch 2 times, most recently from b2d9d2a to 45dbb1f Compare February 28, 2022 23:07
@samalba
Copy link
Copy Markdown
Contributor

samalba commented Mar 1, 2022

FWIW, I tested on one of my sample config it works great. LGTM on my side.

@talentedmrjones talentedmrjones force-pushed the dagger-do-help branch 2 times, most recently from 66ad128 to 55ec9b0 Compare March 1, 2022 18:08
Signed-off-by: Richard Jones <[email protected]>
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 1, 2022

@talentedmrjones talentedmrjones merged commit e055244 into dagger:main Mar 1, 2022
@talentedmrjones talentedmrjones deleted the dagger-do-help branch March 1, 2022 21:17
@shykes
Copy link
Copy Markdown
Contributor

shykes commented Mar 2, 2022

Nice work!

@helderco helderco mentioned this pull request Mar 8, 2022
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.

0.2 CLI

4 participants