Skip to content

[WIP] Change Host to more clear name - #6408

Closed
sipsma wants to merge 1 commit into
dagger:mainfrom
sipsma:host-to-local
Closed

sipsma wants to merge 1 commit into
dagger:mainfrom
sipsma:host-to-local

Conversation

@sipsma

@sipsma sipsma commented Jan 12, 2024 •

Copy link
Copy Markdown
Contributor

Fixes #6312

Opening this purely to have a discussion right now, the changes amount to find+replace on the host name right now, but not even entirely yet (need to update tests, etc.)

Background

The name Host has become extremely confusing in the context of modules. So far, it seems that more often than not users very reasonably assume that in a module when they use dag.Host they are interacting with the original "host" where the module was invoked from.

However, that's not the case. They are actually interacting with the local execution environment of the module, which is the container the module is executing in.

We do want to retain this ability; being able to interact with the local execution environment of a module supports use cases like:

  1. Writing a local file and then importing it to dagger
    • e.g. maybe your module is using a library that insists on writing a file to the local filesystem, but you then want to use it in other dagger api calls
  2. Starting a service from within a module function and then interacting with it directly from your module code (in which case you'd want to setup a tunnel)

Whether we want to additionally support a module reading files/env vars/etc. from the caller's environment (i.e. read a file from the filesystem local to the actual CLI call) is still an open question (see discussion here), but for now we are going to continue not supporting it and just leave it open as a possibility.

Possible new names

Local (current state of this PR)

Examples of usage:

dag.Local().File("./some/file")

dag.Local().Directory("./some/dir")

dag.Local().UnixSocket("/some/sock")

dag.Local().Tunnel(someService)

dag.Local().Service([]dagger.PortForward{
    {Frontend: 80, Backend: port},
})

dag.Local().SetSecretFile("topsecret", "/some/secret/file")

Users will still need to have some understanding that modules execute in a container, not directly on the CLI's host, in order to fully grok this name and intuitively guess its behavior. However, once they know that, I think Local makes much more sense than Host.

  • The problem today is that even if you know that modules execute in a container, it's still entirely reasonable+intuitive to assume that dag.Host() is going back to the "host" of the CLI caller. It feels very unnatural to call a containerized execution environment "host".
  • I think that is largely alleviated with Local, in which case it feels much more natural to think of Local as referring to the local execution environment (which in the case of modules, is their container)

I also like that Local is still relatively succinct (i.e. not something even clearer but overly verbose like CurrentExecutionEnvironment).

I was concerned that local might be a reserved word in too many languages and thus require too much special casing everywhere, but to my surprise it doesn't appear to be a reserved word in our current SDKs.

  • This is from a very hasty search though, worth a double check; please chime in if I'm missing something.

Other possible names

Some others that came to mind but I didn't go with for now are:

  • ExecutionEnvironment
    • While potentially more obvious than Local, felt too verbose to be worth it
  • Caller
    • Felt like it would have the same problems of Host in that it would be reasonable to assume that Caller is referring to the CLI caller of the module (as opposed to the module itself)
  • CurrentModule
    • See "C) Add new APIs to CurrentModule, remove Host from module clients" section below

Renaming approaches

There's a few different ways we can go about renaming the API.

Expand

A) Just rename Host (current state of this PR)

The most straightforward is to just rename the Host type to something that is more clear.

This is what this PR is currently doing, specifically renaming Host to Local (see "Possible new names" section above for discussion on this choice and alternatives).

Pros:

  1. Keeps module and non-module clients aligned

Cons:

  1. Big breaking change for non-module clients (everyone is going to be doing a lot of find+replace)
    • This could be somewhat alleviated by deprecating Host but leaving it in for a few more releases and making lots of noise about the need to update to use Local

B) Rename Host only for module clients

Another possibility would be to keep the name Host for clients that are not executing in a module, but use a different name like Local only for clients executing in modules.

In terms of implementing this, it would be somewhat annoying but could be done entirely server-side and not require every SDK to update itself to handle this (since the server tells SDKs what schema to run codegen for). So the annoyance would be entirely internal and not so bad as to rule this out.

Pros:

  1. Doesn't break existing non-module SDK users
  2. For users transitioning from non-module SDK code to module code, makes the fact that their code should no longer assume it can read anything from the original caller's host more obvious (since they need to explicitly update the api in their code)

Cons:

  1. Diverges non-module client sdks from module client sdks, may require unnecessary updates in some cases
    • To explain, there actually are plenty of cases where dag.Host() would incidentally have the same behavior when run outside a module and inside a module.
    • Specifically, if the non-module code was reading local files that now become files loaded into the module container (i.e. the directory under the module's dagger.json), then they technically wouldn't have had to make any updates to their code.

C) Add new APIs to CurrentModule, remove Host from module clients

Another variant would be to:

  1. Remove Host from being callable from from module sdks (but leave non-module SDKs alone)
  2. Add methods to the existing CurrentModule API that allow equivalent functionality (reading files, tunneling, etc.)

CurrentModule already exists and returns the Module object that the current caller is executing in (error otherwise).

Though I haven't worked out exactly how, in theory we could probably adjust that API such that it has the fields current present under Host are exposed under CurrentModule, so module code would make calls like:

dag.CurrentModule().File("./some/file")

dag.CurrentModule().Tunnel(someService)

// etc.

Pros (same as option B):

  1. Doesn't break existing non-module SDK users
  2. For users transitioning from non-module SDK code to module code, makes the fact that their code should no longer assume it can read anything from the original caller's host more obvious (since they need to explicitly update the api in their code)

Cons:

  1. (same as option B) Diverges non-module client sdks from module client sdks, may require unnecessary updates in some cases
  2. Not entirely clear how to adjust the API in such a way that CurrentModule still returns a Module type but also doesn't create a bunch of cases where non-module code tries to call i.e. dag.Directory("./whatever").AsModule().File("./some/file") and we either error out or have some sort of very confusing behavior
    • Basically, not sure yet if there's a way of doing this that results in a comprehensible Module api

My opinion

For the sake of having a concrete starting place amongst the many possibilities, my current preference is to:

  1. Add Local api for all clients, both module and non-module. Same fields as Host, just a new name.
  2. Remove Host from module sdk codegen entirely (since backwards incompatible changes there are less painful right now)
  3. Keep Host in for non-module client sdks at first but marked as deprecated. Make noise about users needing to update to Local. Remove Host in a few releases.

That feels like a good balance of not creating too much short-term pain for existing users, creating a more clear name for module users and not being overly burdensome in terms of the implementation.

@sipsma
sipsma requested a review from helderco January 12, 2024 02:57
@sagikazarmark

Copy link
Copy Markdown
Contributor

Yet another occasion where a dagger version constraint in dagger.json would be extremely useful to avoid module breaks on higher/lower dagger versions.

@sipsma

sipsma commented Jan 12, 2024

Copy link
Copy Markdown
Contributor Author

Yet another occasion where a dagger version constraint in dagger.json would be extremely useful to avoid module breaks on higher/lower dagger versions.

We are going to have tracking of the version of dagger a module was initialized from in the near future. We won't immediately also have the ability to serve certain schemas to different modules based on that version, but we should be tee'd up to support that too in the medium term. In the very long term, we want all of the core functionality to be a versioned module itself, but that will take a while to come to fruition.

So, I agree 😄 But in the meantime at this exact moment we still need to contend w/ issues like this.

@sagikazarmark

Copy link
Copy Markdown
Contributor

I actually had something very simple in mind:

{
    // ...
    "daggerVersion": "0.9.*|^0.9.0|~0.9.0|^0.9.0,!0.9.3"
}

If the running dagger version doesn't match that constraint, just refuse to run/evaluate the module.

While I understand that modules are experimental, I assume there will be tons of other breaking changes before it becomes stable, and this would make managing those breaks easier.

If the schema is going to change anyway, I see no harm in adding a field like this for the short term and then removing it once it doesn't make sense anymore.

It would also make it easier for modules to express that they require a certain minimum version (for example: because they use the new constructor feature)

I made my case, defense rests. 😄

@shykes

shykes commented Jan 12, 2024

Copy link
Copy Markdown
Contributor

Hello! Just back from vacation, will add this to my UX review list (let me know if there are other time-sensitive ones, I know there’s a RC coming up).

Curious if you considered Client ?

@marcosnils

marcosnils commented Jan 12, 2024 •

Copy link
Copy Markdown
Contributor

Whether we want to additionally support a module reading files/env vars/etc. from the caller's environment (i.e. read a file from the filesystem local to the actual CLI call) is still an open question (see discussion here), but for now we are going to continue not supporting it and just leave it open as a possibility.

while reading this comment it crossed my mind the capability based security model that the kernel and WASM has (https://github.com/bytecodealliance/wasmtime/blob/main/docs/WASI-overview.md)

re: Local, SGTM! I coincidentally thought about the same term only by reading the title of this PR without seeing your proposal.

@helderco

Copy link
Copy Markdown
Contributor

Curious if you considered Client ?

We already make query turn into dagger.Client. So Client.host (query { host }) would become Client.client.

@helderco

Copy link
Copy Markdown
Contributor

I don't think there's a term that works for both the actual host and a container, for those that don't know there's a difference. We need to explain this when teaching modules much like docker users on a Mac need to understand that the host is the Linux VM running the engine, not macOS.

So the best we can do (as far as choosing a word here, and other than simply documenting) is steer away from stronger associations to each side, like Host.

Local leans a bit more towards suggesting "host" for me but only slightly and I don't have a better suggestion. So SGTM 👍

+1 on the deprecation path too since it's high impact.

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

gerhard commented Jan 31, 2024

Copy link
Copy Markdown
Contributor

I really like the new name! Local is so much clearer than Host. I am wondering if Localhost would be taking it too far.

I'm all in favour of this and think that, if possible, we should do it before 0.10. WDYT?

@sipsma

sipsma commented Jan 31, 2024

Copy link
Copy Markdown
Contributor Author

Sorry I meant to close this one out last night as I opened up #6535 as a replacement. Basically, module's now have an expanded dag.CurrentModule() api from #6386 and we thus can just block Host from being usable from modules entirely rather than needing to rename anything per-se.

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

6 participants