Skip to content

Host resources - #10753

Closed
shykes wants to merge 1 commit into
dagger:mainfrom
shykes:host-resources
Closed

shykes wants to merge 1 commit into
dagger:mainfrom
shykes:host-resources

Conversation

@shykes

@shykes shykes commented Jul 18, 2025 •

Copy link
Copy Markdown
Contributor

Overview

This introduces a unified naming system for host resources, and an API for loading them.

Host resources are useful anytime you need a text representation for various resources in the Dagger API, and a simple way to convert that text representation to a typed object.

Purpose

This removes logic that already exists in the CLI, and moves it to the engine. That will allow implementing #10697 which is part of #10370 .

@shykes
shykes force-pushed the host-resources branch 2 times, most recently from c57ae21 to f1b1bc7 Compare July 18, 2025 17:11
@shykes
shykes marked this pull request as ready for review July 18, 2025 17:11
@shykes
shykes requested review from a team as code owners July 18, 2025 17:11
@shykes
shykes requested review from sipsma and vito July 18, 2025 17:11
@shykes
shykes requested review from eunomie and grouville July 18, 2025 17:20
@shykes

shykes commented Jul 18, 2025

Copy link
Copy Markdown
Contributor Author

Open question: are these host resources, or just... resources?

@vito

vito commented Jul 18, 2025

Copy link
Copy Markdown
Contributor

Open question: are these host resources, or just... resources?

'Host resources' makes sense to me since they're always resolved relative to the host - e.g. when you pass localhost:1234 as a service arg, ./foo as a directory/file, etc.

It also makes sense to gatekeep them a bit, e.g. modules currently can't access the Host API, and that feels like what we'd want here?

@sipsma

sipsma commented Jul 18, 2025

Copy link
Copy Markdown
Contributor

Open question: are these host resources, or just... resources?

host doesn't make sense to me in this example:

host | resource https://github.com/dagger/dagger | as-git-repository

Since it's a remote git repo.

I'd personally vote for just dropping the leading host and adding a new top-level, e.g.

resource https://github.com/dagger/dagger | as-git-repository

But not highly opinionated there.


Also seems like we'll might want to add an enum alongside each of the as* fields that indicates which type it actually is. That way clients can do something like:

resource := dag.Resource("env://FOO")
kind, err := resource.Kind(ctx) // returns an enum indicating which kind of resource it is
if err != nil { // ... }
switch kind {
case dagger.SecretResourceKind:
   secret := resource.AsSecret()
   // do stuff with it ...
case dagger.Container:
   ctr := resource.AsContainer()
   // do stuff with it ...
}

That's what we've done for other similar parts of the API (like ModuleSource). Otherwise you are forced to try each as* field and see if it returns an error; that'd be weird, would create confusing telemetry, not be especially performant, etc. etc.

However, that does bring up the related question of whether it's always going to be a one-to-one mapping of a given URI to its valid "kind" (container, secret, etc.) or if it would every make sense for multiple to be possible.

e.g. I suppose since we support turning a local dir into a GitRepository both of these might be allowed:

  1. resource ./some/local/git/dir | as-directory
  2. resource ./some/local/git/dir | as-git-repository

In which case the enum idea might need some adjustment 🤔 Just food for thought at this point

@shykes

shykes commented Jul 18, 2025

Copy link
Copy Markdown
Contributor Author

@sipsma yeah in this case it's specifically not going to be a one-to-one mapping IMO. This design is an attempt at making the API more readable and concise - but conceptually it could also be done like this:

loadDirectory(address: String!): Directory!
loadSecret(address: String!): Secret!
loadFile(address: String!): File!
loadGitRepository(address: String!): GitRepository!

And so on.

@shykes

shykes commented Jul 18, 2025

Copy link
Copy Markdown
Contributor Author

@sipsma re: dropping the "host": yeah I was wondering the same thing.

  • On the one hand: as you said, calling it "host" is pushing it in some cases...
  • But on the other hand: if we remove "host", there are some cases where the address is interpreted in a very host-specific way (env://FOO, op://FOO, ~/foo, cmd:foo etc) so it would feel like an exception to host()...

@jedevc

jedevc commented Jul 21, 2025

Copy link
Copy Markdown
Contributor

Just to throw another design point into the mix - if we put it behind host it definitely won't be accessible to modules. Do we want it exposed to modules? If so, we probably need to put it somewhere else. I'm voting no though, but just raising depending on the vision.

Comment thread core/schema/host.go
return inst, err
}

func (s *hostSchema) resourceAsService(

@jedevc jedevc Jul 21, 2025 •

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.

Thoughts on a future resourceAsContainer? That would be used for parsing the CLI args for a remote image. Would also be used to use it as default values for a Container arg, etc, see #8483.

Reason I'm raising, is because in the context of #10737, there's two potential places to load from: the host, or a remote registry. Just wondering what the API would look like here 🤔

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.

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.

Ah, it's at the top 🤦‍♀️ Yeah that!

Just kinda wondering how this would work if a host container store was connected, it should probably be able to look there as well?

@shykes

shykes commented Jul 21, 2025

Copy link
Copy Markdown
Contributor Author

Just to throw another design point into the mix - if we put it behind host it definitely won't be accessible to modules. Do we want it exposed to modules? If so, we probably need to put it somewhere else. I'm voting no though, but just raising depending on the vision.

Good point. No strong opinion about hiding it from modules. I think, given that runtime access is correctly sandboxed, there's no strong requirement to hide this API from modules. It boils down to making sure devs are not confused by the API.

@jedevc

jedevc commented Jul 21, 2025

Copy link
Copy Markdown
Contributor

Forgot to comment this: very nice, I like it 🎉

@shykes

shykes commented Jul 21, 2025

Copy link
Copy Markdown
Contributor Author

Closing in favor of #10770

@shykes shykes closed this Jul 21, 2025
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