Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions cmd/sealer/cmd/image/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ import (
"github.com/sealerio/sealer/pkg/imageengine"
)

var loadOpts *options.LoadOptions
var (
loadOpts *options.LoadOptions

var longNewLoadCmdDescription = `Load a sealer image from a tar archive`
longNewLoadCmdDescription = `
Load a sealer image from a tar archive
Save an image to docker-archive or oci-archive on the local machine. Default is docker-archive.`

var exampleForLoadCmd = `
exampleForLoadCmd = `
sealer load -i kubernetes.tar
`

Specifies the temporary load directory:
sealer load -i my.tar --tmp-dir /root/my-tmp`
)

// NewLoadCmd loadCmd represents the load command
func NewLoadCmd() *cobra.Command {
Expand All @@ -40,28 +46,31 @@ func NewLoadCmd() *cobra.Command {
Long: longNewLoadCmdDescription,
Example: exampleForLoadCmd,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
engine, err := imageengine.NewImageEngine(options.EngineGlobalConfigurations{})
if err != nil {
return err
}

err = engine.Load(loadOpts)
if err == nil {
logrus.Infof("successfully load %s to image storage", loadOpts.Input)
}

return err
},
RunE: runLoadCmd,
}
loadOpts = &options.LoadOptions{}
flags := loadCmd.Flags()
flags.StringVarP(&loadOpts.Input, "input", "i", "", "Load image from file")
flags.StringVarP(&loadOpts.Input, "input", "i", "", "Read from specified archive file")
flags.BoolVarP(&loadOpts.Quiet, "quiet", "q", false, "Suppress the output")
flags.StringVar(&loadOpts.TmpDir, "tmp-dir", "", "set temporary directory when load image. if not set, use system`s temporary directory")
flags.StringVar(&loadOpts.TmpDir, "tmp-dir", "", "Set temporary directory when load image. use system temporary directory is not (/var/tmp/)at present ")
Copy link
Copy Markdown
Member

@kakaZhou719 kakaZhou719 Apr 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set temporary directory when load image. use system temporary directory(/tmp/) if not present.


if err := loadCmd.MarkFlagRequired("input"); err != nil {
logrus.Errorf("failed to init flag: %v", err)
os.Exit(1)
}
return loadCmd
}

func runLoadCmd(cmd *cobra.Command, args []string) error {
engine, err := imageengine.NewImageEngine(options.EngineGlobalConfigurations{})
if err != nil {
return err
}

err = engine.Load(loadOpts)
if err == nil {
logrus.Infof("successfully load %s to image storage", loadOpts.Input)
}

return err
}
6 changes: 2 additions & 4 deletions pkg/imageengine/buildah/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,9 @@ func (engine *Engine) Load(opts *options.LoadOptions) error {

manifestName := string(metaBytes)
// delete it if manifestName is already used
_, err = engine.ImageRuntime().LookupManifestList(manifestName)
if err == nil {
if _, err := engine.ImageRuntime().LookupManifestList(manifestName); err == nil {
logrus.Warnf("%s is already in use, will delete it", manifestName)
delErr := engine.DeleteManifests([]string{manifestName}, &options.ManifestDeleteOpts{})
if delErr != nil {
if delErr := engine.DeleteManifests([]string{manifestName}, &options.ManifestDeleteOpts{}); delErr != nil {
return fmt.Errorf("%s is already in use: %v", manifestName, delErr)
}
}
Expand Down