mirror of https://github.com/containers/podman.git
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:
parent
41fa1c2c5c
commit
527b3793b8
|
@ -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")
|
||||
|
|
|
@ -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*
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ type InitOptions struct {
|
|||
CPUS uint64
|
||||
DiskSize uint64
|
||||
IgnitionPath string
|
||||
ImagePath string
|
||||
Image string
|
||||
Volumes []string
|
||||
VolumeDriver string
|
||||
IsDefault bool
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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{},
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue