-
Notifications
You must be signed in to change notification settings - Fork 1.3k
dockerfile2llb: filter unused paths for named contexts #4161
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,19 +8,22 @@ import ( | |
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "math" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "os" | ||
| "os/exec" | ||
| "path" | ||
| "path/filepath" | ||
| "regexp" | ||
| "runtime" | ||
| "sort" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| v1 "github.com/moby/buildkit/cache/remotecache/v1" | ||
| "golang.org/x/sync/errgroup" | ||
|
|
||
| "github.com/containerd/containerd" | ||
| "github.com/containerd/containerd/content" | ||
|
|
@@ -130,6 +133,7 @@ var allTests = integration.TestFuncs( | |
| testNamedOCILayoutContextExport, | ||
| testNamedInputContext, | ||
| testNamedMultiplatformInputContext, | ||
| testNamedFilteredContext, | ||
| testEmptyDestDir, | ||
| testCopyChownCreateDest, | ||
| testCopyThroughSymlinkContext, | ||
|
|
@@ -6063,6 +6067,114 @@ COPY --from=build /foo /out / | |
| require.Equal(t, "foo is bar-arm64\n", string(dt)) | ||
| } | ||
|
|
||
| func testNamedFilteredContext(t *testing.T, sb integration.Sandbox) { | ||
| ctx := sb.Context() | ||
|
|
||
| c, err := client.New(ctx, sb.Address()) | ||
| require.NoError(t, err) | ||
| defer c.Close() | ||
|
|
||
| fooDir := integration.Tmpdir(t, | ||
| // small file | ||
| fstest.CreateFile("foo", []byte(`foo`), 0600), | ||
| // blank file that's just large | ||
| fstest.CreateFile("bar", make([]byte, 4096*1000), 0600), | ||
| ) | ||
|
|
||
| f := getFrontend(t, sb) | ||
|
|
||
| runTest := func(t *testing.T, dockerfile []byte, target string, min, max int64) { | ||
| t.Run(target, func(t *testing.T) { | ||
| dir := integration.Tmpdir( | ||
| t, | ||
| fstest.CreateFile(dockerui.DefaultDockerfileName, dockerfile, 0600), | ||
| ) | ||
|
|
||
| ch := make(chan *client.SolveStatus) | ||
|
|
||
| eg, ctx := errgroup.WithContext(sb.Context()) | ||
| eg.Go(func() error { | ||
| _, err := f.Solve(ctx, c, client.SolveOpt{ | ||
| FrontendAttrs: map[string]string{ | ||
| "context:foo": "local:foo", | ||
| "target": target, | ||
| }, | ||
| LocalDirs: map[string]string{ | ||
| dockerui.DefaultLocalNameDockerfile: dir, | ||
| dockerui.DefaultLocalNameContext: dir, | ||
| "foo": fooDir, | ||
| }, | ||
| }, ch) | ||
| return err | ||
| }) | ||
|
|
||
| eg.Go(func() error { | ||
| transferred := make(map[string]int64) | ||
| re := regexp.MustCompile(`transferring (.+):`) | ||
| for ss := range ch { | ||
| for _, status := range ss.Statuses { | ||
| m := re.FindStringSubmatch(status.ID) | ||
| if m == nil { | ||
| continue | ||
| } | ||
|
|
||
| ctxName := m[1] | ||
| transferred[ctxName] = status.Current | ||
| } | ||
| } | ||
|
|
||
| if foo := transferred["foo"]; foo < min { | ||
| return errors.Errorf("not enough data was transferred, %d < %d", foo, min) | ||
| } else if foo > max { | ||
| return errors.Errorf("too much data was transferred, %d > %d", foo, max) | ||
| } | ||
| return nil | ||
| }) | ||
|
|
||
| err := eg.Wait() | ||
| require.NoError(t, err) | ||
| }) | ||
| } | ||
|
|
||
| dockerfileBase := []byte(` | ||
| FROM scratch AS copy_from | ||
| COPY --from=foo /foo / | ||
|
|
||
| FROM alpine AS run_mount | ||
| RUN --mount=from=foo,src=/foo,target=/in/foo cp /in/foo /foo | ||
|
|
||
| FROM foo AS image_source | ||
| COPY --from=alpine / / | ||
| RUN cat /foo > /bar | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add a case that also checks the alias case so that the |
||
| FROM scratch AS all | ||
| COPY --link --from=copy_from /foo /foo.b | ||
| COPY --link --from=run_mount /foo /foo.c | ||
| COPY --link --from=image_source /bar /foo.d | ||
| `) | ||
|
|
||
| t.Run("new", func(t *testing.T) { | ||
| runTest(t, dockerfileBase, "run_mount", 1, 1024) | ||
| runTest(t, dockerfileBase, "copy_from", 1, 1024) | ||
| runTest(t, dockerfileBase, "image_source", 4096*1000, math.MaxInt64) | ||
| runTest(t, dockerfileBase, "all", 4096*1000, math.MaxInt64) | ||
| }) | ||
|
|
||
| dockerfileFull := append([]byte(` | ||
| FROM scratch AS foo | ||
| COPY <<EOF /foo | ||
| test | ||
| EOF | ||
| `), dockerfileBase...) | ||
|
|
||
| t.Run("replace", func(t *testing.T) { | ||
| runTest(t, dockerfileFull, "run_mount", 1, 1024) | ||
| runTest(t, dockerfileFull, "copy_from", 1, 1024) | ||
| runTest(t, dockerfileFull, "image_source", 4096*1000, math.MaxInt64) | ||
| runTest(t, dockerfileFull, "all", 4096*1000, math.MaxInt64) | ||
| }) | ||
| } | ||
|
|
||
| func testSourceDateEpochWithoutExporter(t *testing.T, sb integration.Sandbox) { | ||
| workers.CheckFeatureCompat(t, sb, workers.FeatureOCIExporter, workers.FeatureSourceDateEpoch) | ||
| f := getFrontend(t, sb) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any command that changes LLB should need this, not just
RUN. Also, if the stage is part of the target then it needs all the files.