Skip to content

chore(mod): update sdk field in dagger.json from string to struct - #9454

Merged
jedevc merged 1 commit into
dagger:mainfrom
rajatjindal:sdk-struct-jan27
Feb 7, 2025
Merged

jedevc merged 1 commit into
dagger:mainfrom
rajatjindal:sdk-struct-jan27

Conversation

@rajatjindal

@rajatjindal rajatjindal commented Jan 27, 2025 •

Copy link
Copy Markdown
Contributor

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 Codegen time instead of Runtime (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?):

  • Pin the sdk dependency
  • Add ability to update sdk
  • Verify we can update to a different SDK?

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

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).

Comment thread core/modules/config.go Resolved
Comment thread core/schema/module.go Resolved
Comment thread core/module.go Outdated
Comment on lines +19 to +21
Source string `json:"source"`
Pin string `json:"pin"`
Env map[string]string `json:"env"`

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.

To make these types queryable and appear in the schema, you'll need to add field tags, e.g. look at ModuleSource:

type ModuleSource struct {
Query *Query
Kind ModuleSourceKind `field:"true" name:"kind" doc:"The kind of source (e.g. local, git, etc.)"`
AsLocalSource dagql.Nullable[*LocalModuleSource] `field:"true" doc:"If the source is of kind local, the local source representation of it."`
AsGitSource dagql.Nullable[*GitModuleSource] `field:"true" doc:"If the source is a of kind git, the git source representation of it."`
// Settings that can be used to initialize or override the source's configuration
WithName string
WithDependencies []dagql.Instance[*ModuleDependency]
WithoutDependencies []string
WithUpdateDependencies []string
WithUpdateAllDependencies bool
WithSDK string
WithInitConfig *ModuleInitConfig
WithSourceSubpath string
WithViews []*ModuleSourceView
}

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.

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.

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.

well apparently []Env also fails, so I have to keep it as []string. @jedevc what do you think from UX perspective here?

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.

Hm, having []Env should work - we already have BuildArg, see:

dagql.MustInputSpec(core.BuildArg{}).Install(s.srv)

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).

Comment on lines +1381 to +1385
modCfg.SDK = &modules.SDK{
Source: src.WithSDK,
}

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.

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.

Comment thread core/schema/module.go Resolved
Comment thread core/schema/sdk.go Outdated
Comment on lines +634 to +636
// inject sdk specific env variables before withExec
// TODO(rajatjindal): do we want to have a safelist here?
// e.g. disallow system env variables?

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.

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.

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.

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.

Comment thread core/module.go Resolved
Comment thread core/module.go
}

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."`

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.

🤔 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.

Comment thread cmd/dagger/config.go Resolved

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

Left a couple comments - aside from those, I think this is ready to go. LGTM 🎉

Comment thread core/modulesource.go Resolved
@rajatjindal
rajatjindal force-pushed the sdk-struct-jan27 branch 4 times, most recently from 9adf62d to 808f6ac Compare February 6, 2025 07:17
Comment thread core/modules/config.go Resolved
@rajatjindal
rajatjindal force-pushed the sdk-struct-jan27 branch 3 times, most recently from 97381bf to 1252bdd Compare February 6, 2025 13:17
Comment thread core/schema/sdk.go Resolved
@rajatjindal
rajatjindal marked this pull request as ready for review February 6, 2025 16:20
@rajatjindal
rajatjindal requested review from a team as code owners February 6, 2025 16:20
@jedevc
jedevc merged commit 63132fd into dagger:main Feb 7, 2025
vikram-dagger pushed a commit to vikram-dagger/dagger that referenced this pull request Feb 7, 2025
Comment thread core/schema/sdk.go

// inject sdk specific env variables before withExec
// for now allow only Env with prefix GO
cfg, ok, _ := src.Self.ModuleConfig(ctx)

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.

@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?

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.

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?

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.

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 ?

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.

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?

Comment thread core/schema/sdk.go
cfg, ok, _ := src.Self.ModuleConfig(ctx)
if ok && cfg.SDK != nil {
for k, v := range cfg.SDK.Env {
if !strings.HasPrefix(k, "GO") {

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.

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.

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.

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).

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.

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 🙏

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.

Split this to #9558.

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.

Make sdk field in ModuleConfig a ModuleConfigDependency

3 participants