Skip to content

Commit

Permalink
Merge pull request #5407 from tonistiigi/llb-http-user-agent
Browse files Browse the repository at this point in the history
llb: use buildkit user-agent for HTTP source
  • Loading branch information
crazy-max authored Oct 8, 2024
2 parents 01c1436 + 9f43ed7 commit 0cb9ad6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions frontend/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2757,6 +2757,11 @@ ADD %s /dest/
require.NoError(t, err)
require.Equal(t, []byte("content1"), dt)

// run again to test HEAD request
cmd = sb.Cmd(args)
err = cmd.Run()
require.NoError(t, err)

// test the default properties
dockerfile = []byte(fmt.Sprintf(`
FROM scratch
Expand Down Expand Up @@ -2785,6 +2790,13 @@ ADD %s /dest/
fi, err := os.Stat(destFile)
require.NoError(t, err)
require.Equal(t, modTime.Format(http.TimeFormat), fi.ModTime().Format(http.TimeFormat))

stats := server.Stats("/foo")
require.Len(t, stats.Requests, 2)
require.Equal(t, "GET", stats.Requests[0].Method)
require.Contains(t, stats.Requests[0].Header.Get("User-Agent"), "buildkit/v")
require.Equal(t, "HEAD", stats.Requests[1].Method)
require.Contains(t, stats.Requests[1].Header.Get("User-Agent"), "buildkit/v")
}

func testDockerfileAddArchive(t *testing.T, sb integration.Sandbox) {
Expand Down
2 changes: 2 additions & 0 deletions source/http/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
srctypes "github.com/moby/buildkit/source/types"
"github.com/moby/buildkit/util/bklog"
"github.com/moby/buildkit/util/tracing"
"github.com/moby/buildkit/version"
digest "github.com/opencontainers/go-digest"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -181,6 +182,7 @@ func (hs *httpSourceHandler) CacheKey(ctx context.Context, g session.Group, inde
return "", "", nil, false, err
}
req = req.WithContext(ctx)
req.Header.Add("User-Agent", version.UserAgent())
m := map[string]cacheRefMetadata{}

// If we request a single ETag in 'If-None-Match', some servers omit the
Expand Down

0 comments on commit 0cb9ad6

Please sign in to comment.