Skip to content

Commit

Permalink
nydusify: support v6 image build test
Browse files Browse the repository at this point in the history
Signed-off-by: zyfjeff <tianqian.zyf@alibaba-inc.com>
  • Loading branch information
zyfjeff committed Jun 7, 2022
1 parent e2f9ca4 commit 64f2b37
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
37 changes: 19 additions & 18 deletions contrib/nydusify/tests/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,74 +9,75 @@ import (
"testing"
)

func testBasicConvert(t *testing.T) {
func testBasicConvert(t *testing.T, imageVersion string) {
registry := NewRegistry(t)
defer registry.Destroy(t)

registry.Build(t, "image-basic")
nydusify := NewNydusify(registry, "image-basic", "image-basic-nydus", "", "")
nydusify := NewNydusify(registry, "image-basic", "image-basic-nydus", "", "", imageVersion)
nydusify.Convert(t)
nydusify.Check(t)
}

func testConvertWithCache(t *testing.T) {
func testConvertWithCache(t *testing.T, imageVersion string) {
registry := NewRegistry(t)
defer registry.Destroy(t)

registry.Build(t, "image-basic")
nydusify1 := NewNydusify(registry, "image-basic", "image-basic-nydus-1", "cache:v1", "")
nydusify1 := NewNydusify(registry, "image-basic", "image-basic-nydus-1", "cache:v1", "", imageVersion)
nydusify1.Convert(t)
nydusify1.Check(t)

nydusify2 := NewNydusify(registry, "image-basic", "image-basic-nydus-2", "cache:v1", "")
nydusify2 := NewNydusify(registry, "image-basic", "image-basic-nydus-2", "cache:v1", "", imageVersion)
nydusify2.Convert(t)
nydusify2.Check(t)

registry.Build(t, "image-from-1")
nydusify3 := NewNydusify(registry, "image-from-1", "image-from-nydus-1", "cache:v1", "")
nydusify3 := NewNydusify(registry, "image-from-1", "image-from-nydus-1", "cache:v1", "", imageVersion)
nydusify3.Convert(t)
nydusify3.Check(t)

registry.Build(t, "image-from-2")
nydusify4 := NewNydusify(registry, "image-from-2", "image-from-nydus-2", "cache:v1", "")
nydusify4 := NewNydusify(registry, "image-from-2", "image-from-nydus-2", "cache:v1", "", imageVersion)
nydusify4.Convert(t)
nydusify4.Check(t)
}

func testConvertWithChunkDict(t *testing.T) {
func testConvertWithChunkDict(t *testing.T, imageVersion string) {
registry := NewRegistry(t)
defer registry.Destroy(t)

registry.Build(t, "chunk-dict-1")
// build chunk-dict-1 bootstrap
nydusify1 := NewNydusify(registry, "chunk-dict-1", "nydus:chunk-dict-1", "", "")
nydusify1 := NewNydusify(registry, "chunk-dict-1", "nydus:chunk-dict-1", "", "", imageVersion)
nydusify1.Convert(t)
nydusify1.Check(t)
chunkDictOpt := fmt.Sprintf("bootstrap:registry:%s/%s", registry.Host(), "nydus:chunk-dict-1")
// build without build-cache
registry.Build(t, "image-basic")
nydusify2 := NewNydusify(registry, "image-basic", "nydus:image-basic", "", chunkDictOpt)
nydusify2 := NewNydusify(registry, "image-basic", "nydus:image-basic", "", chunkDictOpt, imageVersion)
nydusify2.Convert(t)
nydusify2.Check(t)
// build with build-cache
registry.Build(t, "image-from-1")
nydusify3 := NewNydusify(registry, "image-from-1", "nydus:image-from-1", "nydus:cache_v1", chunkDictOpt)
nydusify3 := NewNydusify(registry, "image-from-1", "nydus:image-from-1", "nydus:cache_v1", chunkDictOpt, imageVersion)
nydusify3.Convert(t)
nydusify3.Check(t)
// change chunk dict
registry.Build(t, "chunk-dict-2")
nydusify4 := NewNydusify(registry, "chunk-dict-2", "nydus:chunk-dict-2", "", "")
nydusify4 := NewNydusify(registry, "chunk-dict-2", "nydus:chunk-dict-2", "", "", imageVersion)
nydusify4.Convert(t)
nydusify4.Check(t)
chunkDictOpt = fmt.Sprintf("bootstrap:registry:%s/%s", registry.Host(), "nydus:chunk-dict-2")
registry.Build(t, "image-from-2")
nydusify5 := NewNydusify(registry, "image-from-2", "nydus:image-from-2", "nydus:cache_v1", chunkDictOpt)
nydusify5 := NewNydusify(registry, "image-from-2", "nydus:image-from-2", "nydus:cache_v1", chunkDictOpt, imageVersion)
nydusify5.Convert(t)
nydusify5.Check(t)
}

func TestSmoke(t *testing.T) {
testBasicConvert(t)
testConvertWithCache(t)
testConvertWithChunkDict(t)
imageVersions := [2]string{"5", "6"}
for _, v := range imageVersions {
testBasicConvert(t, v)
testConvertWithCache(t, v)
testConvertWithChunkDict(t, v)
}
}
7 changes: 4 additions & 3 deletions contrib/nydusify/tests/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ func transfer(t *testing.T, ref string) {
run(t, fmt.Sprintf("docker push %s/%s", host, ref), true)
}

func convert(t *testing.T, ref string) {
func convert(t *testing.T, ref string, imageVersion string) {
registry := NewRegistry(t)
defer registry.Destroy(t)
transfer(t, ref)
nydusify := NewNydusify(registry, ref, fmt.Sprintf("%s-nydus", ref), "", "")
nydusify := NewNydusify(registry, ref, fmt.Sprintf("%s-nydus", ref), "", "", imageVersion)
nydusify.Convert(t)
nydusify.Check(t)
}

func TestDockerHubImage(t *testing.T) {
for _, ref := range list {
convert(t, ref)
convert(t, ref, "5")
convert(t, ref, "6")
}
}
8 changes: 7 additions & 1 deletion contrib/nydusify/tests/nydusify.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ type Nydusify struct {
backendType string
backendConfig string
chunkDictArgs string
imageVersion string
}

func NewNydusify(registry *Registry, source, target, cache string, chunkDictArgs string) *Nydusify {
func NewNydusify(registry *Registry, source, target, cache string, chunkDictArgs string, imageVersion string) *Nydusify {
host := registry.Host()

backendType := "registry"
Expand All @@ -60,6 +61,9 @@ func NewNydusify(registry *Registry, source, target, cache string, chunkDictArgs
if os.Getenv("BACKEND_CONFIG") != "" {
backendConfig = os.Getenv("BACKEND_CONFIG")
}
if len(imageVersion) == 0 {
imageVersion = "5"
}

return &Nydusify{
Registry: registry,
Expand All @@ -69,6 +73,7 @@ func NewNydusify(registry *Registry, source, target, cache string, chunkDictArgs
backendType: backendType,
backendConfig: backendConfig,
chunkDictArgs: chunkDictArgs,
imageVersion: imageVersion,
}
}

Expand Down Expand Up @@ -128,6 +133,7 @@ func (nydusify *Nydusify) Convert(t *testing.T) {
Insecure: false,
Platform: "linux/amd64",
},
ImageVersion: nydusify.imageVersion,
}

cvt, err := converter.New(opt)
Expand Down

0 comments on commit 64f2b37

Please sign in to comment.