Skip to content

feat(engine): add support for fetching git config - #9323

Merged
jedevc merged 6 commits into
dagger:mainfrom
rajatjindal:fix-private-depss
Mar 18, 2025
Merged

jedevc merged 6 commits into
dagger:mainfrom
rajatjindal:fix-private-depss

Conversation

@rajatjindal

@rajatjindal rajatjindal commented Jan 6, 2025 •

Copy link
Copy Markdown
Contributor

Fixes #8766, #9178 by implementing #7787.

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@rajatjindal

Copy link
Copy Markdown
Contributor Author

I am working through changing the SDK field from being a string to a struct to support the 2nd part of this PR (to pass along goprivate env variable)

@rajatjindal

rajatjindal commented Jan 31, 2025 •

Copy link
Copy Markdown
Contributor Author

I have this working end to end. and currently cleaning up the changes (in a different branch, will pull them here) and working through test failures. The complete fix for this also needs #9454 which adds the ability to set environment variables in codegen/runtime container from dagger.json.

the idea is that with this PR, we will pull the selective gitconfig keys from user's configuration and add them to the codegen/runtime container automatically. we are doing selective gitconfig because we don't want to pull all the git-config key/values from user system as they may or may not work on the engine (e.g. a config pointing to a file on the local file system for gitignore). Also we don't want to be in a position where we allowed everything, ran into a problem with some keys but can't revert back because of backward compatibility problems.

@rajatjindal
rajatjindal force-pushed the fix-private-depss branch 11 times, most recently from 2d7f145 to 80a0a2c Compare February 11, 2025 07:42
Comment thread core/schema/sdk.go Resolved
Comment thread engine/session/git.go Resolved
@rajatjindal
rajatjindal force-pushed the fix-private-depss branch 5 times, most recently from e9a06b2 to ff9e91b Compare February 13, 2025 12:22
@rajatjindal
rajatjindal force-pushed the fix-private-depss branch 6 times, most recently from f3cd6f6 to 82ea4ed Compare February 25, 2025 01:31
@rajatjindal
rajatjindal force-pushed the fix-private-depss branch 5 times, most recently from b922049 to 49386ab Compare March 14, 2025 11:24
@rajatjindal

Copy link
Copy Markdown
Contributor Author

Hi @jedevc, this PR is ready for final set of review/merge. When you get chance, could you please look into this. thank you.

Comment thread core/modulesource.go Resolved
Comment thread core/schema/sdk.go
return nil, err
}

for _, entry := range gitconfig {

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.

Is there a way to avoid this being in lots of little WithExecs? I think I mentioned this before in #9323 (comment).

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.

I did tried it. It seems like not... (unless we take complete git config as is). once we fetch config using git config -l, we cannot translate it back to a working gitconfig file unless we call git config on those retrieved values again.

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.

🤔 is it not just as simple as appending to the gitconfig file manually? Or is that just too fundamentally complex?

The other option would be to combine all of these by passing them to a sh and joining them with &&.

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.

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.

yep, this seems useful to me.

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.

i tried this one. it seems it does not support merging git configs (e.g. system level vs user level vs repo level).

although when running git config -l through session attachable, it does not consider repo level config either.

another thing to notice is that we have a safe list of git config keys allowed right now, which is just one, so having withExec is not going to be a problem unless we allow a large number of keys (or remove that check) from 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.

Ah, yes, I'd forgotten we only allow the url transformation.

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

Couple comments, otherwise LGTM 🎉

@rajatjindal
rajatjindal force-pushed the fix-private-depss branch 3 times, most recently from 9261f73 to 06627e2 Compare March 17, 2025 16:48
Signed-off-by: Rajat Jindal <[email protected]>
@jedevc

jedevc commented Mar 18, 2025

Copy link
Copy Markdown
Contributor

Okay, @rajatjindal merging this now. Ideally we'd also have some docs for this as well - not sure exactly where these should go, maybe into https://docs.dagger.io/api/remote-modules?

It's related to the concept of remote modules, but it's about private deps. Perhaps @grouville and @vikram-dagger can advise here.

@jedevc jedevc linked an issue Mar 18, 2025 that may be closed by this pull request
@jedevc
jedevc merged commit 84ee119 into dagger:main Mar 18, 2025
@jedevc jedevc added this to the v0.17.0 milestone Mar 18, 2025
@rajatjindal

Copy link
Copy Markdown
Contributor Author

This PR cover a few changes:

  1. Add support to fetch gitconfig from user's host system.
  2. Add support for SDK Config in the engine.
  3. Add support for configuring GOPRIVATE env variable (by leveraging the new ^^ sdk config feature) for Go SDK

Add support to fetch gitconfig from user's host system.

  1. Currently we only fetch use this url instead of this type gitconfig.
  2. We decided not to fetch everything from user's host gitconfig as it can have user's system specific config which can break the engine/module and trigger unexpected behavior and inconsistencies.
  3. We can easily add more gitconfig keys if a user requests in future.
  4. We need git to be installed on the host system for this to work, but it is optional. We ignore if git is not installed.

Add support for SDK Config in the engine.

  1. We added a new field sdk.config in dagger.json.
  2. This is an object (map[string]interface{})
  3. moduleSDK can define a WithConfig function. If the function exists, we verify the arguments against the keys specified in sdk.config object.
  4. We error out if there is a key in sdk.config, which is not supported by SDK.
  5. We use default value (as defined in WithConfig function) by doing introspection on it IF no override is provided in sdk.config object in dagger.json
  6. The support for this is already added in Go SDK (currently only has one config goprivate, which sets the GOPRIVATE env variable in the codegen container.
  7. I have some changes in a branch for typescript SDK, but it needs more changes. I will talk a bit more about it in one of the next section.

Add support for private dependencies in golang sdk

  1. We leverage the above two features to support private deps in golang based modules.
  2. The user can now set sdk.config.goprivate in dagger.json, which gets translated to GOPRIVATE env variable in the codegen container.

Add support for custom config in typescript sdk

  1. This is a WIP right now as it involves quite a bit of refactoring of typescript SDK to ensure the sdk.config could be used in the SDK.
  2. Some of the changes involve the configs that we pass using package.json properties today. e.g. runtime etc.
  3. For this to work we need to restructure the sdk so that
  4. sdk provides a base image (currently this requires some config from package.json)
  5. we add our customizations on top of that base image (e.g. SSH Auth Sock and configs from sdk.config
  6. The sdk then runs codegen on that container and use that as runtime.
  7. I might be oversimplifying the steps here, but that is basically it.
  8. I have a WIP branch that I will rebase and cleanup and open PR for review.

kpenfound pushed a commit to kpenfound/dagger that referenced this pull request Mar 21, 2025
* chore(engine): rename GitCredential attachable to Git

Signed-off-by: Rajat Jindal <[email protected]>

* feat(engine): support fetching gitconfig from host system

Signed-off-by: Rajat Jindal <[email protected]>

* feat(sdk): add support for sdk specific config

Signed-off-by: Rajat Jindal <[email protected]>

* ensure gitconfig, and ssh_auth_sock works

Signed-off-by: Rajat Jindal <[email protected]>

* address review comments

Signed-off-by: Rajat Jindal <[email protected]>

* chore: remove outdated module_test.go TODO

Signed-off-by: Justin Chadwell <[email protected]>

---------

Signed-off-by: Rajat Jindal <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Co-authored-by: Justin Chadwell <[email protected]>
Signed-off-by: kpenfound <[email protected]>
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.

✨ Support private go dependencies in module development engine: support for user-specified Git URL rewrite rules

2 participants