Files
warewulf/internal/pkg/image/imprt.go
Jonathon Anderson 45a690ca4e Rename "container" to "image"
- Updated `wwctl upgrade` to handle updates
- Maintained `.Container` and `.ContainerName` in tstruct
- Added `ContainerName()` methods to node and profile objects
- Added `--container`, `-C` aliases to wwctl commands (`<node|profile> <add|set>`)
- Added `wwctl container` alias
- Added support for `container_exit.sh` if `image_exit.sh` is not found

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
2025-01-19 05:54:19 -07:00

81 lines
1.6 KiB
Go

package image
import (
"context"
"os"
"path"
"github.com/containers/image/v5/types"
"github.com/containers/storage/drivers/copy"
"github.com/containers/storage/pkg/reexec"
"github.com/pkg/errors"
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
"github.com/warewulf/warewulf/internal/pkg/oci"
"github.com/warewulf/warewulf/internal/pkg/util"
)
func ImportDocker(uri string, name string, sCtx *types.SystemContext) error {
OciBlobCacheDir := warewulfconf.Get().Paths.OciBlobCachedir()
err := os.MkdirAll(OciBlobCacheDir, 0755)
if err != nil {
return err
}
if !ValidName(name) {
return errors.New("Image name contains illegal characters: " + name)
}
fullPath := RootFsDir(name)
err = os.MkdirAll(fullPath, 0755)
if err != nil {
return err
}
p, err := oci.NewPuller(
oci.OptSetBlobCachePath(OciBlobCacheDir),
oci.OptSetSystemContext(sCtx),
)
if err != nil {
return err
}
if _, err := p.GenerateID(context.Background(), uri); err != nil {
return err
}
if err := p.Pull(context.Background(), uri, fullPath); err != nil {
return err
}
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(uri, "/bin/sh")) {
return errors.New("Source directory has no /bin/sh: " + uri)
}
if reexec.Init() {
return errors.New("couldn't init reexec")
}
err = copy.DirCopy(uri, fullPath, copy.Content, true)
if err != nil {
return err
}
return nil
}