diff --git a/cmd/start.go b/cmd/start.go index eac419e7..77bd4af4 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -163,6 +163,7 @@ func init() { startCmd.Flags().StringVarP(&startCmdArgs.Arch, "arch", "a", defaultArch, "architecture (aarch64, x86_64)") startCmd.Flags().BoolVarP(&startCmdArgs.Flags.Foreground, "foreground", "f", false, "Keep colima in the foreground") startCmd.Flags().StringVar(&startCmdArgs.Hostname, "hostname", "", "custom hostname for the virtual machine") + startCmd.Flags().StringVarP(&startCmdArgs.DiskImage, "disk-image", "i", "", "local path or URL to a custom disk image") // host IP addresses startCmd.Flags().BoolVar(&startCmdArgs.Network.HostAddresses, "network-host-addresses", false, "support port forwarding to specific host IP addresses") diff --git a/config/config.go b/config/config.go index 9c904b38..27ea4c16 100644 --- a/config/config.go +++ b/config/config.go @@ -44,6 +44,7 @@ type Config struct { VMType string `yaml:"vmType,omitempty"` VZRosetta bool `yaml:"rosetta,omitempty"` NestedVirtualization bool `yaml:"nestedVirtualization,omitempty"` + DiskImage string `yaml:"diskImage,omitempty"` // volume mounts Mounts []Mount `yaml:"mounts,omitempty"` diff --git a/embedded/defaults/colima.yaml b/embedded/defaults/colima.yaml index fec14980..56f5c21a 100644 --- a/embedded/defaults/colima.yaml +++ b/embedded/defaults/colima.yaml @@ -197,6 +197,14 @@ sshPort: 0 # Default: [] mounts: [] +# Specify a custom disk image for the virtual machine. +# When not specified, Colima downloads the disk image from Github at +# https://github.com/abiosoft/colima-core/releases. +# A custom disk image (local disk path or URL) can be specified to override the behaviour. +# +# Default: "" +diskImage: "" + # Environment variables for the virtual machine. # # EXAMPLE diff --git a/environment/vm/lima/lima.go b/environment/vm/lima/lima.go index 645113e5..74b0e3e2 100644 --- a/environment/vm/lima/lima.go +++ b/environment/vm/lima/lima.go @@ -274,11 +274,26 @@ func (l limaVM) Arch() environment.Arch { func (l *limaVM) downloadDiskImage(ctx context.Context, conf config.Config) error { log := l.Logger(ctx) + // use a previously cached image if image, ok := limautil.ImageCached(l.limaConf.Arch, conf.Runtime); ok { l.limaConf.Images = []limaconfig.File{image} return nil } + // use a user specified disk image + if conf.DiskImage != "" { + log.Infoln("using specified disk image ...") + image, err := limautil.Image(l.limaConf.Arch, conf.Runtime) + if err != nil { + return fmt.Errorf("error getting disk image details: %w", err) + } + log.Warnf("disk image must be identical to '%s'", image.Location) + image.Location = conf.DiskImage + l.limaConf.Images = []limaconfig.File{image} + return nil + } + + // download image log.Infoln("downloading disk image ...") image, err := limautil.DownloadImage(l.limaConf.Arch, conf.Runtime) if err != nil { diff --git a/environment/vm/lima/limautil/image.go b/environment/vm/lima/limautil/image.go index a877073f..62b80582 100644 --- a/environment/vm/lima/limautil/image.go +++ b/environment/vm/lima/limautil/image.go @@ -53,6 +53,11 @@ func findImage(arch environment.Arch, runtime string) (f limaconfig.File, err er return img, nil } +// Image returns the details of the disk image to download for the arch and runtime. +func Image(arch environment.Arch, runtime string) (limaconfig.File, error) { + return findImage(arch, runtime) +} + // DownloadImage downloads the image for arch and runtime. func DownloadImage(arch environment.Arch, runtime string) (f limaconfig.File, err error) { img, err := findImage(arch, runtime)