Skip to content

For discussion: Alternative to #dagger:compute syntax - #128

Closed
aluzzardi wants to merge 1 commit into
mainfrom
component-annotation
Closed

aluzzardi wants to merge 1 commit into
mainfrom
component-annotation

Conversation

@aluzzardi

Copy link
Copy Markdown
Contributor

NOTE: this PR is for illustration purposes only, tests etc are broken.

This is a follow up to #118 (read that PR for context) and a mashup of:

  • @shykes's #run proposal
  • @dubo-dubon-duponey's feedback of "less black magic" (e.g. use the imported dagger library for everything, no special magic values)
  • @verdverm's suggestion of using annotations

What this does is provide a dagger.#Component definition that users embed into their Cue types to add dagger computation (no "magic" #dagger anymore)

The embedded dagger.#Component defines a #run -- from this point on it's exactly the same as #118 with a twist: the #run definition has a @dagger() annotation. The runtime specifically checks for this annotation, ignores everything that doesn't have it.

This is to avoid namespace collisions: The downside of using #run instead of #dagger is we might clash with user configuration that has nothing to do with dagger. Because of the (internal) @dagger() annotation, user config can make use of the keyword #run for their own purposes without clashing.

The syntax needs some work, I think it can look better. Here's an example:

import (
  "dagger.io/dagger"
)

foo: {
  url: string

  dagger.#Component & {
    #run: [
      dagger.#FetchContainer & {
        ref: "alpine@sha256:08d6ca16c60fe7490c03d10dc339d9fd8ea67c6466dea8d558526b1330a85930"
      },
    ]
  }
}

For "data-less" components it looks like this:

repository: dagger.#Component & {
	#run: [
		dagger.#FetchGit & {
			remote: "https://github.com/kabirbaidhya/react-todo-app.git"
			ref:    "624041b17bd62292143f99bce474a0e3c2d2dd61"
		},
	]
}

The #Component definition is as simple as

#Component: {
	#run: [...#Op] @dagger()
}

I have a feeling annotations are super powerful and might unlock an even better UX, I just don't see it yet. @shykes @verdverm any thoughts?

For instance, half baked idea: we could have a definition like #Run: [...#Op] @dagger(), which would allow to write anywhere in the config dagger.#Run & [dagger.#FetchContainer{ ... }].

Signed-off-by: Andrea Luzzardi <[email protected]>
@verdverm

Copy link
Copy Markdown
Contributor

attributes (annotations) can have a string inside them which Cue will parse into key/value pairs, which is where I think the real power / UX can come from. There is less validation of them though and they are not part of unification

I've written @eject(<image-name>) as a simple first example and tried to find them all (not familiar enough with dagger code yet, but the task is helping!)

I've also opened this issue regarding attributes and what I was trying for dagger (cuelang/cue#774)

Attributes need a bit of UX improvement on the Cue side (as a dev importing Cue into my tool), I have several issues / PRs on this

@aluzzardi

Copy link
Copy Markdown
Contributor Author

@verdverm nice.

We certainly can use attributes internally to flag our operations, but I'm not sure we want to expose them to end users:

  • Yet another (sub) syntax to learn
  • Different behavior, especially in error handling (e.g. we'd have to handle errors in dagger as Cue won't help with that)
  • Consistency: Long term we'll have an extensive standard library. You'll be able to do things like import dagger.io/go go.#Build & { ... }. It's going to be rare to use the low level calls such as dagger.#Exec, so it would look strange if you're using a bunch of definitions everywhere (from the stdlib) but then need to use something completely different (attributes) when doing a few low-level calls directly

@verdverm

Copy link
Copy Markdown
Contributor

That will make implementing eject easier today, thanks for the context

@verdverm

verdverm commented Feb 19, 2021 •

Copy link
Copy Markdown
Contributor

Because of the (internal) @dagger() annotation, user config can make use of the keyword #run for their own purposes without clashing.

If these two #run defs were in the same Cue value / struct, they would unify and likely conflict if the user's intention was to have their #run do something else

I also don't think annotations are coming through imports currently

Marcel is working on them apparently cuelang/cue#529 (comment)

@shykes

shykes commented Feb 24, 2021

Copy link
Copy Markdown
Contributor

We discussed this with @aluzzardi yesterday, here is a summary of our conclusion.

On the use of annotations:

In order to decide if we want to use annotations for this, we must first decide whether using our helper types is the only recommended way to write a dagger configuration, or if writing “naked” configurations (without helper types) is equally correct.

  • If it’s the former (helper types only), then it makes sense to consider this, because the additional complexity of annotations + definitions will be mostly hidden from developers.

  • If it’s the latter (with or without helper types), then this proposal would increase the complexity of naked configurations, and consequently increase the difficulty of learning dagger.

Additionally, it may be premature to address namespace conflicts because it’s possible that in the future Cue will support namespacing of definitions by package (from a past conversation with Marcel). And in the meantime namespace conflict on #run is probably not a big deal, especially since components cannot be nested.

@shykes

shykes commented Feb 24, 2021

Copy link
Copy Markdown
Contributor

Based on our last discussion, I suggest the following:

  1. We table the use of annotations for now. I’m convinced we will find a good use for them eventually, but it feels like right now we have a lot on our plate already and this can afford to wait.

  2. We move forward on replacing #dagger:compute with #run in a standalone PR, it seems that we had consensus on the usefulness of that. We can refresh Attach compute pipelines to a value with #compute rather than #dagger.compute #118 (I’m happy to do the work) or start fresh, whichever you think is best @aluzzardi . I do think we should try to push this one through quickly to score an incremental win.

  3. We start a discussion thread to decide on whether using helper types should be A) mandatory or B) optional.

WDYT?

@aluzzardi

Copy link
Copy Markdown
Contributor Author

In order to decide if we want to use annotations for this, we must first decide whether using our helper types is the only recommended way to write a dagger configuration, or if writing “naked” configurations (without helper types) is equally correct.

👍

I'm starting to form an opinion on this after writing some configs, I'd be happy to have a conversation soon. Would be curious to hear from others.

That being said, I agree it should be its own conversation and shouldn't hold back these incremental changes.

We table the use of annotations for now. I’m convinced we will find a good use for them eventually, but it feels like right now we have a lot on our plate already and this can afford to wait.

👍 Really depends on figuring out naked vs helper-types

We move forward on replacing #dagger:compute with #run in a standalone PR, it seems that we had consensus on the usefulness of that. We can refresh #118 (I’m happy to do the work) or start fresh, whichever you think is best @aluzzardi . I do think we should try to push this one through quickly to score an incremental win.

Either refresh #118 or start fresh, whichever is easier.

There's one more thing though this proposal tried to address, it's @dubo-dubon-duponey's feedback (#118 (comment)):

It feels a little bit weird to have part of dagger SDK being imported with the natural cue mechanism, under their own namespace (import, then call dagger.#Bla), while some other parts (#dagger.compute) are just there, magically, in the global namespace.

This PR addressed that with the following:

#Component: {
	#run: [...#Op] @dagger()
}

Which you would use like so:

#Foo: {
	source: dagger.#Dir
	dagger.#Component & {
		#run: [ ... ]
         }
}

As you can see, this is purely a UX change, there's no impact in how dagger sees things (e.g. it's a dagger.cue addition on top of #118, no Go changes).

Even though it's a fairly minimal change, in a "helper types only" config, you can write the entire configuration using the dagger package, without "magic" keywords (e.g. dagger.#Component + dagger.#FetchContainer instead of #run + op: "fetch-container")

@shykes

shykes commented Feb 24, 2021

Copy link
Copy Markdown
Contributor

Either refresh #118 or start fresh, whichever is easier.

Ok I will refresh #118 then, seems easier as it’s mostly manual search-replace.

There's one more thing though this proposal tried to address, it's @dubo-dubon-duponey's feedback (#118 (comment)):

It feels a little bit weird to have part of dagger SDK being imported with the natural cue mechanism, under their own namespace (import, then call dagger.#Bla), while some other parts (#dagger.compute) are just there, magically, in the global namespace.

This PR addressed that with the following:

#Component: {
	#run: [...#Op] @dagger()
}

Which you would use like so:

#Foo: {
	source: dagger.#Dir
	dagger.#Component & {
		#run: [ ... ]
         }
}

As you can see, this is purely a UX change, there's no impact in how dagger sees things (e.g. it's a dagger.cue addition on top of #118, no Go changes).

Even though it's a fairly minimal change, in a "helper types only" config, you can write the entire configuration using the dagger package, without "magic" keywords (e.g. dagger.#Component + dagger.#FetchContainer instead of #run + op: "fetch-container")

What I don’t understand about that part is that you still have to write #run, and you can already use dagger.#FetchContainer etc. to avoid running op: “fetch-container”. So it’s not clear to me what problem this solves. Sorry @dubo-dubon-duponey if I’m misunderstanding your feedback.

In any case, if this change could potentially be useful regardless of whether helper types are optional or mandatory, I guess it makes sense to spin it out into its own PR and continue the discussion there?

@aluzzardi

Copy link
Copy Markdown
Contributor Author

What I don’t understand about that part is that you still have to write #run, and you can already use dagger.#FetchContainer etc. to avoid running op: “fetch-container”.

The difference is that #run becomes a property of dagger.#Component rather than being a "special" key/path. In other words, you're using dagger entirely via the import: you import dagger, embed a dagger.#Component, call dagger.#Ops, etc. All your interactions with the dagger API are through the package, no "implicit" API.

I'll let @dubo-dubon-duponey chime in here

In any case, if this change could potentially be useful regardless of whether helper types are optional or mandatory, I guess it makes sense to spin it out into its own PR and continue the discussion there?

Yes agreed. I believe it's useful in both scenarios. Of course you'd only want to use this on helper-based configs, not on naked ones.

@aluzzardi

Copy link
Copy Markdown
Contributor Author

Closing this -- superseded by #118

@aluzzardi aluzzardi closed this Mar 4, 2021
@aluzzardi
aluzzardi deleted the component-annotation branch April 15, 2021 17:26
aluzzardi pushed a commit that referenced this pull request Sep 16, 2022
docs: small improvements/fixes
shykes added a commit that referenced this pull request Jun 12, 2026
…state

The section's checkboxes had drifted — nearly everything implemented
shipped under a [ ] marker. Replace with explicit status legend:

  ✅ shipped on this branch
  🟡 partially shipped (different shape than design)
  ⬜ designed, not yet implemented

Categorized by surface area:
- Shipped — top-level / module / api / cloud / workspace / config /
  schema / flag rename / removals / hidden aliases
- 🟡 Partial — current --sdk-flag init shapes vs. designed positional
  dispatch (module init, api client init). Includes the note that
  --option on client init is dead plumbing today.
- ⬜ Not yet implemented — handoff items with task references:
  - dagger sdk top-level group (tasks #120, #122-#124)
  - init reshape to positional + dynamic SDK flags (tasks #125-#128)
  - initModule/initClient capability semantics + targetRuntime wiring
    (task #129)
  - dagger exec → dagger api exec (task #130)
  - cloneModuleAsSDK empty-marker preservation (task #121)
  - Default-SDK inference, SDK codegen regen, --option removal
- Known unfixed items reduced to just the legitimate one (workspace
  concept needs a one-liner definition).

Status line updated from "Proposed" to reflect actual landing state.
eunomie pushed a commit to eunomie/dagger that referenced this pull request Jun 16, 2026
…state

The section's checkboxes had drifted — nearly everything implemented
shipped under a [ ] marker. Replace with explicit status legend:

  ✅ shipped on this branch
  🟡 partially shipped (different shape than design)
  ⬜ designed, not yet implemented

Categorized by surface area:
- Shipped — top-level / module / api / cloud / workspace / config /
  schema / flag rename / removals / hidden aliases
- 🟡 Partial — current --sdk-flag init shapes vs. designed positional
  dispatch (module init, api client init). Includes the note that
  --option on client init is dead plumbing today.
- ⬜ Not yet implemented — handoff items with task references:
  - dagger sdk top-level group (tasks dagger#120, dagger#122-dagger#124)
  - init reshape to positional + dynamic SDK flags (tasks dagger#125-dagger#128)
  - initModule/initClient capability semantics + targetRuntime wiring
    (task dagger#129)
  - dagger exec → dagger api exec (task dagger#130)
  - cloneModuleAsSDK empty-marker preservation (task dagger#121)
  - Default-SDK inference, SDK codegen regen, --option removal
- Known unfixed items reduced to just the legitimate one (workspace
  concept needs a one-liner definition).

Status line updated from "Proposed" to reflect actual landing state.

Signed-off-by: Solomon Hykes <[email protected]>
eunomie pushed a commit to eunomie/dagger that referenced this pull request Jun 16, 2026
…state

The section's checkboxes had drifted — nearly everything implemented
shipped under a [ ] marker. Replace with explicit status legend:

  ✅ shipped on this branch
  🟡 partially shipped (different shape than design)
  ⬜ designed, not yet implemented

Categorized by surface area:
- Shipped — top-level / module / api / cloud / workspace / config /
  schema / flag rename / removals / hidden aliases
- 🟡 Partial — current --sdk-flag init shapes vs. designed positional
  dispatch (module init, api client init). Includes the note that
  --option on client init is dead plumbing today.
- ⬜ Not yet implemented — handoff items with task references:
  - dagger sdk top-level group (tasks dagger#120, dagger#122-dagger#124)
  - init reshape to positional + dynamic SDK flags (tasks dagger#125-dagger#128)
  - initModule/initClient capability semantics + targetRuntime wiring
    (task dagger#129)
  - dagger exec → dagger api exec (task dagger#130)
  - cloneModuleAsSDK empty-marker preservation (task dagger#121)
  - Default-SDK inference, SDK codegen regen, --option removal
- Known unfixed items reduced to just the legitimate one (workspace
  concept needs a one-liner definition).

Status line updated from "Proposed" to reflect actual landing state.

Signed-off-by: Solomon Hykes <[email protected]>
eunomie pushed a commit that referenced this pull request Jun 17, 2026
…state

The section's checkboxes had drifted — nearly everything implemented
shipped under a [ ] marker. Replace with explicit status legend:

  ✅ shipped on this branch
  🟡 partially shipped (different shape than design)
  ⬜ designed, not yet implemented

Categorized by surface area:
- Shipped — top-level / module / api / cloud / workspace / config /
  schema / flag rename / removals / hidden aliases
- 🟡 Partial — current --sdk-flag init shapes vs. designed positional
  dispatch (module init, api client init). Includes the note that
  --option on client init is dead plumbing today.
- ⬜ Not yet implemented — handoff items with task references:
  - dagger sdk top-level group (tasks #120, #122-#124)
  - init reshape to positional + dynamic SDK flags (tasks #125-#128)
  - initModule/initClient capability semantics + targetRuntime wiring
    (task #129)
  - dagger exec → dagger api exec (task #130)
  - cloneModuleAsSDK empty-marker preservation (task #121)
  - Default-SDK inference, SDK codegen regen, --option removal
- Known unfixed items reduced to just the legitimate one (workspace
  concept needs a one-liner definition).

Status line updated from "Proposed" to reflect actual landing state.

Signed-off-by: Solomon Hykes <[email protected]>
eunomie pushed a commit that referenced this pull request Jun 18, 2026
…state

The section's checkboxes had drifted — nearly everything implemented
shipped under a [ ] marker. Replace with explicit status legend:

  ✅ shipped on this branch
  🟡 partially shipped (different shape than design)
  ⬜ designed, not yet implemented

Categorized by surface area:
- Shipped — top-level / module / api / cloud / workspace / config /
  schema / flag rename / removals / hidden aliases
- 🟡 Partial — current --sdk-flag init shapes vs. designed positional
  dispatch (module init, api client init). Includes the note that
  --option on client init is dead plumbing today.
- ⬜ Not yet implemented — handoff items with task references:
  - dagger sdk top-level group (tasks #120, #122-#124)
  - init reshape to positional + dynamic SDK flags (tasks #125-#128)
  - initModule/initClient capability semantics + targetRuntime wiring
    (task #129)
  - dagger exec → dagger api exec (task #130)
  - cloneModuleAsSDK empty-marker preservation (task #121)
  - Default-SDK inference, SDK codegen regen, --option removal
- Known unfixed items reduced to just the legitimate one (workspace
  concept needs a one-liner definition).

Status line updated from "Proposed" to reflect actual landing state.

Signed-off-by: Solomon Hykes <[email protected]>
tiborvass pushed a commit that referenced this pull request Jun 19, 2026
…state

The section's checkboxes had drifted — nearly everything implemented
shipped under a [ ] marker. Replace with explicit status legend:

  ✅ shipped on this branch
  🟡 partially shipped (different shape than design)
  ⬜ designed, not yet implemented

Categorized by surface area:
- Shipped — top-level / module / api / cloud / workspace / config /
  schema / flag rename / removals / hidden aliases
- 🟡 Partial — current --sdk-flag init shapes vs. designed positional
  dispatch (module init, api client init). Includes the note that
  --option on client init is dead plumbing today.
- ⬜ Not yet implemented — handoff items with task references:
  - dagger sdk top-level group (tasks #120, #122-#124)
  - init reshape to positional + dynamic SDK flags (tasks #125-#128)
  - initModule/initClient capability semantics + targetRuntime wiring
    (task #129)
  - dagger exec → dagger api exec (task #130)
  - cloneModuleAsSDK empty-marker preservation (task #121)
  - Default-SDK inference, SDK codegen regen, --option removal
- Known unfixed items reduced to just the legitimate one (workspace
  concept needs a one-liner definition).

Status line updated from "Proposed" to reflect actual landing state.

Signed-off-by: Solomon Hykes <[email protected]>
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.

3 participants