Use machine image as specified in containers.conf

For podman machine init, deprecate the --image-path option for --image.
--image now accepts the correct image from containers.conf

Also, add the ability to specify an OCI image from the --image flag using the docker:// transport.

Signed-off-by: Ashley Cui <acui@redhat.com>
This commit is contained in:
Ashley Cui 2024-02-28 00:57:15 -05:00
parent 41fa1c2c5c
commit 527b3793b8
8 changed files with 32 additions and 13 deletions

View File

@ -14,6 +14,7 @@ import (
"github.com/containers/podman/v5/pkg/machine/define" "github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/shim" "github.com/containers/podman/v5/pkg/machine/shim"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -101,9 +102,17 @@ func init() {
flags.StringVar(&initOpts.Username, UsernameFlagName, cfg.ContainersConfDefaultsRO.Machine.User, "Username used in image") flags.StringVar(&initOpts.Username, UsernameFlagName, cfg.ContainersConfDefaultsRO.Machine.User, "Username used in image")
_ = initCmd.RegisterFlagCompletionFunc(UsernameFlagName, completion.AutocompleteDefault) _ = 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" 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) _ = 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" VolumeFlagName := "volume"
flags.StringArrayVarP(&initOpts.Volumes, VolumeFlagName, "v", cfg.ContainersConfDefaultsRO.Machine.Volumes.Get(), "Volumes to mount, source:target") flags.StringArrayVarP(&initOpts.Volumes, VolumeFlagName, "v", cfg.ContainersConfDefaultsRO.Machine.Volumes.Get(), "Volumes to mount, source:target")

View File

@ -73,11 +73,10 @@ Fully qualified path of the ignition file.
If an ignition file is provided, the 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. 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. Fully qualified registry, path, or URL to a VM image.
Can also be set to `testing`, `next`, or `stable` to pull down default image. Registry target must be in the form of `docker://registry/repo/image:version`.
Defaults to `testing`.
#### **--memory**, **-m**=*number* #### **--memory**, **-m**=*number*

View File

@ -6,7 +6,7 @@ type InitOptions struct {
CPUS uint64 CPUS uint64
DiskSize uint64 DiskSize uint64
IgnitionPath string IgnitionPath string
ImagePath string Image string
Volumes []string Volumes []string
VolumeDriver string VolumeDriver string
IsDefault bool IsDefault bool

View File

@ -22,7 +22,7 @@ func pullOCITestDisk(finalDir string, vmType define.VMType) error {
return err return err
} }
dirs := define.MachineDirs{ImageCacheDir: imageCacheDir} 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 { if err != nil {
return err return err
} }

View File

@ -25,6 +25,7 @@ import (
const ( const (
// TODO This is temporary until we decide on a proper image name // TODO This is temporary until we decide on a proper image name
// Also should be moved into c/common once stabilized
artifactRegistry = "quay.io" artifactRegistry = "quay.io"
artifactRepo = "baude" artifactRepo = "baude"
artifactImageName = "stage-podman-machine-image" 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 ( var (
arch string arch string
) )
@ -91,12 +92,17 @@ func NewOCIArtifactPull(ctx context.Context, dirs *define.MachineDirs, vmName st
diskType: vmType.String(), diskType: vmType.String(),
os: machineOS, os: machineOS,
} }
if endpoint == "" {
endpoint = fmt.Sprintf("docker://%s/%s/%s:%s", artifactRegistry, artifactRepo, artifactImageName, artifactVersion.majorMinor())
}
ociDisk := OCIArtifactDisk{ ociDisk := OCIArtifactDisk{
ctx: ctx, ctx: ctx,
dirs: dirs, dirs: dirs,
diskArtifactOpts: &diskOpts, diskArtifactOpts: &diskOpts,
finalPath: finalPath.GetPath(), finalPath: finalPath.GetPath(),
imageEndpoint: fmt.Sprintf("docker://%s/%s/%s:%s", artifactRegistry, artifactRepo, artifactImageName, artifactVersion.majorMinor()), imageEndpoint: endpoint,
machineVersion: artifactVersion, machineVersion: artifactVersion,
name: vmName, name: vmName,
pullOptions: &PullOptions{}, pullOptions: &PullOptions{},

View File

@ -15,8 +15,8 @@ func GetDisk(userInputPath string, dirs *define.MachineDirs, imagePath *define.V
mydisk ocipull.Disker mydisk ocipull.Disker
) )
if userInputPath == "" { if userInputPath == "" || strings.HasPrefix(userInputPath, "docker://") {
mydisk, err = ocipull.NewOCIArtifactPull(context.Background(), dirs, name, vmType, imagePath) mydisk, err = ocipull.NewOCIArtifactPull(context.Background(), dirs, userInputPath, name, vmType, imagePath)
} else { } else {
if strings.HasPrefix(userInputPath, "http") { if strings.HasPrefix(userInputPath, "http") {
// TODO probably should use tempdir instead of datadir // TODO probably should use tempdir instead of datadir

View File

@ -140,7 +140,7 @@ func Init(opts machineDefine.InitOptions, mp vmconfigs.VMProvider) (*vmconfigs.M
// "/path // "/path
// "docker://quay.io/something/someManifest // "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 return nil, err
} }

View File

@ -11,6 +11,7 @@ import (
"strings" "strings"
"github.com/containers/podman/v5/pkg/machine/ocipull" "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/stdpull"
"github.com/containers/podman/v5/pkg/machine/wsl/wutil" "github.com/containers/podman/v5/pkg/machine/wsl/wutil"
@ -281,11 +282,15 @@ func (w WSLStubber) VMType() define.VMType {
return define.WSLVirt 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 ( var (
myDisk ocipull.Disker 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 // check github for the latest version of the WSL dist
downloadURL, downloadVersion, _, _, err := GetFedoraDownloadForWSL() downloadURL, downloadVersion, _, _, err := GetFedoraDownloadForWSL()
if err != nil { if err != nil {