|
1 | 1 | package main |
2 | 2 |
|
3 | | -import "fmt" |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + |
| 6 | + src "github.com/WoodProgrammer/firecracker-vmbuilder/src" |
| 7 | + "github.com/rs/zerolog/log" |
| 8 | + "github.com/spf13/cobra" |
| 9 | +) |
| 10 | + |
| 11 | +var ( |
| 12 | + configFile string |
| 13 | +) |
| 14 | + |
| 15 | +func newBuildClient() src.Builder { |
| 16 | + return &src.BuildHandler{} |
| 17 | +} |
| 18 | + |
| 19 | +func newParserClient() src.Parser { |
| 20 | + return &src.ParseHandler{} |
| 21 | +} |
| 22 | + |
| 23 | +func newRootFSClient() src.RootFS { |
| 24 | + return &src.RootFSHandler{} |
| 25 | +} |
| 26 | + |
| 27 | +func HandleRootFS() { |
| 28 | + parserClient := newParserClient() |
| 29 | + buildCLient := newBuildClient() |
| 30 | + rootFsClient := newRootFSClient() |
| 31 | + |
| 32 | + result, err := parserClient.ParseYamlFile(configFile) |
| 33 | + if err != nil { |
| 34 | + log.Err(err).Msg("Error while running parserCli.ParseYamlFile()") |
| 35 | + } |
| 36 | + |
| 37 | + err = rootFsClient.CreateFileDD(10, "ops") |
| 38 | + if err != nil { |
| 39 | + log.Err(err).Msg("Error while running rootFsClient.CreateFileDD()") |
| 40 | + } |
| 41 | + |
| 42 | + fsErr := rootFsClient.FormatandMountFileSystem("ops", result.TargetDirectory) |
| 43 | + if fsErr != nil { |
| 44 | + log.Err(fsErr).Msg("Error while running rootFsClient.FormatFileSystem()") |
| 45 | + } |
| 46 | + |
| 47 | + err = buildCLient.BuildExportDockerImage(result.Context, result.DockerfilePath, result.TargetDirectory) |
| 48 | + if err != nil { |
| 49 | + log.Err(err).Msg("Error while running buildCLient.BuildExportDockerImage()") |
| 50 | + } |
| 51 | + |
| 52 | +} |
4 | 53 |
|
5 | 54 | func main() { |
6 | | - fmt.Println("This is firecracker vmbuilder 0.0.1") |
| 55 | + var rootCmd = &cobra.Command{ |
| 56 | + Use: "rootfsCreator", |
| 57 | + Short: "CLI tool to manage RootFS for firecracker micro VMs", |
| 58 | + Run: func(cmd *cobra.Command, args []string) { |
| 59 | + HandleRootFS() |
| 60 | + }, |
| 61 | + } |
| 62 | + rootCmd.Flags().StringVarP(&configFile, "config", "C", "config.yaml", "Config file of RootFS creation") |
| 63 | + |
| 64 | + rootCmd.MarkFlagRequired("config") |
| 65 | + |
| 66 | + if err := rootCmd.Execute(); err != nil { |
| 67 | + log.Err(err).Msg("rootfsCreator execution failed") |
| 68 | + os.Exit(1) |
| 69 | + } |
7 | 70 | } |
0 commit comments