Skip to content

Commit

Permalink
fix sealer alpha mount bug (#1985)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevent-fei committed Jan 17, 2023
1 parent 8470f90 commit 9934e11
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions cmd/sealer/cmd/alpha/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
package alpha

import (
"fmt"
"os"
"path/filepath"
"strings"
"time"

"github.com/containers/storage"
"github.com/olekukonko/tablewriter"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/olekukonko/tablewriter"
"github.com/sealerio/sealer/common"
"github.com/sealerio/sealer/pkg/define/options"
"github.com/sealerio/sealer/pkg/imageengine"
"github.com/sealerio/sealer/pkg/imageengine/buildah"
)

Expand Down Expand Up @@ -81,16 +82,32 @@ func NewMountCmd() *cobra.Command {
}
}

imageEngine, err := imageengine.NewImageEngine(options.EngineGlobalConfigurations{})
cid, err := engine.CreateContainer(&options.FromOptions{
Image: args[0],
Quiet: false,
})
if err != nil {
return err
}

//too fast to mount.
time.Sleep(time.Second * 1)

mounts, err := engine.Mount(&options.MountOptions{Containers: []string{cid}})
if err != nil {
return err
}
if _, err := imageEngine.CreateWorkingContainer(&options.BuildRootfsOptions{
DestDir: path,
ImageNameOrID: args[0],
}); err != nil {

// remove destination dir if it exists, otherwise the Symlink will fail.
if _, err = os.Stat(path); err == nil {
return fmt.Errorf("destination directionay %s exists, you should remove it first", path)
}

mountPoint := mounts[0].MountPoint
if err := os.Symlink(mountPoint, path); err != nil {
return err
}

logrus.Infof("mount cluster image %s to %s successful", args[0], path)
return nil
},
Expand Down

0 comments on commit 9934e11

Please sign in to comment.