Skip to content

Remove Host API from module SDK codegen. - #6535

Merged
gerhard merged 4 commits into
dagger:mainfrom
sipsma:no-host
Feb 1, 2024
Merged

gerhard merged 4 commits into
dagger:mainfrom
sipsma:no-host

Conversation

@sipsma

@sipsma sipsma commented Jan 31, 2024 •

Copy link
Copy Markdown
Contributor

🔥 Update Instructions for Breaking Changes

Modules that use the Host API to read source files

(using go syntax below, but same idea applies to all SDKs)

Previously, module containers set their working directory to the directory containing the module's source code. You could then read files from that directory with calls like dag.Host().File("./some/file.txt").

Now, module containers are set to an initially empty scratch directory, so those calls will not work anymore.

To use files/directories from the module source code, you can instead:

  1. Directories - dag.CurrentModule().Source().Directory("some/subdir")
  2. Files - dag.CurrentModule().Source().File("some/file.txt")

Additionally, it used to technically be possible to use files/directories from anywhere in the root dir loaded for a module in the case where "root" was configured in dagger.json. This is no longer possible; instead anything you need to use from outside the module's source code directory should be accepted as an argument to a function or the module constructor.

One final use case to mention: if you need to create new files/directories and then load them into the dagger API during module execution, this is still possible.

  1. Directories - dag.CurrentModule().Workdir("./some/dir")
  2. Files - dag.CurrentModule().WorkdirFile("./some/file.txt")

The new dag.CurrentModule() API replaces the need for the Host API and gives more controlled functionality that is specific to modules.

Fixes #6312

More details on the new API in this PR description (specifically CurrentModule API).

TODO:

  • Update release notes with details on breaking change

Comment thread core/schema/coremod.go Resolved
@sipsma sipsma added this to the v0.9.8 milestone Feb 1, 2024
@sipsma

sipsma commented Feb 1, 2024

Copy link
Copy Markdown
Contributor Author

I only ran a subset of tests locally, but didn't run TestModuleDaggerCallArgTypes/service_args which I now see is failing due to the fact that you pass a service created w/ the host API from the CLI to a module, which no longer knows anything about host and thus can't load its ID...

Been thinking through whether there's any reasonable options here that also maintains the current approach, but don't see any; only see options that would hack dagql in unreasonable ways.

I am going to give a shot at a different approach that still allows the host schema to be loaded for module clients on the graphql level, but just not presented to SDKs for codegen. Should create same end effect while still allowing use cases like this to work.

@sipsma sipsma changed the title Remove Host API from schemas presented to modules. Remove Host API from module SDK codegen. Feb 1, 2024
@sipsma
sipsma requested a review from vito February 1, 2024 06:11
@sipsma

sipsma commented Feb 1, 2024

Copy link
Copy Markdown
Contributor Author

The new approach described in previous comment works much better and thankfully isn't quite as kludgy as I originally imagined: 685e6e5

I could actually see it being useful in general outside this use case; e.g. I considered doing the same thing to block the Query.blob API from all SDK clients since that's very much internal only (backed out because I really don't want to expand the scope of this too much last minute).

@jedevc

jedevc commented Feb 1, 2024

Copy link
Copy Markdown
Contributor

If we're removing the host api entirely, it's now not possible to tunnel/reverse-tunnel a service from the module container?

I quite liked this feature, and I'm not sure if we should remove it - though maybe it does genuinely belong somewhere else (e.g. under Local as in #6408).

gives more controlled functionality that is specific to modules.

We do need to leave in the underlying graphql schema for host because
it's needed for internal calls (e.g. a host service passed to a module
function). So this just results in the Host types being scrubbed from
the introspection JSON that is provided to module SDKs for codegen.

Signed-off-by: Erik Sipsma <[email protected]>
This library seems to be very opinionated about the exact format of the
introspection json, so need to add a few `omitempty`s and add a
(currently always empty) `interfaces` to `Type`.

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

jedevc commented Feb 1, 2024

Copy link
Copy Markdown
Contributor

(rebased to fix merge conflicts against main)

@gerhard gerhard 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! OK to merge?

@jedevc

jedevc commented Feb 1, 2024

Copy link
Copy Markdown
Contributor

Removed the changelog entry, following the same logic as in #6546

@jedevc jedevc 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.

Happy to take this now, since it'll be good to remove the access to the host files for this release.

But also, I want to make sure that #6535 (comment) doesn't get lost, and that we have a way to restore this in the future.

(ahhh, I've realized we can do tunnels using the chainable up to do this)

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.

Modules: dag.Host() name is extremely confusing

4 participants