Repository navigation
chore(mod): update sdk field in dagger.json from string to struct - #9454
Conversation
jedevc
left a comment
There was a problem hiding this comment.
Hey, nice! Just left a few small comments, the direction looks right to me.
Happy to defer adding and making the pin field work (and working with updates, etc).
| Source string `json:"source"` | ||
| Pin string `json:"pin"` | ||
| Env map[string]string `json:"env"` |
There was a problem hiding this comment.
To make these types queryable and appear in the schema, you'll need to add field tags, e.g. look at ModuleSource:
Lines 58 to 77 in 539584e
There was a problem hiding this comment.
with map[string]string we get cannot convert map[string]string to a Typed value error. how do you feel about making the env either []string (meaning user will have to type in KEY=VALUE format) OR making it []Env, where Env is a struct with a key/value fields.
There was a problem hiding this comment.
well apparently []Env also fails, so I have to keep it as []string. @jedevc what do you think from UX perspective here?
There was a problem hiding this comment.
Hm, having []Env should work - we already have BuildArg, see:
Line 61 in 12f298a
That should allow you to have it in the API.
However, the ModuleConfig struct should ideally still represent it as a map[string]string (should be fine, since it's serialized as JSON, and I don't think it's exposed in the API directly).
| modCfg.SDK = &modules.SDK{ | ||
| Source: src.WithSDK, | ||
| } |
There was a problem hiding this comment.
WithSDK would need changing as well - the method should be updated to additionally take pin (similar to how moduleSource takes it as well), and maybe even env? Happy to defer that for now, but IMO the WithSDK field should change to be the new SDKConfig type instead of a string.
60754c7 to
0ecd464
Compare
025c6fa to
53c9cb4
Compare
da6edb0 to
9eddde0
Compare
| // inject sdk specific env variables before withExec | ||
| // TODO(rajatjindal): do we want to have a safelist here? | ||
| // e.g. disallow system env variables? |
There was a problem hiding this comment.
Potentially I would filter to anything with a GO prefix? Is there any reason we'd want to inject non-go prefixes?
We could always expand the list later, but I'm struggling to think of a legit reason we'd want anything that's not in that list.
There was a problem hiding this comment.
only usecase I can think of is if other SDK needs some environment variables. but like you said we can add them quickly if needed while removing a broader safelist is difficult.
| } | ||
|
|
||
| type SDKConfig struct { | ||
| Source string `field:"true" name:"source" doc:"Source of the SDK. Either a name of a builtin SDK or a module source ref string pointing to the SDK's implementation."` |
There was a problem hiding this comment.
🤔 One day, I wonder if we would want to split this up into a source and builtin field. But that's kind of out-of-scope for here, just wondering out loud.
jedevc
left a comment
There was a problem hiding this comment.
Left a couple comments - aside from those, I think this is ready to go. LGTM 🎉
9adf62d to
808f6ac
Compare
97381bf to
1252bdd
Compare
Signed-off-by: Rajat Jindal <[email protected]>
1252bdd to
0fb5149
Compare
…gger#9454) Signed-off-by: Rajat Jindal <[email protected]>
|
|
||
| // inject sdk specific env variables before withExec | ||
| // for now allow only Env with prefix GO | ||
| cfg, ok, _ := src.Self.ModuleConfig(ctx) |
There was a problem hiding this comment.
@rajatjindal @jedevc IIUC this env thing will only work for the Go SDK right? did we create an issue somewhere so the other SDKs could potentially implement this as well?
There was a problem hiding this comment.
I addition to this. Now that we have this mechanism, shall we mark the current SYSTEMENV thing as deprecated so we can effectively remove it in future releases?
There was a problem hiding this comment.
we have not created the issue for supporting other env variable as we thought we will allow them on case by case basis. on 2nd thoughts, we should also update all docs to reflect this new format of dagger.json -> sdk field? what do you think @jedevc ?
There was a problem hiding this comment.
Mm, I think that makes sense. Currently we only use it for GODEBUG and GOPROXY. Given we don't document it, I'm happy to remove it.
However - I do actually think that configuring proxy settings are an engine.json level setting, not a module level setting. Proxies + mirrors shouldn't affect the reproducibility of a module right? So configuring them should probably be an infra concern (for whoever hosts the engine) - not a module level decision.
So, I think what this implies is that we should be able to configure these env vars in engine.json as well as in dagger.json. Does that make sense?
| cfg, ok, _ := src.Self.ModuleConfig(ctx) | ||
| if ok && cfg.SDK != nil { | ||
| for k, v := range cfg.SDK.Env { | ||
| if !strings.HasPrefix(k, "GO") { |
There was a problem hiding this comment.
Do we want to add this condition? I think this will be confusing to some users. I don't see why we would like this to be this way. For example, there are some Go related variables that don't start with GO like CGO_ENABLED=1.
There was a problem hiding this comment.
that is a fair point. are you running into a limitation already because of that? The idea was we can extend it on case by case basis to ensure we don't end up allowing something and then having to revert that later (e.g. for security considerations).
There was a problem hiding this comment.
that is a fair point. are you running into a limitation already because of that? The idea was we can extend it on case by case basis to ensure we don't end up allowing something and then having to revert that later (e.g. for security considerations).
oh, I see what you mean.. yeah.. I don't have any particular requirement now. Given the security constraints, it seems ok to me to leave it like this for now 🙏
This (is a WIP) stab at updating the dagger.json's sdk field from a string to a struct.
fixes #9156
I am opening this PR to collect initial feedback while I am trying to figure out how we can extend this to include environment variables in the runtime container. (I am guessing we will need those env variable at
Codegentime instead ofRuntime(to ensure those work for codegen for the private module's dependency, but that is wht I am currently evaluating).other things that we need to cover (possibly different PRs?):