diff --git a/cmd/podman/machine/init.go b/cmd/podman/machine/init.go index 88f358d764..3e97a7f942 100644 --- a/cmd/podman/machine/init.go +++ b/cmd/podman/machine/init.go @@ -14,6 +14,7 @@ import ( "github.com/containers/podman/v5/pkg/machine/define" "github.com/containers/podman/v5/pkg/machine/shim" "github.com/containers/podman/v5/pkg/machine/vmconfigs" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -101,9 +102,17 @@ func init() { flags.StringVar(&initOpts.Username, UsernameFlagName, cfg.ContainersConfDefaultsRO.Machine.User, "Username used in image") _ = initCmd.RegisterFlagCompletionFunc(UsernameFlagName, completion.AutocompleteDefault) + ImageFlagName := "image" + flags.StringVar(&initOpts.Image, ImageFlagName, cfg.ContainersConfDefaultsRO.Machine.Image, "Bootable image for machine") + _ = initCmd.RegisterFlagCompletionFunc(ImageFlagName, completion.AutocompleteDefault) + + // Deprecate image-path option, use --image instead ImagePathFlagName := "image-path" - flags.StringVar(&initOpts.ImagePath, ImagePathFlagName, "", "Path to bootable image") + flags.StringVar(&initOpts.Image, ImagePathFlagName, cfg.ContainersConfDefaultsRO.Machine.Image, "Bootable image for machine") _ = initCmd.RegisterFlagCompletionFunc(ImagePathFlagName, completion.AutocompleteDefault) + if err := flags.MarkDeprecated(ImagePathFlagName, "use --image instead"); err != nil { + logrus.Error("unable to mark image-path flag deprecated") + } VolumeFlagName := "volume" flags.StringArrayVarP(&initOpts.Volumes, VolumeFlagName, "v", cfg.ContainersConfDefaultsRO.Machine.Volumes.Get(), "Volumes to mount, source:target") diff --git a/docs/source/markdown/podman-machine-init.1.md.in b/docs/source/markdown/podman-machine-init.1.md.in index 17fde730d7..ae8a1bf639 100644 --- a/docs/source/markdown/podman-machine-init.1.md.in +++ b/docs/source/markdown/podman-machine-init.1.md.in @@ -73,11 +73,10 @@ Fully qualified path of the ignition file. If an ignition file is provided, the file is copied into the user's CONF_DIR and renamed. Additionally, no SSH keys are generated, nor are any system connections made. It is assumed that the user does these things manually or handled otherwise. -#### **--image-path** +#### **--image** -Fully qualified path or URL to the VM image. -Can also be set to `testing`, `next`, or `stable` to pull down default image. -Defaults to `testing`. +Fully qualified registry, path, or URL to a VM image. +Registry target must be in the form of `docker://registry/repo/image:version`. #### **--memory**, **-m**=*number* diff --git a/pkg/machine/define/initopts.go b/pkg/machine/define/initopts.go index 06bbef8520..fcf922958b 100644 --- a/pkg/machine/define/initopts.go +++ b/pkg/machine/define/initopts.go @@ -6,7 +6,7 @@ type InitOptions struct { CPUS uint64 DiskSize uint64 IgnitionPath string - ImagePath string + Image string Volumes []string VolumeDriver string IsDefault bool diff --git a/pkg/machine/e2e/machine_pull_test.go b/pkg/machine/e2e/machine_pull_test.go index c441f91926..8a37e178c5 100644 --- a/pkg/machine/e2e/machine_pull_test.go +++ b/pkg/machine/e2e/machine_pull_test.go @@ -22,7 +22,7 @@ func pullOCITestDisk(finalDir string, vmType define.VMType) error { return err } dirs := define.MachineDirs{ImageCacheDir: imageCacheDir} - ociArtPull, err := ocipull.NewOCIArtifactPull(context.Background(), &dirs, "e2emachine", vmType, unusedFinalPath) + ociArtPull, err := ocipull.NewOCIArtifactPull(context.Background(), &dirs, "", "e2emachine", vmType, unusedFinalPath) if err != nil { return err } diff --git a/pkg/machine/ocipull/ociartifact.go b/pkg/machine/ocipull/ociartifact.go index 2c8604da40..5e17cdf993 100644 --- a/pkg/machine/ocipull/ociartifact.go +++ b/pkg/machine/ocipull/ociartifact.go @@ -25,6 +25,7 @@ import ( const ( // TODO This is temporary until we decide on a proper image name + // Also should be moved into c/common once stabilized artifactRegistry = "quay.io" artifactRepo = "baude" artifactImageName = "stage-podman-machine-image" @@ -71,7 +72,7 @@ type DiskArtifactOpts struct { */ -func NewOCIArtifactPull(ctx context.Context, dirs *define.MachineDirs, vmName string, vmType define.VMType, finalPath *define.VMFile) (*OCIArtifactDisk, error) { +func NewOCIArtifactPull(ctx context.Context, dirs *define.MachineDirs, endpoint string, vmName string, vmType define.VMType, finalPath *define.VMFile) (*OCIArtifactDisk, error) { var ( arch string ) @@ -91,12 +92,17 @@ func NewOCIArtifactPull(ctx context.Context, dirs *define.MachineDirs, vmName st diskType: vmType.String(), os: machineOS, } + + if endpoint == "" { + endpoint = fmt.Sprintf("docker://%s/%s/%s:%s", artifactRegistry, artifactRepo, artifactImageName, artifactVersion.majorMinor()) + } + ociDisk := OCIArtifactDisk{ ctx: ctx, dirs: dirs, diskArtifactOpts: &diskOpts, finalPath: finalPath.GetPath(), - imageEndpoint: fmt.Sprintf("docker://%s/%s/%s:%s", artifactRegistry, artifactRepo, artifactImageName, artifactVersion.majorMinor()), + imageEndpoint: endpoint, machineVersion: artifactVersion, name: vmName, pullOptions: &PullOptions{}, diff --git a/pkg/machine/shim/diskpull/diskpull.go b/pkg/machine/shim/diskpull/diskpull.go index ce768ad593..49e9ff09e1 100644 --- a/pkg/machine/shim/diskpull/diskpull.go +++ b/pkg/machine/shim/diskpull/diskpull.go @@ -15,8 +15,8 @@ func GetDisk(userInputPath string, dirs *define.MachineDirs, imagePath *define.V mydisk ocipull.Disker ) - if userInputPath == "" { - mydisk, err = ocipull.NewOCIArtifactPull(context.Background(), dirs, name, vmType, imagePath) + if userInputPath == "" || strings.HasPrefix(userInputPath, "docker://") { + mydisk, err = ocipull.NewOCIArtifactPull(context.Background(), dirs, userInputPath, name, vmType, imagePath) } else { if strings.HasPrefix(userInputPath, "http") { // TODO probably should use tempdir instead of datadir diff --git a/pkg/machine/shim/host.go b/pkg/machine/shim/host.go index 133ec91242..f69bd8cbeb 100644 --- a/pkg/machine/shim/host.go +++ b/pkg/machine/shim/host.go @@ -140,7 +140,7 @@ func Init(opts machineDefine.InitOptions, mp vmconfigs.VMProvider) (*vmconfigs.M // "/path // "docker://quay.io/something/someManifest - if err := mp.GetDisk(opts.ImagePath, dirs, mc); err != nil { + if err := mp.GetDisk(opts.Image, dirs, mc); err != nil { return nil, err } diff --git a/pkg/machine/wsl/stubber.go b/pkg/machine/wsl/stubber.go index fdb07ad18e..c28db07842 100644 --- a/pkg/machine/wsl/stubber.go +++ b/pkg/machine/wsl/stubber.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/containers/podman/v5/pkg/machine/ocipull" + "github.com/containers/podman/v5/pkg/machine/shim/diskpull" "github.com/containers/podman/v5/pkg/machine/stdpull" "github.com/containers/podman/v5/pkg/machine/wsl/wutil" @@ -281,11 +282,15 @@ func (w WSLStubber) VMType() define.VMType { return define.WSLVirt } -func (w WSLStubber) GetDisk(_ string, dirs *define.MachineDirs, mc *vmconfigs.MachineConfig) error { +func (w WSLStubber) GetDisk(userInputPath string, dirs *define.MachineDirs, mc *vmconfigs.MachineConfig) error { var ( myDisk ocipull.Disker ) + if userInputPath != "" { + return diskpull.GetDisk(userInputPath, dirs, mc.ImagePath, w.VMType(), mc.Name) + } + // check github for the latest version of the WSL dist downloadURL, downloadVersion, _, _, err := GetFedoraDownloadForWSL() if err != nil {