Skip to content

Commit

Permalink
compose: handle --fs option to support both ZFS and ROFS
Browse files Browse the repository at this point in the history
Signed-off-by: Waldemar Kozaczuk <[email protected]>
  • Loading branch information
wkozaczuk committed May 23, 2023
1 parent 3c09168 commit 68fc0e5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
8 changes: 7 additions & 1 deletion capstan.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ func main() {
&cli.StringFlag{Name: "size", Aliases: []string{"s"}, Value: "10G", Usage: "size of the target user partition (use M or G suffix)"},
&cli.StringFlag{Name: "command_line", Aliases: []string{"c"}, Usage: "command line OSv will boot with"},
&cli.BoolFlag{Name: "verbose", Aliases: []string{"v"}, Usage: "verbose mode"},
&cli.StringFlag{Name: "fs", Usage: "specify type of filesystem: zfs or rofs"},
},
Action: func(c *cli.Context) error {
if c.Args().Len() != 2 {
Expand All @@ -274,7 +275,12 @@ func main() {
return cli.NewExitError(fmt.Sprintf("Incorrect image size format: %s\n", err), EX_DATAERR)
}

if err := cmd.Compose(repo, loaderImage, imageSize, uploadPath, appName, commandLine, verbose); err != nil {
filesystem := c.String("fs")
if filesystem == "" || (filesystem != "zfs" && filesystem != "rofs") {
filesystem = "zfs"
}

if err := cmd.Compose(repo, loaderImage, imageSize, filesystem, uploadPath, appName, commandLine, verbose); err != nil {
return cli.NewExitError(err.Error(), EX_DATAERR)
}
return nil
Expand Down
50 changes: 35 additions & 15 deletions cmd/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,53 @@ import (
"io/ioutil"
"net"
"os"
"path"
"path/filepath"
"strings"
)

func Compose(r *util.Repo, loaderImage string, imageSize int64, uploadPath string, appName string, commandLine string, verbose bool) error {
zfsBuilderPath, err := r.GetZfsBuilderImagePath()
if err != nil {
return err
}
// Initialize an empty image based on the provided loader image. imageSize is used to
// determine the size of the user partition.
err = r.InitializeZfsImage(loaderImage, appName, imageSize)
func Compose(r *util.Repo, loaderImage string, imageSize int64, filesystem string, uploadPath string, appName string, commandLine string, verbose bool) error {
// If all is well, we have to start preparing the files for upload.
paths, err := CollectPathContents(uploadPath)
if err != nil {
return err
}

// Get the path of imported image.
imagePath := r.ImagePath("qemu", appName)

paths, err := CollectPathContents(uploadPath)
if err != nil {
return err
}
if filesystem == "zfs" {
// Create ZFS
zfsBuilderPath, err := r.GetZfsBuilderImagePath()
if err != nil {
return err
}
// Initialize an empty image based on the provided loader image. imageSize is used to
// determine the size of the user partition.
err = r.InitializeZfsImage(loaderImage, appName, imageSize)
if err != nil {
return err
}

// Upload the specified path onto virtual image.
if _, err = UploadPackageContents(r, imagePath, paths, nil, verbose, zfsBuilderPath); err != nil {
return err
// Upload the specified path onto virtual image.
if _, err = UploadPackageContents(r, imagePath, paths, nil, verbose, zfsBuilderPath); err != nil {
return err
}
} else {
// Create ROFS
// Create temporary folder in which the image will be composed.
tmp, _ := ioutil.TempDir("", "capstan")
// Once this function is finished, remove temporary file.
defer os.RemoveAll(tmp)
rofs_image_path := path.Join(tmp, "rofs.img")

if err := util.WriteRofsImage(rofs_image_path, paths, uploadPath, verbose); err != nil {
return fmt.Errorf("Failed to write ROFS image named %s.\nError was: %s", rofs_image_path, err)
}

if err = r.CreateRofsImage(loaderImage, appName, rofs_image_path); err != nil {
return fmt.Errorf("Failed to create ROFS image named %s.\nError was: %s", appName, err)
}
}

if commandLine != "" {
Expand Down

0 comments on commit 68fc0e5

Please sign in to comment.