()
| 41 | } |
| 42 | |
| 43 | func buildCmd() *cobra.Command { |
| 44 | |
| 45 | var ( |
| 46 | name string |
| 47 | dir string |
| 48 | outputFile string |
| 49 | sizeString string |
| 50 | pull bool |
| 51 | docker bool |
| 52 | decompressKernel bool |
| 53 | arch string |
| 54 | cacheDir flagOverEnvVarOverDefaultString |
| 55 | buildFormats formatList |
| 56 | outputTypes = mobybuild.OutputTypes() |
| 57 | noSbom bool |
| 58 | sbomOutputFilename string |
| 59 | inputTar string |
| 60 | sbomCurrentTime bool |
| 61 | dryRun bool |
| 62 | ) |
| 63 | cmd := &cobra.Command{ |
| 64 | Use: "build", |
| 65 | Short: "Build a bootable OS image from a yaml configuration file", |
| 66 | Long: `Build a bootable OS image from a yaml configuration file. |
| 67 | |
| 68 | The generated image can be in one of multiple formats which can be run on various platforms. |
| 69 | `, |
| 70 | Example: ` linuxkit build [options] <file>[.yml]`, |
| 71 | Args: cobra.MinimumNArgs(1), |
| 72 | RunE: func(cmd *cobra.Command, args []string) error { |
| 73 | if name == "" && outputFile == "" { |
| 74 | conf := args[len(args)-1] |
| 75 | if conf == "-" { |
| 76 | name = defaultNameForStdin |
| 77 | } else { |
| 78 | name = strings.TrimSuffix(filepath.Base(conf), filepath.Ext(conf)) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // There are two types of output, they will probably be split into "build" and "package" later |
| 83 | // the basic outputs are tarballs, while the packaged ones are the LinuxKit out formats that |
| 84 | // cannot be streamed but we do allow multiple ones to be built. |
| 85 | |
| 86 | if len(buildFormats) == 0 { |
| 87 | if outputFile == "" { |
| 88 | buildFormats = formatList{"kernel+initrd"} |
| 89 | } else { |
| 90 | buildFormats = formatList{"tar"} |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | log.Debugf("Formats selected: %s", buildFormats.String()) |
| 95 | |
| 96 | if len(buildFormats) > 1 { |
| 97 | for _, o := range buildFormats { |
| 98 | if mobybuild.Streamable(o) { |
| 99 | return fmt.Errorf("format type %s must be the only format specified", o) |
| 100 | } |
no test coverage detected