diff --git a/internal/app/wwctl/container/exec/main.go b/internal/app/wwctl/container/exec/main.go index 0e818d85..1ad9ff03 100644 --- a/internal/app/wwctl/container/exec/main.go +++ b/internal/app/wwctl/container/exec/main.go @@ -38,12 +38,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } fmt.Printf("Rebuilding container...\n") - output, err := container.Build(containerName, false) + err := container.Build(containerName, false) if err != nil { wwlog.Printf(wwlog.ERROR, "Could not build container %s: %s\n", containerName, err) os.Exit(1) } else { - fmt.Printf("%s\n", output) + //fmt.Printf("%s\n", output) } return nil diff --git a/internal/app/wwctl/container/imprt/main.go b/internal/app/wwctl/container/imprt/main.go index 180980fb..3a3ef37f 100644 --- a/internal/app/wwctl/container/imprt/main.go +++ b/internal/app/wwctl/container/imprt/main.go @@ -5,6 +5,7 @@ import ( "os" "path" "strconv" + "strings" "github.com/containers/image/v5/types" "github.com/hpcng/warewulf/internal/pkg/container" @@ -85,38 +86,46 @@ func CobraRunE(cmd *cobra.Command, args []string) error { if util.IsDir(fullPath) == true { if SetForce == true { - wwlog.Printf(wwlog.WARN, "Overwriting existing VNFS\n") + fmt.Printf("Overwriting existing VNFS\n") err := os.RemoveAll(fullPath) if err != nil { wwlog.Printf(wwlog.ERROR, "%s\n", err) os.Exit(1) } } else if SetUpdate == true { - wwlog.Printf(wwlog.WARN, "Updating existing VNFS\n") + fmt.Printf("Updating existing VNFS\n") } else { wwlog.Printf(wwlog.ERROR, "VNFS Name exists, specify --force, --update, or choose a different name: %s\n", name) os.Exit(1) } } - sCtx, err := getSystemContext() - if err != nil { - wwlog.Printf(wwlog.ERROR, "%s\n", err) - } + if strings.HasPrefix(uri, "docker://") || strings.HasPrefix(uri, "docker-daemon://") { + sCtx, err := getSystemContext() + if err != nil { + wwlog.Printf(wwlog.ERROR, "%s\n", err) + } - err = container.PullURI(uri, name, sCtx) - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not pull image: %s\n", err) - os.Exit(1) + err = container.ImportDocker(uri, name, sCtx) + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not import image: %s\n", err) + os.Exit(1) + } + } else if util.IsDir(uri) { + err := container.ImportDirectory(uri, name) + if err != nil { + wwlog.Printf(wwlog.ERROR, "Could not import image: %s\n", err) + os.Exit(1) + } } fmt.Printf("Building container: %s\n", name) - output, err := container.Build(name, true) + err := container.Build(name, true) if err != nil { wwlog.Printf(wwlog.ERROR, "Could not build container %s: %s\n", name, err) os.Exit(1) } else { - fmt.Printf("%s: %s\n", name, output) + //fmt.Printf("%s: %s\n", name, output) } if SetDefault == true { diff --git a/internal/pkg/container/pull.go b/internal/pkg/container/imprt.go similarity index 60% rename from internal/pkg/container/pull.go rename to internal/pkg/container/imprt.go index 26a4680b..fa33141d 100644 --- a/internal/pkg/container/pull.go +++ b/internal/pkg/container/imprt.go @@ -2,7 +2,9 @@ package container import ( "context" + "github.com/hpcng/warewulf/internal/pkg/util" "os" + "path" "github.com/containers/image/v5/types" "github.com/hpcng/warewulf/internal/pkg/config" @@ -10,7 +12,7 @@ import ( "github.com/hpcng/warewulf/internal/pkg/oci" ) -func PullURI(uri string, name string, sCtx *types.SystemContext) error { +func ImportDocker(uri string, name string, sCtx *types.SystemContext) error { OciBlobCacheDir := config.LocalStateDir + "/oci/blobs" err := os.MkdirAll(OciBlobCacheDir, 0755) @@ -47,3 +49,27 @@ func PullURI(uri string, name string, sCtx *types.SystemContext) error { return nil } + +func ImportDirectory(uri string, name string) error { + fullPath := RootFsDir(name) + + err := os.MkdirAll(fullPath, 0755) + if err != nil { + return err + } + + if !util.IsDir(uri) { + return errors.New("Import directory does not exist: " + uri) + } + + if !util.IsFile(path.Join(fullPath, "/bin/sh")) { + return errors.New("Source directory has no /bin/sh: " + uri) + } + + err = util.CopyFiles(uri, fullPath) + if err != nil { + return err + } + + return nil +}