Skip to content

Commit 9b28f40

Browse files
authored
Merge pull request moby#3398 from crazy-max/test-s3-cache
integration: basic s3 cache test
2 parents e2efe2e + 05c4d57 commit 9b28f40

File tree

13 files changed

+198
-183
lines changed

13 files changed

+198
-183
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -184,29 +184,6 @@ jobs:
184184
SKIP_INTEGRATION_TESTS: ${{ matrix.skip-integration-tests }}
185185
CACHE_FROM: type=gha,scope=${{ env.CACHE_GHA_SCOPE_IT }} type=gha,scope=${{ env.CACHE_GHA_SCOPE_BINARIES }}
186186

187-
test-s3:
188-
runs-on: ubuntu-20.04
189-
needs:
190-
- base
191-
steps:
192-
-
193-
name: Checkout
194-
uses: actions/checkout@v3
195-
-
196-
name: Expose GitHub Runtime
197-
uses: crazy-max/ghaction-github-runtime@v2
198-
-
199-
name: Set up Docker Buildx
200-
uses: docker/setup-buildx-action@v2
201-
with:
202-
version: ${{ env.BUILDX_VERSION }}
203-
driver-opts: image=${{ env.REPO_SLUG_ORIGIN }}
204-
buildkitd-flags: --debug
205-
-
206-
name: Test
207-
run: |
208-
hack/s3_test/run_test.sh
209-
210187
test-azblob:
211188
runs-on: ubuntu-20.04
212189
needs:

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ ARG STARGZ_SNAPSHOTTER_VERSION=v0.13.0
1111
ARG NERDCTL_VERSION=v1.0.0
1212
ARG DNSNAME_VERSION=v1.3.1
1313
ARG NYDUS_VERSION=v2.1.0
14+
ARG MINIO_VERSION=RELEASE.2022-05-03T20-36-08Z
15+
ARG MINIO_MC_VERSION=RELEASE.2022-05-04T06-07-55Z
1416

1517
ARG ALPINE_VERSION=3.17
1618

19+
# minio for s3 integration tests
20+
FROM minio/minio:${MINIO_VERSION} AS minio
21+
FROM minio/mc:${MINIO_MC_VERSION} AS minio-mc
22+
1723
# alpine base for buildkit image
1824
# TODO: remove this when alpine image supports riscv64
1925
FROM alpine:${ALPINE_VERSION} AS alpine-amd64
@@ -240,6 +246,8 @@ ENTRYPOINT ["/docker-entrypoint.sh"]
240246
ENV BUILDKIT_INTEGRATION_CONTAINERD_EXTRA="containerd-1.6=/opt/containerd-alt-16/bin"
241247
ENV BUILDKIT_INTEGRATION_SNAPSHOTTER=stargz
242248
ENV CGO_ENABLED=0
249+
COPY --link --from=minio /opt/bin/minio /usr/bin/
250+
COPY --link --from=minio-mc /usr/bin/mc /usr/bin/
243251
COPY --link --from=nydus /out/nydus-static/* /usr/bin/
244252
COPY --link --from=stargz-snapshotter /out/* /usr/bin/
245253
COPY --link --from=rootlesskit /rootlesskit /usr/bin/

client/client_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func TestIntegration(t *testing.T) {
111111
testReadonlyRootFS,
112112
testBasicRegistryCacheImportExport,
113113
testBasicLocalCacheImportExport,
114+
testBasicS3CacheImportExport,
114115
testCachedMounts,
115116
testCopyFromEmptyImage,
116117
testProxyEnv,
@@ -4672,6 +4673,44 @@ func testBasicLocalCacheImportExport(t *testing.T, sb integration.Sandbox) {
46724673
testBasicCacheImportExport(t, sb, []CacheOptionsEntry{im}, []CacheOptionsEntry{ex})
46734674
}
46744675

4676+
func testBasicS3CacheImportExport(t *testing.T, sb integration.Sandbox) {
4677+
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
4678+
4679+
opts := integration.MinioOpts{
4680+
Region: "us-east-1",
4681+
AccessKeyID: "minioadmin",
4682+
SecretAccessKey: "minioadmin",
4683+
}
4684+
4685+
s3Addr, s3Bucket, cleanup, err := integration.NewMinioServer(t, sb, opts)
4686+
require.NoError(t, err)
4687+
defer cleanup()
4688+
4689+
im := CacheOptionsEntry{
4690+
Type: "s3",
4691+
Attrs: map[string]string{
4692+
"region": opts.Region,
4693+
"access_key_id": opts.AccessKeyID,
4694+
"secret_access_key": opts.SecretAccessKey,
4695+
"bucket": s3Bucket,
4696+
"endpoint_url": s3Addr,
4697+
"use_path_style": "true",
4698+
},
4699+
}
4700+
ex := CacheOptionsEntry{
4701+
Type: "s3",
4702+
Attrs: map[string]string{
4703+
"region": opts.Region,
4704+
"access_key_id": opts.AccessKeyID,
4705+
"secret_access_key": opts.SecretAccessKey,
4706+
"bucket": s3Bucket,
4707+
"endpoint_url": s3Addr,
4708+
"use_path_style": "true",
4709+
},
4710+
}
4711+
testBasicCacheImportExport(t, sb, []CacheOptionsEntry{im}, []CacheOptionsEntry{ex})
4712+
}
4713+
46754714
func testBasicInlineCacheImportExport(t *testing.T, sb integration.Sandbox) {
46764715
integration.CheckFeatureCompat(t, sb, integration.FeatureDirectPush, integration.FeatureCacheImport)
46774716
requiresLinux(t)

hack/s3_test/Dockerfile

Lines changed: 0 additions & 21 deletions
This file was deleted.

hack/s3_test/docker-bake.hcl

Lines changed: 0 additions & 11 deletions
This file was deleted.

hack/s3_test/run_test.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

hack/s3_test/test.sh

Lines changed: 0 additions & 98 deletions
This file was deleted.

hack/s3_test/test1/Dockerfile

Lines changed: 0 additions & 7 deletions
This file was deleted.

hack/s3_test/test2/Dockerfile

Lines changed: 0 additions & 9 deletions
This file was deleted.

util/testutil/integration/minio.go

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package integration
2+
3+
import (
4+
"fmt"
5+
"net"
6+
"net/http"
7+
"os"
8+
"os/exec"
9+
"testing"
10+
"time"
11+
12+
"github.com/pkg/errors"
13+
)
14+
15+
const (
16+
minioBin = "minio"
17+
mcBin = "mc"
18+
)
19+
20+
type MinioOpts struct {
21+
Region string
22+
AccessKeyID string
23+
SecretAccessKey string
24+
}
25+
26+
func NewMinioServer(t *testing.T, sb Sandbox, opts MinioOpts) (address string, bucket string, cl func() error, err error) {
27+
t.Helper()
28+
bucket = randomString(10)
29+
30+
if _, err := exec.LookPath(minioBin); err != nil {
31+
return "", "", nil, errors.Wrapf(err, "failed to lookup %s binary", minioBin)
32+
}
33+
if _, err := exec.LookPath(mcBin); err != nil {
34+
return "", "", nil, errors.Wrapf(err, "failed to lookup %s binary", mcBin)
35+
}
36+
37+
deferF := &multiCloser{}
38+
cl = deferF.F()
39+
40+
defer func() {
41+
if err != nil {
42+
deferF.F()()
43+
cl = nil
44+
}
45+
}()
46+
47+
l, err := net.Listen("tcp", "localhost:0")
48+
if err != nil {
49+
return "", "", nil, err
50+
}
51+
52+
addr := l.Addr().String()
53+
if err = l.Close(); err != nil {
54+
return "", "", nil, err
55+
}
56+
address = "http://" + addr
57+
58+
// start server
59+
cmd := exec.Command(minioBin, "server", "--json", "--address", addr, t.TempDir())
60+
cmd.Env = append(os.Environ(), []string{
61+
"MINIO_ROOT_USER=" + opts.AccessKeyID,
62+
"MINIO_ROOT_PASSWORD=" + opts.SecretAccessKey,
63+
}...)
64+
minioStop, err := startCmd(cmd, sb.Logs())
65+
if err != nil {
66+
return "", "", nil, err
67+
}
68+
if err = waitMinio(address, 15*time.Second); err != nil {
69+
minioStop()
70+
return "", "", nil, errors.Wrapf(err, "minio did not start up: %s", formatLogs(sb.Logs()))
71+
}
72+
deferF.append(minioStop)
73+
74+
// create alias config
75+
alias := randomString(10)
76+
cmd = exec.Command(mcBin, "alias", "set", alias, address, opts.AccessKeyID, opts.SecretAccessKey)
77+
if err := runCmd(cmd, sb.Logs()); err != nil {
78+
return "", "", nil, err
79+
}
80+
deferF.append(func() error {
81+
return exec.Command(mcBin, "alias", "rm", alias).Run()
82+
})
83+
84+
// create bucket
85+
cmd = exec.Command(mcBin, "mb", "--region", opts.Region, fmt.Sprintf("%s/%s", alias, bucket)) // #nosec G204
86+
if err := runCmd(cmd, sb.Logs()); err != nil {
87+
return "", "", nil, err
88+
}
89+
90+
// trace
91+
cmd = exec.Command(mcBin, "admin", "trace", "--json", alias)
92+
traceStop, err := startCmd(cmd, sb.Logs())
93+
if err != nil {
94+
return "", "", nil, err
95+
}
96+
deferF.append(traceStop)
97+
98+
return
99+
}
100+
101+
func waitMinio(address string, d time.Duration) error {
102+
step := 1 * time.Second
103+
i := 0
104+
for {
105+
if resp, err := http.Get(fmt.Sprintf("%s/minio/health/live", address)); err == nil {
106+
resp.Body.Close()
107+
break
108+
}
109+
i++
110+
if time.Duration(i)*step > d {
111+
return errors.Errorf("failed dialing: %s", address)
112+
}
113+
time.Sleep(step)
114+
}
115+
return nil
116+
}

0 commit comments

Comments
 (0)