Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bake: infer git auth token from remote files to build request #2905

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

crazy-max
Copy link
Member

When BUILDX_BAKE_GIT_AUTH_* env is set to fetch a remote bake definition, we should infer this git auth token to build request if a Git context is detected.

@crazy-max crazy-max requested a review from tonistiigi January 10, 2025 09:11
@crazy-max crazy-max added this to the v0.20.0 milestone Jan 10, 2025
@crazy-max crazy-max marked this pull request as ready for review January 10, 2025 09:13
Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be only if the context is git based I think. A remote bake definition may not always use the same remote URL as a context.

@crazy-max
Copy link
Member Author

This should be only if the context is git based I think. A remote bake definition may not always use the same remote URL as a context.

I see but that could be unreliable if I use a remote bake def that has a target with subdir context like:

target "default" {
  context = "./subdir"
}

But I guess I can just check context does not start with cwd://

@tonistiigi
Copy link
Member

bo would probably already have the context set correctly. If it is a subdir, then it would be a subdir of the git context in this case.

@crazy-max
Copy link
Member Author

bo would probably already have the context set correctly. If it is a subdir, then it would be a subdir of the git context in this case.

Yes indeed, let me check this

@crazy-max crazy-max force-pushed the bake-infer-auth-token branch from 1d59cbc to 119af60 Compare January 10, 2025 17:00
@crazy-max crazy-max requested a review from tonistiigi January 10, 2025 17:00
@crazy-max
Copy link
Member Author

@tonistiigi Should be good now

bake/bake.go Outdated
@@ -1338,7 +1338,23 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
}
bo.Platforms = platforms

bo.SecretSpecs = t.Secrets.ToPB()
secrets := t.Secrets
if build.IsRemoteURL(bi.ContextPath) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. I think if you have a subpath in bake and command invoked directly then the contextpath in here is a subdir but the contextstate has been replaced with something like llb.Git().Copy("subdir")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you right it would not work for this case

@crazy-max crazy-max force-pushed the bake-infer-auth-token branch from 119af60 to 45fc5ed Compare January 14, 2025 14:56
@crazy-max crazy-max requested a review from tonistiigi January 14, 2025 16:11
if build.IsRemoteURL(t.ContextPath) {
return true
}
if inp != nil && build.IsRemoteURL(inp.URL) && !strings.HasPrefix(t.ContextPath, "cwd://") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't inp.URL always URL if it is set?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes if a remote bake def is set but if context is set to git context it is not (first cond in isRemoteContext):

docker buildx bake --set *.context=https://github.com/docker/buildx.git --print
{
  "group": {
    "default": {
      "targets": [
        "binaries"
      ]
    }
  },
  "target": {
    "binaries": {
      "context": "https://github.com/docker/buildx.git",
      "dockerfile": "Dockerfile",
      "args": {
        "BUILDKIT_CONTEXT_KEEP_GIT_DIR": "1"
      },
      "target": "binaries",
      "platforms": [
        "local"
      ],
      "output": [
        {
          "dest": "./bin/build",
          "type": "local"
        }
      ]
    }
  }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that the build.IsRemoteURL(t.ContextPath) {, how does that affect inp.URL?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that the build.IsRemoteURL(t.ContextPath) {,

Yes it is but inp.URL is only set when remote bake def arg is set:

rfiles, inp, err = bake.ReadRemoteFiles(ctx, nodes, url, rnames, pw)

It doesn't take into account git urls in context within bake def or override.

@tonistiigi tonistiigi merged commit 630066b into docker:master Jan 14, 2025
127 checks passed
@crazy-max crazy-max deleted the bake-infer-auth-token branch January 14, 2025 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants