Skip to content

integration: basic s3 cache test#3398

Merged
crazy-max merged 4 commits intomoby:masterfrom
crazy-max:test-s3-cache
Jan 30, 2023
Merged

integration: basic s3 cache test#3398
crazy-max merged 4 commits intomoby:masterfrom
crazy-max:test-s3-cache

Conversation

@crazy-max
Copy link
Copy Markdown
Member

@crazy-max crazy-max commented Dec 13, 2022

Adds basic integration test for s3 cache so we can get rid of the one from hack folder. Also pin busybox in current azblob_test related to #3469.

cc @bpaquet

@crazy-max crazy-max changed the title cache: native s3 cache integration tests integration: basic s3 cache test Jan 7, 2023
@crazy-max crazy-max force-pushed the test-s3-cache branch 2 times, most recently from e4b5c2c to 3782abf Compare January 7, 2023 15:13
@crazy-max crazy-max marked this pull request as ready for review January 7, 2023 16:53
@crazy-max
Copy link
Copy Markdown
Member Author

Also pin busybox in current azblob_test related to #3469.

Has been fixed in #3475, removing that commit.

@crazy-max crazy-max force-pushed the test-s3-cache branch 2 times, most recently from 53b4e00 to 0aaf62b Compare January 8, 2023 11:35
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
testBasicCacheImportExport(t, sb, []CacheOptionsEntry{im}, []CacheOptionsEntry{ex})
}

func testBasicS3CacheImportExport(t *testing.T, sb integration.Sandbox) {
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.

This is only one case. @crazy-max do you want help for others?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think the basic one is fine for this use case:

buildkit/client/client_test.go

Lines 4556 to 4616 in 05c4d57

func testBasicCacheImportExport(t *testing.T, sb integration.Sandbox, cacheOptionsEntryImport, cacheOptionsEntryExport []CacheOptionsEntry) {
requiresLinux(t)
c, err := New(sb.Context(), sb.Address())
require.NoError(t, err)
defer c.Close()
busybox := llb.Image("busybox:latest")
st := llb.Scratch()
run := func(cmd string) {
st = busybox.Run(llb.Shlex(cmd), llb.Dir("/wd")).AddMount("/wd", st)
}
run(`sh -c "echo -n foobar > const"`)
run(`sh -c "cat /dev/urandom | head -c 100 | sha256sum > unique"`)
def, err := st.Marshal(sb.Context())
require.NoError(t, err)
destDir := t.TempDir()
_, err = c.Solve(sb.Context(), def, SolveOpt{
Exports: []ExportEntry{
{
Type: ExporterLocal,
OutputDir: destDir,
},
},
CacheExports: cacheOptionsEntryExport,
}, nil)
require.NoError(t, err)
dt, err := os.ReadFile(filepath.Join(destDir, "const"))
require.NoError(t, err)
require.Equal(t, string(dt), "foobar")
dt, err = os.ReadFile(filepath.Join(destDir, "unique"))
require.NoError(t, err)
ensurePruneAll(t, c, sb)
destDir = t.TempDir()
_, err = c.Solve(sb.Context(), def, SolveOpt{
Exports: []ExportEntry{
{
Type: ExporterLocal,
OutputDir: destDir,
}},
CacheImports: cacheOptionsEntryImport,
}, nil)
require.NoError(t, err)
dt2, err := os.ReadFile(filepath.Join(destDir, "const"))
require.NoError(t, err)
require.Equal(t, string(dt2), "foobar")
dt2, err = os.ReadFile(filepath.Join(destDir, "unique"))
require.NoError(t, err)
require.Equal(t, string(dt), string(dt2))
}

If you think about ones specific to s3, we can do that in follow-ups.

@crazy-max
Copy link
Copy Markdown
Member Author

@bpaquet As discussed with @tonistiigi I will open a follow-up to check the bucket content like you've done. If you want to do it, let me know.

@crazy-max crazy-max merged commit 9b28f40 into moby:master Jan 30, 2023
@crazy-max crazy-max deleted the test-s3-cache branch January 30, 2023 19:39
@guillenotfound
Copy link
Copy Markdown

Is this fixing importing cache from several targets (multi stage builds)? Currently that's not working very well and I cannot find much documentation to ping-pong what's going on.

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.

4 participants