tree

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AMICmd = &cobra.Command{
		Use:   "ami",
		Short: "Convert a container image to an EC2 AMI",
		PreRunE: func(cmd *cobra.Command, args []string) error {
			cmd.SilenceUsage = true

			assetDir, err := expandPath(amiCfg.assetDir)
			if err != nil {
				return fmt.Errorf("failed to expand asset directory path: %w", err)
			}
			if _, err = os.Stat(assetDir); os.IsNotExist(err) {
				return fmt.Errorf("asset directory does not exist: %s", assetDir)
			}
			amiCfg.assetDir = assetDir

			packerDir, err := expandPath(amiCfg.packerDir)
			if err != nil {
				return fmt.Errorf("failed to expand packer directory path: %w", err)
			}
			if _, err = os.Stat(packerDir); os.IsNotExist(err) {
				return fmt.Errorf("packer directory does not exist: %s", packerDir)
			}
			amiCfg.packerDir = packerDir

			svcErr := validateServices(amiCfg.services)
			sshErr := validateSSHInterface(amiCfg.sshInterface)
			return errors.Join(svcErr, sshErr)
		},
		RunE: func(cmd *cobra.Command, args []string) error {
			quotedServices := bytes.NewBufferString("")
			err := json.NewEncoder(quotedServices).Encode(amiCfg.services)
			if err != nil {

				return fmt.Errorf("unexpected value for services: %w", err)
			}

			packerArgs := []string{
				"build",
				"-var", fmt.Sprintf("ami_name=%s", amiCfg.amiName),
				"-var", fmt.Sprintf("asset_dir=%s", amiCfg.assetDir),
				"-var", fmt.Sprintf("container_image=%s", amiCfg.containerImage),
				"-var", fmt.Sprintf("debug=%t", amiCfg.debug),
				"-var", fmt.Sprintf("login_user=%s", amiCfg.loginUser),
				"-var", fmt.Sprintf("login_shell=%s", amiCfg.loginShell),
				"-var", fmt.Sprintf("root_device_name=%s", amiCfg.rootDeviceName),
				"-var", fmt.Sprintf("root_vol_size=%d", amiCfg.size),
				"-var", fmt.Sprintf("services=%s", quotedServices.String()),
				"-var", fmt.Sprintf("ssh_interface=%s", amiCfg.sshInterface),
				"-var", fmt.Sprintf("subnet_id=%s", amiCfg.subnetID),
				"build.pkr.hcl",
			}

			packer := exec.Command("./packer", packerArgs...)

			packer.Stdin = os.Stdin
			packer.Stdout = os.Stdout
			packer.Stderr = os.Stderr

			packer.Dir = amiCfg.packerDir

			packer.Env = append(os.Environ(), []string{
				"CHECKPOINT_DISABLE=1",
				fmt.Sprintf("PACKER_PLUGIN_PATH=%s/plugins", amiCfg.packerDir),
			}...)

			if amiCfg.debug {
				fmt.Printf("%+v\n", packer)
			}

			cmd.SilenceUsage = true

			return packer.Run()
		},
	}
)
View Source
var (
	RootCmd = &cobra.Command{
		Use:   "easyto",
		Short: "A container image conversion tool",
	}
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL