Files
enki/cmd/dockerfile.go
Dimitris Karakasilis e32a662eb4 Let the user pass the framework image to use
Let's keep things simple for now. Trying to figure out the right
framework image automatically will be very error prone. By making it a
manual setting, we allow the user to even set it to a custom image or
use one that they know it works.

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
2023-10-05 12:36:29 +03:00

65 lines
1.9 KiB
Go

package cmd
import (
"fmt"
"github.com/kairos-io/enki/pkg/action"
"github.com/spf13/cobra"
)
// NewDockerfilCmd generates a dockerfile which can be used to build a kairos
// image out of the provided one.
func NewDockerfileCmd() *cobra.Command {
c := &cobra.Command{
Use: "dockerfile",
Short: "Create a dockerfile that builds a Kairos image from the provided one",
Long: "Create a dockerfile that builds a Kairos image from the provided one\n\n" +
"The base image can be specified either as a directory where the image has been extracted or as an image uri.\n" +
"This is best effort. Enki will try to detect the distribution and add the necessary bits to convert it to a Kairos image",
PreRunE: func(cmd *cobra.Command, args []string) error {
//return CheckRoot() // TODO: Do we need root?
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
// Set this after parsing of the flags, so it fails on parsing and prints usage properly
cmd.SilenceUsage = true
cmd.SilenceErrors = true // Do not propagate errors down the line, we control them
rootfsDir, err := cmd.Flags().GetString("rootfs-dir")
if err != nil {
return err
}
baseImageURI, err := cmd.Flags().GetString("base-image-uri")
if err != nil {
return err
}
frameworkImage, err := cmd.Flags().GetString("framework-image")
if err != nil {
return err
}
a := action.NewDockerfileAction(rootfsDir, baseImageURI, frameworkImage)
dockerfile, err := a.Run()
if err != nil {
return err
}
fmt.Println(dockerfile)
return nil
},
}
return c
}
func init() {
c := NewDockerfileCmd()
rootCmd.AddCommand(c)
c.Flags().StringP("rootfs-dir", "r", "", "the directory containing the extracted base image rootfs")
c.Flags().StringP("base-image-uri", "i", "", "the URI of the base image")
c.Flags().StringP("framework-image", "i", "", "the URI of the base image")
}