Skip to content

Commit 0b1262f

Browse files
authored
Merge pull request #6 from sarus-suite/mksquahsfs-options
Mksquahsfs options
2 parents dc4ef34 + 5a48ce8 commit 0b1262f

File tree

4 files changed

+89
-9
lines changed

4 files changed

+89
-9
lines changed

cmd/migration.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,23 @@ func createSquashSidecarFromMount(srcDir, link string, cfg common.Config) error
334334
if err := os.MkdirAll(filepath.Dir(squashPath), 0o755); err != nil {
335335
return err
336336
}
337-
// TODO: how to expose options? particularly the compression?
338-
cmd := exec.Command(cfg.MksquashfsPath,
339-
srcDir, squashPath,
340-
"-noappend", "-comp", "zstd", "-Xcompression-level", "1", "-noD",
341-
"-no-xattrs", "-e", "security.capability")
337+
338+
// Choose default or user provided flags
339+
defaultFlags := []string {
340+
"-noappend",
341+
"-comp", "zstd",
342+
"-Xcompression-level", "1",
343+
"-noD", "-no-xattrs",
344+
"-e", "security.capability",
345+
}
346+
flags := defaultFlags
347+
if len(cfg.MksquashfsOpts) > 0 {
348+
flags = cfg.MksquashfsOpts
349+
}
350+
351+
// Build mksquashfs command
352+
arg := append([]string{srcDir, squashPath}, flags...)
353+
cmd := exec.Command(cfg.MksquashfsPath, arg...)
342354
if out, err := cmd.CombinedOutput(); err != nil {
343355
return fmt.Errorf("mksquashfs: %v\n%s", err, out)
344356
}

common/cli.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88

99
"github.com/sirupsen/logrus"
10+
"github.com/mattn/go-shellwords"
1011
)
1112

1213
// TODO: auto gen version field
@@ -35,6 +36,7 @@ Options:
3536
"podmanRoot",
3637
"roStoragePath",
3738
"mksquashfsPath",
39+
"mksquashfs-opts",
3840
"log-level",
3941
"version",
4042
}
@@ -96,6 +98,7 @@ func ParseAndValidateFlags(fs *flag.FlagSet, args []string) (*CLI, error) {
9698
podmanRoot := fs.String("podmanRoot", "/var/lib/containers/storage", "Path to Podman root storage directory")
9799
roStorage := fs.String("roStoragePath", "/mnt/nfs/podman", "Path to read-only storage location")
98100
mksquashfs := fs.String("mksquashfsPath", "/usr/bin/mksquashfs", "Path to mksquashfs binary")
101+
mksOptsF := fs.String("mksquashfs-opts", "", "Parameters for mksquashfs")
99102
image := fs.String("image", "", "the name (:tag) of the image to remove")
100103
logLevelF := fs.String("log-level", "info", "Logging level (debug, info, warn, error, fatal, panic)")
101104
migrateF := fs.Bool("migrate", false, "Migrates an image")
@@ -141,13 +144,26 @@ func ParseAndValidateFlags(fs *flag.FlagSet, args []string) (*CLI, error) {
141144
return nil, fmt.Errorf("Invalid log level %q", *logLevelF)
142145
}
143146

147+
// Lets parse the mksquashfs options into a string[]
148+
var opts []string
149+
if *mksOptsF != "" {
150+
parser := shellwords.NewParser()
151+
parser.ParseBacktick = true
152+
parsed, err := parser.Parse(*mksOptsF)
153+
if err != nil {
154+
return nil, fmt.Errorf("invalid mksquashfs-opts: %w", err)
155+
}
156+
opts = parsed
157+
}
158+
144159
// We made it through checks we can init the CLI struct
145160
return &CLI {
146161
Config: Config {
147162
PodmanRoot: *podmanRoot,
148163
RoStoragePath: *roStorage,
149164
MksquashfsPath: *mksquashfs,
150165
Image: *image,
166+
MksquashfsOpts: opts,
151167
},
152168
Op: map[bool]Operation{true: OpMigrate, false: OpRmi}[*migrateF], // inlined if/else
153169
LogLevel: level,

common/config.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import (
66
)
77

88
type Config struct {
9-
PodmanRoot string
10-
RoStoragePath string
11-
MksquashfsPath string
12-
Image string
9+
PodmanRoot string
10+
RoStoragePath string
11+
MksquashfsPath string
12+
Image string
13+
MksquashfsOpts []string
1314
}
1415

1516
func IsDir(path string) error {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
load helpers.bash
2+
3+
@test "migrate with custom mksquashfs compression level 3" {
4+
run \
5+
"$PODMAN_BINARY" \
6+
--root "$PODMAN_ROOT" \
7+
--runroot "$PODMAN_RUNROOT" \
8+
pull docker.io/library/hello-world:linux
9+
10+
run \
11+
"$PARALLAX_BINARY" \
12+
--podmanRoot "$PODMAN_ROOT" \
13+
--roStoragePath "$RO_STORAGE" \
14+
--mksquashfsPath "$MKSQUASHFS_PATH" \
15+
--mksquashfs-opts "-noappend -comp zstd -Xcompression-level 3 -noD -no-xattrs -e security.capability" \
16+
--log-level info \
17+
--migrate \
18+
--image docker.io/library/hello-world:linux
19+
[ "$status" -eq 0 ]
20+
[[ "$output" =~ "Migration successfully completed" ]]
21+
22+
run \
23+
ls "$RO_STORAGE"/overlay/**/*.squash
24+
[ "$status" -eq 0 ]
25+
26+
# Inspect squashfs metadata
27+
run \
28+
bash -c 'SQUASH_FILE=$(ls "$RO_STORAGE"/overlay/**/*.squash | head -n1) && unsquashfs -s "$SQUASH_FILE"'
29+
[ "$status" -eq 0 ]
30+
[[ "$output" =~ "Compression zstd" ]]
31+
[[ "$output" =~ "level 3" ]]
32+
33+
run \
34+
"$PODMAN_BINARY" \
35+
--root "$CLEAN_ROOT" \
36+
--runroot "$PODMAN_RUNROOT" \
37+
--storage-opt additionalimagestore=$RO_STORAGE \
38+
--storage-opt mount_program=$MOUNT_PROGRAM_PATH \
39+
run --rm --security-opt seccomp=unconfined docker.io/library/hello-world:linux
40+
[ "$status" -eq 0 ]
41+
[[ "$output" =~ "Hello from Docker!" ]]
42+
43+
run \
44+
"$PARALLAX_BINARY" \
45+
--podmanRoot "$CLEAN_ROOT" \
46+
--roStoragePath "$RO_STORAGE" \
47+
--mksquashfsPath "$MKSQUASHFS_PATH" \
48+
--log-level info \
49+
--rmi \
50+
--image docker.io/library/hello-world:linux
51+
}

0 commit comments

Comments
 (0)