Skip to content

Commit 6704de1

Browse files
oci-export fix and root&mount fs methods
1 parent 9e11f09 commit 6704de1

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

main.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ func main() {
2626
log.Err(err).Msg("Error while running parserCli.ParseYamlFile()")
2727
}
2828

29-
err = buildCLient.BuildExportDockerImage(result.Context, result.DockerfilePath, result.TargetDirectory)
29+
err = rootFsClient.CreateFileDD(10, "ops")
3030
if err != nil {
31-
log.Err(err).Msg("Error while running buildCLient.BuildExportDockerImage()")
31+
log.Err(err).Msg("Error while running rootFsClient.CreateFileDD()")
3232
}
3333

34-
err = rootFsClient.CreateFileDD(10, "ops")
34+
fsErr := rootFsClient.FormatandMountFileSystem("ops", result.TargetDirectory)
35+
if fsErr != nil {
36+
log.Err(fsErr).Msg("Error while running rootFsClient.FormatFileSystem()")
37+
}
38+
39+
err = buildCLient.BuildExportDockerImage(result.Context, result.DockerfilePath, result.TargetDirectory)
3540
if err != nil {
36-
log.Err(err).Msg("Error while running rootFsClient.CreateFileDD()")
41+
log.Err(err).Msg("Error while running buildCLient.BuildExportDockerImage()")
3742
}
38-
// Extract rootfs components now
3943

4044
}

src/rootfs.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,43 @@
11
package src
22

33
import (
4+
"fmt"
45
"os"
6+
"os/exec"
57

68
"github.com/rs/zerolog/log"
79
)
810

911
type RootFS interface {
1012
CreateFileDD(size int64, fileName string) error
13+
FormatandMountFileSystem(path, targetDirectory string) error
1114
}
1215

1316
type RootFSHandler struct{}
1417

18+
func (rootfs *RootFSHandler) FormatandMountFileSystem(path, targetDirectory string) error {
19+
cmd := exec.Command("mkfs.ext4", path)
20+
output, err := cmd.CombinedOutput()
21+
if err != nil {
22+
log.Err(err).Msg("Error running mkfs.ext4:")
23+
log.Info().Msgf("Output: %s", string(output))
24+
return err
25+
}
26+
27+
log.Info().Msgf("Output: %s", string(output))
28+
29+
cmd = exec.Command(fmt.Sprintf("mount", path, targetDirectory))
30+
output, err = cmd.CombinedOutput()
31+
if err != nil {
32+
log.Err(err).Msg("Error running mount")
33+
log.Info().Msgf("Mount exec output: %s", string(output))
34+
return err
35+
}
36+
37+
log.Info().Msgf("Mount exec output: %s", string(output))
38+
return nil
39+
}
40+
1541
func (rootfs *RootFSHandler) CreateFileDD(size int64, fileName string) error {
1642

1743
size = int64(size * 1024 * 1024) // in MiB files

0 commit comments

Comments
 (0)