Support container import of chroot directory
This commit is contained in:
@@ -38,12 +38,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Rebuilding container...\n")
|
fmt.Printf("Rebuilding container...\n")
|
||||||
output, err := container.Build(containerName, false)
|
err := container.Build(containerName, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wwlog.Printf(wwlog.ERROR, "Could not build container %s: %s\n", containerName, err)
|
wwlog.Printf(wwlog.ERROR, "Could not build container %s: %s\n", containerName, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%s\n", output)
|
//fmt.Printf("%s\n", output)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/image/v5/types"
|
"github.com/containers/image/v5/types"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/container"
|
"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 util.IsDir(fullPath) == true {
|
||||||
if SetForce == true {
|
if SetForce == true {
|
||||||
wwlog.Printf(wwlog.WARN, "Overwriting existing VNFS\n")
|
fmt.Printf("Overwriting existing VNFS\n")
|
||||||
err := os.RemoveAll(fullPath)
|
err := os.RemoveAll(fullPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
} else if SetUpdate == true {
|
} else if SetUpdate == true {
|
||||||
wwlog.Printf(wwlog.WARN, "Updating existing VNFS\n")
|
fmt.Printf("Updating existing VNFS\n")
|
||||||
} else {
|
} else {
|
||||||
wwlog.Printf(wwlog.ERROR, "VNFS Name exists, specify --force, --update, or choose a different name: %s\n", name)
|
wwlog.Printf(wwlog.ERROR, "VNFS Name exists, specify --force, --update, or choose a different name: %s\n", name)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sCtx, err := getSystemContext()
|
if strings.HasPrefix(uri, "docker://") || strings.HasPrefix(uri, "docker-daemon://") {
|
||||||
if err != nil {
|
sCtx, err := getSystemContext()
|
||||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
if err != nil {
|
||||||
}
|
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
err = container.PullURI(uri, name, sCtx)
|
err = container.ImportDocker(uri, name, sCtx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wwlog.Printf(wwlog.ERROR, "Could not pull image: %s\n", err)
|
wwlog.Printf(wwlog.ERROR, "Could not import image: %s\n", err)
|
||||||
os.Exit(1)
|
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)
|
fmt.Printf("Building container: %s\n", name)
|
||||||
output, err := container.Build(name, true)
|
err := container.Build(name, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wwlog.Printf(wwlog.ERROR, "Could not build container %s: %s\n", name, err)
|
wwlog.Printf(wwlog.ERROR, "Could not build container %s: %s\n", name, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%s: %s\n", name, output)
|
//fmt.Printf("%s: %s\n", name, output)
|
||||||
}
|
}
|
||||||
|
|
||||||
if SetDefault == true {
|
if SetDefault == true {
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package container
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
"github.com/containers/image/v5/types"
|
"github.com/containers/image/v5/types"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/config"
|
"github.com/hpcng/warewulf/internal/pkg/config"
|
||||||
@@ -10,7 +12,7 @@ import (
|
|||||||
"github.com/hpcng/warewulf/internal/pkg/oci"
|
"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"
|
OciBlobCacheDir := config.LocalStateDir + "/oci/blobs"
|
||||||
|
|
||||||
err := os.MkdirAll(OciBlobCacheDir, 0755)
|
err := os.MkdirAll(OciBlobCacheDir, 0755)
|
||||||
@@ -47,3 +49,27 @@ func PullURI(uri string, name string, sCtx *types.SystemContext) error {
|
|||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user