Skip to content

Commit

Permalink
nydusify: fix tests after refactoring
Browse files Browse the repository at this point in the history
And remove useless `registry` backend type.

Signed-off-by: Yan Song <imeoer@linux.alibaba.com>
  • Loading branch information
imeoer committed Dec 22, 2022
1 parent 85ca323 commit fcf5e8c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 89 deletions.
10 changes: 5 additions & 5 deletions contrib/nydusify/cmd/nydusify.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func getBackendConfig(c *cli.Context, required bool) (string, string, error) {
}
return "", "", nil
}
possibleBackendTypes := []string{"registry", "oss", "s3"}
possibleBackendTypes := []string{"oss", "s3"}
if !isPossibleValue(possibleBackendTypes, backendType) {
return "", "", fmt.Errorf("--backend-type should be one of %v", possibleBackendTypes)
}
Expand Down Expand Up @@ -240,7 +240,7 @@ func main() {
&cli.StringFlag{
Name: "backend-type",
Value: "registry",
Usage: "Type of storage backend, possible values: 'registry', 'oss', 's3'",
Usage: "Type of storage backend, possible values: 'oss', 's3'",
EnvVars: []string{"BACKEND_TYPE"},
},
&cli.StringFlag{
Expand Down Expand Up @@ -499,7 +499,7 @@ func main() {
&cli.StringFlag{
Name: "backend-type",
Value: "",
Usage: "Type of storage backend, enable verification of file data in Nydus image if specified, possible values: 'registry', 'oss', 's3'",
Usage: "Type of storage backend, enable verification of file data in Nydus image if specified, possible values: 'oss', 's3'",
EnvVars: []string{"BACKEND_TYPE"},
},
&cli.StringFlag{
Expand Down Expand Up @@ -602,7 +602,7 @@ func main() {
Name: "backend-type",
Value: "",
Required: true,
Usage: "Type of storage backend, possible values: 'registry', 'oss', 's3'",
Usage: "Type of storage backend, possible values: 'oss', 's3'",
EnvVars: []string{"BACKEND_TYPE"},
},
&cli.StringFlag{
Expand Down Expand Up @@ -714,7 +714,7 @@ func main() {
Name: "backend-type",
Value: "oss",
DefaultText: "oss",
Usage: "Type of storage backend, possible values: 'registry', 'oss', 's3'",
Usage: "Type of storage backend, possible values: 'oss', 's3'",
EnvVars: []string{"BACKEND_TYPE"},
},
&cli.StringFlag{
Expand Down
40 changes: 5 additions & 35 deletions contrib/nydusify/examples/converter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

"github.com/dragonflyoss/image-service/contrib/nydusify/pkg/converter"
"github.com/dragonflyoss/image-service/contrib/nydusify/pkg/provider"
)

func main() {
Expand All @@ -13,37 +12,13 @@ func main() {
nydusImagePath := "/path/to/nydus-image"
source := "localhost:5000/ubuntu:latest"
target := "localhost:5000/ubuntu:latest-nydus"
// Set to empty if no authorization be required
auth := "<base64_encoded_auth>"
// Set to false if using https registry
insecure := true

// Logger outputs Nydus image conversion progress
logger, err := provider.DefaultLogger()
if err != nil {
panic(err)
}

// Create remote with auth string for registry communication
sourceRemote, err := provider.DefaultRemoteWithAuth(source, insecure, auth)
if err != nil {
panic(err)
}
// Or we can create with docker config
// sourceRemote, err := provider.DefaultRemote(source, insecure)
// if err != nil {
// panic(err)
// }
targetRemote, err := provider.DefaultRemoteWithAuth(target, insecure, auth)
if err != nil {
panic(err)
}

opt := converter.Opt{
Logger: logger,
TargetPlatform: "linux/amd64",
SourceRemote: sourceRemote,
TargetRemote: targetRemote,
Source: source,
Target: target,
SourceInsecure: true,
TargetInsecure: true,

WorkDir: workDir,
PrefetchPatterns: "/",
Expand All @@ -52,12 +27,7 @@ func main() {
DockerV2Format: true,
}

cvt, err := converter.New(opt)
if err != nil {
panic(err)
}

if err := cvt.Convert(context.Background()); err != nil {
if err := converter.Convert(context.Background(), opt); err != nil {
panic(err)
}
}
55 changes: 6 additions & 49 deletions contrib/nydusify/tests/nydusify.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@ package tests

import (
"context"
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"

"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"

"github.com/dragonflyoss/image-service/contrib/nydusify/pkg/checker"
"github.com/dragonflyoss/image-service/contrib/nydusify/pkg/converter"
"github.com/dragonflyoss/image-service/contrib/nydusify/pkg/provider"
"github.com/dragonflyoss/image-service/contrib/nydusify/pkg/remote"
)

var nydusImagePath string
Expand Down Expand Up @@ -47,25 +43,12 @@ type Nydusify struct {
workDir string
}

func buildRegistryBackendConfig(registry *Registry, repo string) string {
config := make(map[string]string)
config["host"] = registry.host
config["repo"] = repo
config["scheme"] = "http"
if registry.authString != "" {
config["auth"] = registry.authString
}
configBytes, _ := json.Marshal(config)
return string(configBytes)
}

func NewNydusify(registry *Registry, source, target, cache string, chunkDictArgs string, fsVersion string) *Nydusify {
backendType := "registry"
backendType := ""
if os.Getenv("BACKEND_TYPE") != "" {
backendType = os.Getenv("BACKEND_TYPE")
}
repoTag := strings.Split(target, ":")
backendConfig := buildRegistryBackendConfig(registry, repoTag[0])
backendConfig := ""
if os.Getenv("BACKEND_CONFIG") != "" {
backendConfig = os.Getenv("BACKEND_CONFIG")
}
Expand Down Expand Up @@ -102,30 +85,12 @@ func (nydusify *Nydusify) Convert(t *testing.T) {
buildCache = host + "/" + nydusify.Cache
}

logger, err := provider.DefaultLogger()
assert.Nil(t, err)

sourceRemote, err := provider.DefaultRemote(host+"/"+nydusify.Source, true)
assert.Nil(t, err)

targetRemote, err := provider.DefaultRemote(host+"/"+nydusify.Target, true)
assert.Nil(t, err)

var cacheRemote *remote.Remote
if buildCache != "" {
buildCache = host + "/" + nydusify.Cache
cacheRemote, err = provider.DefaultRemote(buildCache, true)
assert.Nil(t, err)
}

opt := converter.Opt{
Logger: logger,

TargetPlatform: "linux/amd64",
SourceRemote: sourceRemote,
TargetRemote: targetRemote,
Source: host + "/" + nydusify.Source,
Target: host + "/" + nydusify.Target,

CacheRemote: cacheRemote,
CacheRef: buildCache,
CacheMaxRecords: 10,
CacheVersion: "v1",

Expand All @@ -138,18 +103,10 @@ func (nydusify *Nydusify) Convert(t *testing.T) {
BackendType: nydusify.backendType,
BackendConfig: nydusify.backendConfig,

ChunkDict: converter.ChunkDictOpt{
Args: nydusify.chunkDictArgs,
Insecure: false,
Platform: "linux/amd64",
},
FsVersion: nydusify.fsVersion,
}

cvt, err := converter.New(opt)
assert.Nil(t, err)

err = cvt.Convert(context.Background())
err := converter.Convert(context.Background(), opt)
assert.Nil(t, err)
}

Expand Down

0 comments on commit fcf5e8c

Please sign in to comment.