Skip to content

Commit

Permalink
Nydusify: get nydus-image/nydusd path from env
Browse files Browse the repository at this point in the history
So that allow specifying the path from env by make command.

Signed-off-by: Yan Song <[email protected]>
  • Loading branch information
imeoer committed Mar 25, 2022
1 parent dfbad26 commit c01190c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
16 changes: 10 additions & 6 deletions contrib/nydusify/pkg/nydusify/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ type MergeOption struct {
PrefetchPatterns string
}

func getBuilder() string {
builderPath := os.Getenv(envNydusBuilder)
if builderPath == "" {
builderPath = "nydus-image"
}
return builderPath
}

// Unpack a OCI formatted tar stream into a directory.
func unpackOciTar(ctx context.Context, dst string, reader io.Reader) error {
ds, err := compression.DecompressStream(reader)
Expand Down Expand Up @@ -218,12 +226,8 @@ func Convert(ctx context.Context, src io.Reader, opt ConvertOption) (io.ReadClos
bootstrapPath := filepath.Join(workDir, "bootstrap")
blobPath := filepath.Join(workDir, "blob")

builderPath := os.Getenv(envNydusBuilder)
if builderPath == "" {
builderPath = "nydus-image"
}
if err := tool.Convert(tool.ConvertOption{
BuilderPath: builderPath,
BuilderPath: getBuilder(),

BootstrapPath: bootstrapPath,
BlobPath: blobPath,
Expand Down Expand Up @@ -294,7 +298,7 @@ func Merge(ctx context.Context, layers []Layer, opt MergeOption) (reader io.Read
targetBootstrapPath := filepath.Join(workDir, "bootstrap")

if err := tool.Merge(tool.MergeOption{
BuilderPath: "nydus-image",
BuilderPath: getBuilder(),

SourceBootstrapPaths: sourceBootstrapPaths,
TargetBootstrapPath: targetBootstrapPath,
Expand Down
8 changes: 7 additions & 1 deletion contrib/nydusify/pkg/nydusify/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/dragonflyoss/image-service/contrib/nydusify/pkg/nydusify/tool"
)

const envNydusdPath = "NYDUS_NYDUSD"

func hugeString(size int) string {
var buf strings.Builder
buf.Grow(size)
Expand Down Expand Up @@ -172,9 +174,13 @@ func convertLayer(t *testing.T, source io.ReadCloser, chunkDict, workDir string)
func verify(t *testing.T, workDir string) {
mountDir := filepath.Join(workDir, "mnt")
blobDir := filepath.Join(workDir, "blobs")
nydusdPath := os.Getenv(envNydusdPath)
if nydusdPath == "" {
nydusdPath = "nydusd"
}
config := tool.NydusdConfig{
EnablePrefetch: true,
NydusdPath: "nydusd",
NydusdPath: nydusdPath,
BootstrapPath: filepath.Join(workDir, "bootstrap"),
ConfigPath: filepath.Join(workDir, "nydusd-config.json"),
BackendType: "localfs",
Expand Down

0 comments on commit c01190c

Please sign in to comment.