mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
refactor(backend): base's size as Go constants, base's disk in Lima's origin
Base's size was read from assets/base.yaml four ways: vm.BaseDisk's
line scanner (a new VM's smallest disk), SizeChoice.Fitted's same scanner
for CPUs and memory (devvm size -g and setup's question), Lima's
buildSize regexes (base's build size), and limactl create reading disk:
from the template on its input. Now backend.BaseCPUs, BaseMemoryGiB and
BaseDiskGiB are the one source:
- vm checks new VMs' disks against backend.BaseDiskGiB, and Fitted fits
BaseCPUs and BaseMemoryGiB; SizeChoice has no Assets any more.
- Lima's buildSize uses the constants; its Origin carries base's disk as
a step of its own ("disk", its GiB), which originOf requires and
createArgs passes as --disk=, so base's key still hashes it, and the
--from conversion's VM gets it too.
- base.yaml sets no cpus, memory or disk, and is hashed only into Lima's
key as Lima's settings.
Tests: TestBuildImageBaseSize (pinned on the old code: base created with
4 CPUs, 8 GiB and a 100 GiB disk, now all flags and none in base.yaml),
TestBaseSize, TestOriginOfRefuses' no disk and bad disk; the limactl stub
reads create's --disk=. Docs: internals/images.md, internals/lima.md,
contributing.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
22 files changed
+149
-134
No files matched your search
+1
-3
@@ -7,9 +7,7 @@
|
||||
# don't make systemd-networkd-wait-online wait for it.
|
||||
param:
|
||||
internal_netplanOptional: "true"
|
||||
cpus: 4
|
||||
memory: 8GiB
|
||||
disk: 100GiB
|
||||
# No cpus, memory or disk here: devvm gives base its size on limactl create's command line.
|
||||
containerd:
|
||||
system: false
|
||||
user: false
|
||||
@@ -180,7 +180,7 @@ devvm runs every VM on Lima, but the rest of devvm reaches Lima only through the
|
||||
|
||||
- **It implements `backend.Backend`** and returns errors as messages, as [AGENTS.md](https://github.com/w3cj/devvm/blob/main/AGENTS.md#backends) says, instead of ending the run. `Backend` is the backend's `Name` and `Caps` and four roles, each an interface of its own that every backend implements in full:
|
||||
- `backend.Host` is what the backend needs of this machine and where it keeps its VMs there. `Problems` lists what the host lacks for it, and `backend.Check(ctx, b)` returns the first of them, so a backend doesn't write a check of its own. `NameMax` is the longest VM name it takes, `Location` is where its VMs live when that can change between runs (`backend.LocationOf`), and `DiskDirs` and `Floors` are the folders its disks are in and the free space it wants there (`backend.Space`). A backend whose VMs can't move returns `""` from `Location`, and one whose disks aren't on this machine returns no `DiskDirs`.
|
||||
- `backend.Images` builds images and the shared tools' images and keeps the images. `BuildImage` runs the spec's `Recipe` (`image.Recipe`, which `internal/build` puts together and `image.Input` hashes) as it is, each `image.Step` with its arguments and as root when it says so. `Origin` is the backend's own steps that base starts with, such as the Ubuntu image Lima pinned on this machine, a `--from` image's conversion and `base.yaml`. `internal/build` puts them first in base's recipe, as its `Origin`, so base's key hashes them, and `BuildImage` is given them back and runs those rather than reading its own files again. `PinOrigin` pins what base starts from on this machine, which `internal/build` asks for before it keys a build (`backend.PinFirst`): on Lima, that's the newest Ubuntu cloud image (`state.UbuntuPin`, found by `ubuntu.Finder`). A base build's `ImageSpec.Packages` sends its packages into the VM's `backend.PackagesDir` before the steps and takes them out after, which `internal/build/packages.go` records or replays and checks, and a step that exits `backend.ExitUnreachable` fails as `build_sources_unreachable`.
|
||||
- `backend.Images` builds images and the shared tools' images and keeps the images. `BuildImage` runs the spec's `Recipe` (`image.Recipe`, which `internal/build` puts together and `image.Input` hashes) as it is, each `image.Step` with its arguments and as root when it says so. `Origin` is the backend's own steps that base starts with, such as the Ubuntu image Lima pinned on this machine, a `--from` image's conversion, base's disk size (`backend.BaseDiskGiB`) and `base.yaml`. Base's size is `backend.BaseCPUs`, `backend.BaseMemoryGiB` and `backend.BaseDiskGiB`, never read from a backend's files. `internal/build` puts them first in base's recipe, as its `Origin`, so base's key hashes them, and `BuildImage` is given them back and runs those rather than reading its own files again. `PinOrigin` pins what base starts from on this machine, which `internal/build` asks for before it keys a build (`backend.PinFirst`): on Lima, that's the newest Ubuntu cloud image (`state.UbuntuPin`, found by `ubuntu.Finder`). A base build's `ImageSpec.Packages` sends its packages into the VM's `backend.PackagesDir` before the steps and takes them out after, which `internal/build/packages.go` records or replays and checks, and a step that exits `backend.ExitUnreachable` fails as `build_sources_unreachable`.
|
||||
- `backend.Machines` makes, starts, stops, renames and deletes VMs, lists them, and runs commands and shells in them. `Running` says how a VM runs now, in one `backend.Run`: the ID of its current start, whether it's confined to its proxy, and its lifeline, the file that the VM's proxy and port forwarder follow. The backend runs no port forwarder of its own, and `SSH` says how ssh, links and devvm's forwarder (`vmssh.Forwards`) reach a running VM's sshd, a target that `vmssh.FromTarget` checks.
|
||||
- `backend.Housekeeping` is what devvm space and devvm gc ask: `Usage`, `Strays`, and `DevvmCache` and `DeleteCache` for its own caches. A backend that can't tell returns none.
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ devvm builds each image in a VM of its own, and that VM then is the image:
|
||||
|
||||
While the VM is being built, it already has the image's final name, so devvm holds a lock for each image it builds, `~/.local/share/devvm/images/locks/<key>`, from before it looks for the image until the record is written. Another devvm that builds the same image waits for that lock and says so (`image_build_waiting`) after 3 seconds, and once it gets the lock, it finds the image built. An image without a record is unfinished only when its lock is free, so devvm then deletes it and builds it again (`image_leftover`). While the lock is held, the image is `building`, and `devvm gc`, `devvm rebuild` and `devvm images rm` leave it alone (`image_building`). The lock is an OS lock on an open file, which the system releases when its devvm ends, however it ends, so a crash never leaves an image looking like it's still being built. devvm deletes the lock file together with the image's folder.
|
||||
|
||||
Nothing from the host is mounted into a build, because layer scripts run third-party installers, which mustn't see your files. Behind a company proxy, a build on Lima goes through a proxy of devvm's on this machine for that build alone, which goes through the company proxy. The scripts' commands get only that proxy's address, with a password devvm makes for the build, so neither the build nor its image ever has the company proxy's password ([a company proxy](design.md#a-company-proxy)). base gets `base.yaml`'s CPUs, or as many as the host has when it has fewer. It gets `base.yaml`'s memory, or half the host's memory when `base.yaml`'s would leave the host less than 2 GiB. The images built on base, and their VMs, keep that size ([base's size](#bases-size)).
|
||||
Nothing from the host is mounted into a build, because layer scripts run third-party installers, which mustn't see your files. Behind a company proxy, a build on Lima goes through a proxy of devvm's on this machine for that build alone, which goes through the company proxy. The scripts' commands get only that proxy's address, with a password devvm makes for the build, so neither the build nor its image ever has the company proxy's password ([a company proxy](design.md#a-company-proxy)). base gets its 4 CPUs, or as many as the host has when it has fewer. It gets its 8 GiB of memory, or half the host's memory when 8 GiB would leave the host less than 2 GiB. The images built on base, and their VMs, keep that size ([base's size](#bases-size)).
|
||||
|
||||
## Keys and caching
|
||||
|
||||
@@ -24,11 +24,11 @@ devvm builds images in layers and caches them, as Docker does. `base` comes firs
|
||||
|
||||
| Image | Its key hashes |
|
||||
| --- | --- |
|
||||
| `base` | the backend, `assets/base.yaml`, `assets/layers/apt.sh`, `assets/layers/base.sh`, the chosen features that have a script, in order (each name and its script), its rebuild counter, and with `--from`, the image, its digest and the scripts that convert it; on Lima, the Ubuntu cloud image pinned on this machine (its release, file and SHA-256), and the user that a `--from` conversion puts in the image (its name, uid and home folder) with the converted disk's size |
|
||||
| `base` | the backend, `assets/base.yaml`, `assets/layers/apt.sh`, `assets/layers/base.sh`, the chosen features that have a script, in order (each name and its script), its rebuild counter, and with `--from`, the image, its digest and the scripts that convert it; on Lima, the Ubuntu cloud image pinned on this machine (its release, file and SHA-256), base's disk size, and the user that a `--from` conversion puts in the image (its name, uid and home folder) with the converted disk's size |
|
||||
| a built-in layer | its parent's key, its name, `assets/layers/apt.sh`, its script (`assets/layers/<name>.sh`) and its rebuild counter |
|
||||
| a custom layer | its parent's key, its name, `assets/layers/apt.sh`, its script (`~/.config/devvm/layers/<name>.sh`) and its rebuild counter |
|
||||
|
||||
devvm puts together each image's recipe once, as the ordered list of steps its build runs. A step is a script with its name, its arguments and whether it runs as root. The recipe of `base` starts with the backend's own steps, which say what the backend makes `base`'s disk from. On Lima, those are the Ubuntu cloud image pinned on this machine and `base.yaml`, and with `--from`, the conversion's scripts too, `build.sh` with its arguments. Then come `apt.sh begin`, `base.sh`, the chosen features' scripts and `apt.sh end`, while a layer's recipe is `apt.sh lists` and then its own script. The key hashes that recipe, and the backend is given the same recipe and runs it as it is, so nothing reaches a build that its key doesn't hold, apart from base's packages: those are the ones its key recorded at its first build, or the mirror to record them from, which [base's packages](#bases-packages) describes. A chosen feature without a script isn't in the recipe, and devvm warns about it (`unknown_feature`) when it builds `base`. The user's CAs and a company proxy's variables are added to each step while it runs and taken out again, so they aren't in the recipe, and the image keeps none of them. A build's CPUs and memory aren't in it either, because the host's size doesn't change what an image holds ([base's size](#bases-size)).
|
||||
devvm puts together each image's recipe once, as the ordered list of steps its build runs. A step is a script with its name, its arguments and whether it runs as root. The recipe of `base` starts with the backend's own steps, which say what the backend makes `base`'s disk from. On Lima, those are the Ubuntu cloud image pinned on this machine, base's disk size and `base.yaml`, and with `--from`, the conversion's scripts too, `build.sh` with its arguments. Then come `apt.sh begin`, `base.sh`, the chosen features' scripts and `apt.sh end`, while a layer's recipe is `apt.sh lists` and then its own script. The key hashes that recipe, and the backend is given the same recipe and runs it as it is, so nothing reaches a build that its key doesn't hold, apart from base's packages: those are the ones its key recorded at its first build, or the mirror to record them from, which [base's packages](#bases-packages) describes. A chosen feature without a script isn't in the recipe, and devvm warns about it (`unknown_feature`) when it builds `base`. The user's CAs and a company proxy's variables are added to each step while it runs and taken out again, so they aren't in the recipe, and the image keeps none of them. A build's CPUs and memory aren't in it either, because the host's size doesn't change what an image holds, but base's disk size is, because the disk is part of the image ([base's size](#bases-size)).
|
||||
|
||||
A key is the first 12 hex digits of a SHA-256. Each input goes into the hash with its length, so different inputs never hash the same bytes. An image's record keeps its chain, which is the key of each image it's built on, from `base` up.
|
||||
|
||||
@@ -80,7 +80,7 @@ The pin is part of base's recipe, so base's key hashes the release, the file and
|
||||
|
||||
## Base's settings and pins
|
||||
|
||||
`assets/base.yaml` holds base's VM settings, which are 4 CPUs, 8 GiB of memory and a 100 GiB disk, and devvm fits the CPUs and memory to the host ([base's size](#bases-size)). `assets/layers/base.sh` installs base, and the optional [features](../using/customizing.md) you chose follow it.
|
||||
Base's size is 4 CPUs, 8 GiB of memory and a 100 GiB disk, which devvm sets in its own code, and it fits the CPUs and memory to the host ([base's size](#bases-size)). On Lima, `assets/base.yaml` holds base's other VM settings. `assets/layers/base.sh` installs base, and the optional [features](../using/customizing.md) you chose follow it.
|
||||
|
||||
Each download in `assets/layers/base.sh` is pinned to a version and a SHA-256 at the top of the script, and the build fails if a checksum doesn't match. Each feature pins its downloads in the same way, at the top of its script, `assets/features/<name>.sh` in the repo, which is built into devvm. apt's packages are pinned per image key, as [base's packages](#bases-packages) describes.
|
||||
|
||||
@@ -102,9 +102,9 @@ A key's set is written once, and the cache holds each file under its own SHA-256
|
||||
|
||||
## Base's size
|
||||
|
||||
devvm fits base's CPUs and memory to the host with one rule that every backend uses. Base gets `base.yaml`'s 4 CPUs, or the host's count when the host has fewer, because a Lima `vz` VM given more CPUs than the Mac has can start so slowly that its ssh never comes up, as [Lima's issue](https://github.com/lima-vm/lima/issues/1621) reports. Base gets `base.yaml`'s 8 GiB of memory, or half the host's whole GiB when 8 GiB would leave the host less than 2 GiB, because a VM asking for all of the host's memory doesn't start.
|
||||
devvm fits base's CPUs and memory to the host with one rule that every backend uses. Base gets its 4 CPUs, or the host's count when the host has fewer, because a Lima `vz` VM given more CPUs than the Mac has can start so slowly that its ssh never comes up, as [Lima's issue](https://github.com/lima-vm/lima/issues/1621) reports. Base gets its 8 GiB of memory, or half the host's whole GiB when 8 GiB would leave the host less than 2 GiB, because a VM asking for all of the host's memory doesn't start.
|
||||
|
||||
- **Lima** passes the fitted size to `limactl create` as `--cpus` and `--memory`, for base and for the VM that converts a `--from` image. The images built on base are clones of it, so they and their VMs keep that size.
|
||||
- **Lima** passes the fitted size to `limactl create` as `--cpus` and `--memory`, and base's 100 GiB disk as `--disk`, for base and for the VM that converts a `--from` image. The images built on base are clones of it, so they and their VMs keep that size. A new VM's disk is never smaller than base's, because disks can't shrink.
|
||||
|
||||
A size you set with `--cpus`, `--memory` or `devvm size -g` replaces the fitted one. devvm checks that size against the same rule, so it refuses more memory than the host's whole GiB less 2, or half of them on a host of 4 GiB or less, and the fitted memory always passes ([size](../using/ports-size.md#size-and-ports)). The fitted size isn't in image keys, because the host's size doesn't change what an image holds.
|
||||
|
||||
@@ -128,11 +128,11 @@ The daemon doesn't read `/etc/environment`, so the [VM's setup](network.md#the-v
|
||||
|
||||
## How it's converted
|
||||
|
||||
With `--from`, devvm turns the container image into a disk in a throwaway VM, `devvm-oci-build`, which it makes from Ubuntu's cloud image with `base.yaml`'s settings. No Docker is needed:
|
||||
With `--from`, devvm turns the container image into a disk in a throwaway VM, `devvm-oci-build`, which it makes from Ubuntu's cloud image with `base.yaml`'s settings and base's size. No Docker is needed:
|
||||
|
||||
1. [crane](https://github.com/google/go-containerregistry/tree/main/cmd/crane) downloads exactly the [digest](#digests) in `base`'s key, for this machine's architecture, and flattens its layers. crane is pinned like every download: its version and SHA-256 are at the top of `assets/oci/build.sh`, checked with `sha256sum`.
|
||||
2. `assets/oci/bootify.sh`, in a chroot of the image, adds what a container lacks to boot as a VM: a kernel and initramfs, an init system (systemd, or OpenRC on Alpine), cloud-init, sshd and sudo, and your user in the VM. Your user has your uid, so `bootify.sh` first removes a user of the image's that has it, such as Ubuntu's own `ubuntu` (uid 1000, the uid a Linux host's first user usually has).
|
||||
3. `mke2fs` writes the image's files into a raw ext4 disk, and `base` grows it to `base.yaml`'s size.
|
||||
3. `mke2fs` writes the image's files into a raw ext4 disk, and `base` grows it to base's 100 GiB disk.
|
||||
|
||||
`build.sh` also writes down the image's C library, from its `/etc/os-release`, and for a glibc image, its glibc version, which `getconf GNU_LIBC_VERSION` prints in a chroot of the image. devvm checks both, keeps them in the record of `base` and of every image on it (`libc` and `glibc`), and checks each shared tool against that glibc version ([building tools](#building-tools)).
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ devvm runs `limactl` from its own data folder. When a config is invalid, Lima wr
|
||||
|
||||
## Clones and overlays
|
||||
|
||||
An image is a stopped VM in devvm's Lima home, named `devvm-img-<key>`. devvm makes base's from Ubuntu's cloud image with `base.yaml` and `--mount-none`, and it gives `limactl create` the template on its standard input (`-`), from the binary, so no copy of `base.yaml` is on disk. With `--from`, it makes base's from the converted disk instead, and boots its kernel and initrd directly ([details](images.md#how-its-converted)). A layer's image is a clone of its parent's, also made with `--mount-none`, so a build mounts nothing from the host. A project VM is a clone of its image's VM, which devvm makes while the image is stopped.
|
||||
An image is a stopped VM in devvm's Lima home, named `devvm-img-<key>`. devvm makes base's from Ubuntu's cloud image with `base.yaml`, [base's size](images.md#bases-size) as `--cpus`, `--memory` and `--disk`, and `--mount-none`, and it gives `limactl create` the template on its standard input (`-`), from the binary, so no copy of `base.yaml` is on disk. With `--from`, it makes base's from the converted disk instead, and boots its kernel and initrd directly ([details](images.md#how-its-converted)). A layer's image is a clone of its parent's, also made with `--mount-none`, so a build mounts nothing from the host. A project VM is a clone of its image's VM, which devvm makes while the image is stopped.
|
||||
|
||||
- **macOS:** the clone's disk is an APFS copy-on-write copy. It shares the image's blocks until the VM writes them, so `du` overcounts it.
|
||||
- **Linux:** Lima's disks are qcow2 files, and a clone would be a full copy. So a project VM's disk is a qcow2 overlay of its image's, readable only by you, which shares the image's blocks and holds only the VM's changes. An image's disk is read-only once it's built, and devvm can't delete an image while VMs' disks are overlays of it (`image_in_use`). devvm reads each VM disk's backing file with `qemu-img info -U`, which shares the disk with the QEMU of a running VM, because that QEMU's write lock refuses `qemu-img info` otherwise.
|
||||
|
||||
@@ -340,7 +340,7 @@ type Built struct {
|
||||
// "" for musl, for base from the backend's own Ubuntu, and above base.
|
||||
Glibc string
|
||||
// Fitted is base's CPUs and memory when fitting them to the host made
|
||||
// either less than base.yaml's (Fitted); zero when it didn't, and
|
||||
// either less than BaseCPUs or BaseMemoryGiB (Fitted); zero when it didn't, and
|
||||
// above base.
|
||||
Fitted Size
|
||||
}
|
||||
|
||||
+11
-1
@@ -3,6 +3,16 @@ package backend
|
||||
// gib is a GiB in bytes.
|
||||
const gib = 1 << 30
|
||||
|
||||
// Base's size, which every backend gives base: its CPUs and memory, which
|
||||
// FitCPUs and FitMemory fit to the host, and its disk, which every image
|
||||
// and new VM gets at least, as disks can't shrink. Base's disk goes into
|
||||
// its image, so each backend's Origin carries it into base's key.
|
||||
const (
|
||||
BaseCPUs = 4
|
||||
BaseMemoryGiB = 8 // GiB
|
||||
BaseDiskGiB = 100 // GiB
|
||||
)
|
||||
|
||||
// FitCPUs is the CPUs a VM asking for want gets on a host with hostCPUs:
|
||||
// want, or the host's count when it has fewer. A hostCPUs of 0 or less
|
||||
// is unknown, and gives want.
|
||||
@@ -26,7 +36,7 @@ func FitMemory(wantGiB float64, hostBytes uint64) float64 {
|
||||
}
|
||||
|
||||
// Fitted is got's CPUs and memory, base's as fitted to the host, when
|
||||
// either is less than want's, base.yaml's; zero when the host gave base
|
||||
// either is less than want's, base's own; zero when the host gave base
|
||||
// all it asks for.
|
||||
func Fitted(want, got Size) Size {
|
||||
if got.CPUs < want.CPUs || got.MemoryGiB < want.MemoryGiB {
|
||||
|
||||
@@ -17,7 +17,14 @@ func TestFitCPUs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// base's memory: base.yaml's, or half the host's whole GiB when that
|
||||
// Base's own size is 4 CPUs, 8 GiB of memory and a 100 GiB disk.
|
||||
func TestBaseSize(t *testing.T) {
|
||||
if got := (Size{CPUs: BaseCPUs, MemoryGiB: BaseMemoryGiB, DiskGiB: BaseDiskGiB}); got != (Size{CPUs: 4, MemoryGiB: 8, DiskGiB: 100}) {
|
||||
t.Errorf("base's size: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// base's memory: its own, or half the host's whole GiB when that
|
||||
// leaves it less than 2 GiB.
|
||||
func TestFitMemory(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
@@ -68,7 +75,7 @@ func TestMaxMemory(t *testing.T) {
|
||||
}
|
||||
|
||||
// What a build reports as fitted: the CPUs and memory base got when
|
||||
// either is less than base.yaml's, never its disk; nothing otherwise.
|
||||
// either is less than base's own, never its disk; nothing otherwise.
|
||||
func TestFitted(t *testing.T) {
|
||||
want := Size{CPUs: 4, MemoryGiB: 8, DiskGiB: 100}
|
||||
for _, c := range []struct {
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -22,7 +21,7 @@ import (
|
||||
|
||||
// BuildImage builds the image's instance, devvm-img-<key>, which is then
|
||||
// the image: base is a VM made from Ubuntu's cloud image with base.yaml's
|
||||
// settings (with spec.From, from that image converted into a disk:
|
||||
// settings and base's size (buildSize) (with spec.From, from that image converted into a disk:
|
||||
// convert), all from its recipe's origin (Origin, checked by originOf), a
|
||||
// layer a clone of its parent's instance. Neither mounts anything from the
|
||||
// host. It starts confined as spec.Net asks (no port forwards, and on
|
||||
@@ -101,7 +100,7 @@ func (l *images) BuildImage(ctx context.Context, spec backend.ImageSpec) (backen
|
||||
if err != nil {
|
||||
return backend.Built{}, err
|
||||
}
|
||||
want, size, err := l.buildSize(o.yaml)
|
||||
want, size, err := l.buildSize(o)
|
||||
if err != nil {
|
||||
return backend.Built{}, err
|
||||
}
|
||||
@@ -267,7 +266,7 @@ func layerArgs(parent, inst string) []string {
|
||||
// on this machine, which base's origin holds, with yaml's settings
|
||||
// (base.yaml) and nothing from the host mounted, or the mounts a --set in
|
||||
// opts gives it (--set applies after --mount-none). It returns the image
|
||||
// it used. It gets size's CPUs and memory (buildSize's).
|
||||
// it used. It gets size's CPUs, memory and disk (buildSize's).
|
||||
func (l *images) createFromUbuntu(ctx context.Context, vm string, yaml []byte, size backend.Size, opts ...string) (ubuntu.Image, error) {
|
||||
img, err := l.pinnedImage()
|
||||
if err != nil {
|
||||
@@ -282,11 +281,16 @@ func (l *images) createFromUbuntu(ctx context.Context, vm string, yaml []byte, s
|
||||
|
||||
// createArgs are limactl create's arguments for a VM booting images, with
|
||||
// nothing from the host mounted but what opts' --set gives it, size's CPUs
|
||||
// and memory, and the rest of base.yaml's settings, which create gives it
|
||||
// on its standard input (-).
|
||||
// and memory, its disk unless that's zero (Lima's own then), and the rest
|
||||
// of base.yaml's settings, which create gives it on its standard input
|
||||
// (-).
|
||||
func createArgs(vm string, images []limaImage, size backend.Size, opts ...string) []string {
|
||||
args := append([]string{"create", "--tty=false", "--mount-none", "--name=" + vm, "--set", ".images = " + yqJSON(images)}, opts...)
|
||||
return append(args, "--cpus="+strconv.Itoa(size.CPUs), "--memory="+gibString(size.MemoryGiB), "-")
|
||||
args = append(args, "--cpus="+strconv.Itoa(size.CPUs), "--memory="+gibString(size.MemoryGiB))
|
||||
if size.DiskGiB > 0 {
|
||||
args = append(args, "--disk="+gibString(size.DiskGiB))
|
||||
}
|
||||
return append(args, "-")
|
||||
}
|
||||
|
||||
// create runs limactl create with args (createArgs) as step, yaml
|
||||
@@ -366,35 +370,21 @@ func (l *images) unfinished(ctx context.Context, inst string) {
|
||||
_ = l.delete(ctx, inst)
|
||||
}
|
||||
|
||||
var (
|
||||
cpusLine = regexp.MustCompile(`(?m)^cpus:\s*([0-9]+)\s*$`)
|
||||
memoryLine = regexp.MustCompile(`(?m)^memory:\s*([0-9.]+)GiB\s*$`)
|
||||
)
|
||||
|
||||
// buildSize is base's CPUs and memory: data's, base.yaml's (want), and
|
||||
// got, them fitted to the host (backend.FitCPUs, backend.FitMemory), so a
|
||||
// host with fewer CPUs gets its own count and one that base.yaml's memory
|
||||
// would leave less than 2 GiB gets half its memory. Images built from
|
||||
// base, and their VMs, keep got.
|
||||
func (l *images) buildSize(data []byte) (want, got backend.Size, err error) {
|
||||
c := cpusLine.FindSubmatch(data)
|
||||
if c == nil {
|
||||
return want, got, errors.New("lima: base.yaml sets no CPUs")
|
||||
}
|
||||
if want.CPUs, err = strconv.Atoi(string(c[1])); err != nil {
|
||||
return want, got, err
|
||||
}
|
||||
m := memoryLine.FindSubmatch(data)
|
||||
if m == nil {
|
||||
return want, got, errors.New("lima: base.yaml sets no memory in GiB")
|
||||
}
|
||||
if want.MemoryGiB, err = strconv.ParseFloat(string(m[1]), 64); err != nil {
|
||||
return want, got, err
|
||||
}
|
||||
// buildSize is base's size: its own CPUs and memory (backend.BaseCPUs,
|
||||
// backend.BaseMemoryGiB) as want, and got, them fitted to the host
|
||||
// (backend.FitCPUs, backend.FitMemory), so a host with fewer CPUs gets
|
||||
// its own count and one that base's memory would leave less than 2 GiB
|
||||
// gets half its memory, with o's disk. Images built from base, and their
|
||||
// VMs, keep got.
|
||||
func (l *images) buildSize(o origin) (want, got backend.Size, err error) {
|
||||
want = backend.Size{CPUs: backend.BaseCPUs, MemoryGiB: backend.BaseMemoryGiB}
|
||||
host, err := l.Memory()
|
||||
if err != nil {
|
||||
return want, got, err
|
||||
}
|
||||
got = backend.Size{CPUs: backend.FitCPUs(want.CPUs, l.CPUs()), MemoryGiB: backend.FitMemory(want.MemoryGiB, host)}
|
||||
got = backend.Size{
|
||||
CPUs: backend.FitCPUs(want.CPUs, l.CPUs()), MemoryGiB: backend.FitMemory(want.MemoryGiB, host),
|
||||
DiskGiB: o.diskGiB,
|
||||
}
|
||||
return want, got, nil
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"testing/fstest"
|
||||
"time"
|
||||
|
||||
"github.com/w3cj/devvm/assets"
|
||||
"github.com/w3cj/devvm/internal/backend"
|
||||
"github.com/w3cj/devvm/internal/daemon"
|
||||
"github.com/w3cj/devvm/internal/image"
|
||||
@@ -30,7 +31,7 @@ const (
|
||||
func buildLima(t *testing.T, os string, parentStatus string) (*Lima, *fakeRunner) {
|
||||
t.Helper()
|
||||
l, f, _ := testLima(t, os)
|
||||
l.Assets = fstest.MapFS{"base.yaml": {Data: []byte("cpus: 4\nmemory: 8GiB\n")}}
|
||||
l.Assets = fstest.MapFS{"base.yaml": {Data: []byte("containerd:\n user: false\n")}}
|
||||
l.Memory = func() (uint64, error) { return 16 * gib, nil }
|
||||
l.CPUs = func() int { return 8 }
|
||||
l.Info = func(msg.M) {}
|
||||
@@ -117,7 +118,7 @@ func TestBuildImageBase(t *testing.T) {
|
||||
checkLines(t, f.lines(), []string{
|
||||
"limactl create --tty=false --mount-none --name=" + inst +
|
||||
` --set .images = [{"location":"` + img + `","arch":"aarch64","digest":"sha256:` + testUbuntuSum + `"}]` +
|
||||
" --cpus=4 --memory=8 -",
|
||||
" --cpus=4 --memory=8 --disk=100 -",
|
||||
"limactl edit --tty=false " + inst + " --set .ssh.localPort=",
|
||||
"sandbox-exec -f " + l.Dirs.VM(inst).Profile() + " ",
|
||||
"limactl shell " + inst + " bash -s",
|
||||
@@ -125,7 +126,7 @@ func TestBuildImageBase(t *testing.T) {
|
||||
"limactl stop " + inst,
|
||||
})
|
||||
for _, c := range f.calls {
|
||||
if strings.HasPrefix(c.line(), "limactl create") && c.stdin != "cpus: 4\nmemory: 8GiB\n" {
|
||||
if strings.HasPrefix(c.line(), "limactl create") && c.stdin != "containerd:\n user: false\n" {
|
||||
t.Errorf("limactl create's input: %q, want base.yaml", c.stdin)
|
||||
}
|
||||
}
|
||||
@@ -407,8 +408,6 @@ func TestBuildImageRefuses(t *testing.T) {
|
||||
"an existing image": func(s *backend.ImageSpec) { s.Key = baseKey; s.Parent = "" },
|
||||
"no Ubuntu pinned": func(*backend.ImageSpec) {},
|
||||
"another Ubuntu": func(*backend.ImageSpec) {},
|
||||
"no memory in GiB": func(*backend.ImageSpec) {},
|
||||
"no CPUs": func(*backend.ImageSpec) {},
|
||||
"no host memory": func(*backend.ImageSpec) {},
|
||||
"a missing base.yml": func(*backend.ImageSpec) {},
|
||||
} {
|
||||
@@ -423,10 +422,6 @@ func TestBuildImageRefuses(t *testing.T) {
|
||||
if err := os.Remove(l.Dirs.UbuntuPin()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
case "no memory in GiB":
|
||||
l.Assets = fstest.MapFS{"base.yaml": {Data: []byte("cpus: 4\nmemory: 8G\n")}}
|
||||
case "no CPUs":
|
||||
l.Assets = fstest.MapFS{"base.yaml": {Data: []byte("memory: 8GiB\n")}}
|
||||
case "no host memory":
|
||||
l.Memory = func() (uint64, error) { return 0, errors.ErrUnsupported }
|
||||
case "a missing base.yml":
|
||||
@@ -475,6 +470,41 @@ func TestBuildImageSmallHost(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// devvm's own base, on a host with room for it, is created with 4 CPUs,
|
||||
// 8 GiB of memory and a 100 GiB disk, all limactl create's flags: the
|
||||
// base.yaml on its input sets none of them.
|
||||
func TestBuildImageBaseSize(t *testing.T) {
|
||||
l, f := buildLima(t, "darwin", "")
|
||||
l.Assets = assets.FS
|
||||
if _, err := l.BuildImage(t.Context(), baseSpec(t, l)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var create call
|
||||
for _, c := range f.calls {
|
||||
if strings.HasPrefix(c.line(), "limactl create") {
|
||||
create = c
|
||||
}
|
||||
}
|
||||
flag := func(name string) string {
|
||||
for _, a := range create.argv {
|
||||
if v, ok := strings.CutPrefix(a, "--"+name+"="); ok {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
for name, want := range map[string]string{"cpus": "4", "memory": "8", "disk": "100"} {
|
||||
if got := flag(name); got != want {
|
||||
t.Errorf("base's %s: %q, want %q (%s)", name, got, want, create.line())
|
||||
}
|
||||
for line := range strings.Lines(create.stdin) {
|
||||
if strings.HasPrefix(line, name+":") {
|
||||
t.Errorf("base.yaml sets %s: %q", name, line)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLimaArch(t *testing.T) {
|
||||
for goarch, want := range map[string]string{"arm64": "aarch64", "amd64": "x86_64", "riscv64": "riscv64"} {
|
||||
if got := limaArch(goarch); got != want {
|
||||
|
||||
@@ -179,8 +179,11 @@ func (l *Lima) Name() string { return Name }
|
||||
// Origin is what Lima makes base from, which BuildImage is given back:
|
||||
// the Ubuntu cloud image pinned on this machine (PinOrigin; "" before
|
||||
// one is), which a --from conversion's VM boots too, with f, the
|
||||
// conversion's scripts (convertSteps), and then base.yaml, the settings
|
||||
// limactl create reads.
|
||||
// conversion's scripts (convertSteps), then base's disk in GiB
|
||||
// (backend.BaseDiskGiB), which limactl create gets as its --disk, and
|
||||
// then base.yaml, the other settings limactl create reads. Base's CPUs
|
||||
// and memory aren't in it: they're fitted to the host, and don't change
|
||||
// what the image holds.
|
||||
func (l *images) Origin(f *backend.From) ([]image.Step, error) {
|
||||
pin, _, err := l.pinned()
|
||||
if err != nil {
|
||||
@@ -198,19 +201,23 @@ func (l *images) Origin(f *backend.From) ([]image.Step, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return append(steps, image.Step{Name: originConfig, Data: yaml}), nil
|
||||
return append(steps,
|
||||
image.Step{Name: originDisk, Args: []string{gibString(backend.BaseDiskGiB)}},
|
||||
image.Step{Name: originConfig, Data: yaml}), nil
|
||||
}
|
||||
|
||||
// The names of Lima's origin steps: the Ubuntu image's pin, and
|
||||
// base.yaml.
|
||||
// The names of Lima's origin steps: the Ubuntu image's pin, base's disk,
|
||||
// and base.yaml.
|
||||
const (
|
||||
originUbuntu = "ubuntu-image"
|
||||
originDisk = "disk"
|
||||
originConfig = "base.yaml"
|
||||
)
|
||||
|
||||
// origin is base's origin steps as BuildImage runs them.
|
||||
type origin struct {
|
||||
yaml []byte // base.yaml, for limactl create
|
||||
diskGiB float64 // base's disk, limactl create's --disk
|
||||
conversion []image.Step // with --from, the conversion's (convertSteps); nil without
|
||||
}
|
||||
|
||||
@@ -231,6 +238,8 @@ func (l *images) originOf(steps []image.Step, f *backend.From) (origin, error) {
|
||||
switch {
|
||||
case s.Name == originUbuntu && len(s.Args) == 1:
|
||||
pin = s.Args[0]
|
||||
case s.Name == originDisk && len(s.Args) == 1:
|
||||
o.diskGiB, _ = strconv.ParseFloat(s.Args[0], 64)
|
||||
case s.Name == originConfig:
|
||||
o.yaml = s.Data
|
||||
case strings.HasPrefix(s.Name, "oci/"):
|
||||
@@ -242,6 +251,8 @@ func (l *images) originOf(steps []image.Step, f *backend.From) (origin, error) {
|
||||
return origin{}, fmt.Errorf("lima: base's recipe pins Ubuntu %q, not %q", pin, want)
|
||||
case o.yaml == nil:
|
||||
return origin{}, errors.New("lima: base's recipe has no base.yaml")
|
||||
case o.diskGiB <= 0:
|
||||
return origin{}, errors.New("lima: base's recipe has no disk size")
|
||||
case (f != nil) != (o.conversion != nil):
|
||||
return origin{}, errors.New("lima: base's recipe has another conversion than its --from asks for")
|
||||
case f == nil:
|
||||
|
||||
@@ -401,7 +401,7 @@ func stepNames(steps []image.Step) []string {
|
||||
|
||||
// Base's origin is the Ubuntu cloud image pinned on this machine, for the
|
||||
// host ("" before one is, or when the one pinned is another
|
||||
// architecture's), and base.yaml; with --from, the conversion's scripts in
|
||||
// architecture's), base's disk and base.yaml; with --from, the conversion's scripts in
|
||||
// between, build.sh as root with the user it makes the image's, and none
|
||||
// of oci/'s other files. Without the user, or devvm's files, there's
|
||||
// none.
|
||||
@@ -413,11 +413,11 @@ func TestOrigin(t *testing.T) {
|
||||
for arch, pin := range map[string]string{"arm64": want, "amd64": ""} {
|
||||
l.Arch = arch
|
||||
steps, err := l.Origin(nil)
|
||||
if err != nil || !slices.Equal(stepNames(steps), []string{originUbuntu, originConfig}) ||
|
||||
!slices.Equal(steps[0].Args, []string{pin}) {
|
||||
t.Fatalf("%s: Origin = %+v, %v", arch, steps, err)
|
||||
if err != nil || !slices.Equal(stepNames(steps), []string{originUbuntu, originDisk, originConfig}) ||
|
||||
!slices.Equal(steps[0].Args, []string{pin}) || !slices.Equal(steps[1].Args, []string{"100"}) {
|
||||
t.Fatalf("%s: Origin = %q, %v", arch, stepNames(steps), err)
|
||||
}
|
||||
if yaml, _ := fs.ReadFile(assets.FS, "base.yaml"); !bytes.Equal(steps[1].Data, yaml) {
|
||||
if yaml, _ := fs.ReadFile(assets.FS, "base.yaml"); !bytes.Equal(steps[2].Data, yaml) {
|
||||
t.Errorf("%s: base.yaml isn't devvm's", arch)
|
||||
}
|
||||
}
|
||||
@@ -436,7 +436,7 @@ func TestOrigin(t *testing.T) {
|
||||
}
|
||||
pinUbuntu(t, l, testUbuntuURL, testUbuntuSum)
|
||||
steps, err := l.Origin(f)
|
||||
if want := slices.Concat([]string{originUbuntu}, conversionScripts, []string{originConfig}); err != nil || !slices.Equal(stepNames(steps), want) {
|
||||
if want := slices.Concat([]string{originUbuntu}, conversionScripts, []string{originDisk, originConfig}); err != nil || !slices.Equal(stepNames(steps), want) {
|
||||
t.Fatalf("Origin(--from) = %q, %v; want %q", stepNames(steps), err, want)
|
||||
}
|
||||
build := steps[1]
|
||||
@@ -485,8 +485,15 @@ func TestOriginOfRefuses(t *testing.T) {
|
||||
steps []image.Step
|
||||
from *backend.From
|
||||
}{
|
||||
"another Ubuntu": {change(func(s []image.Step) []image.Step { s[0].Args = []string{"x"}; return s }), f},
|
||||
"no base.yaml": {change(func(s []image.Step) []image.Step { return s[:len(s)-1] }), f},
|
||||
"another Ubuntu": {change(func(s []image.Step) []image.Step { s[0].Args = []string{"x"}; return s }), f},
|
||||
"no base.yaml": {change(func(s []image.Step) []image.Step { return s[:len(s)-1] }), f},
|
||||
"no disk": {change(func(s []image.Step) []image.Step {
|
||||
return slices.DeleteFunc(s, func(st image.Step) bool { return st.Name == originDisk })
|
||||
}), f},
|
||||
"a disk that isn't a size": {change(func(s []image.Step) []image.Step {
|
||||
s[len(s)-2] = image.Step{Name: originDisk, Args: []string{"big"}}
|
||||
return s
|
||||
}), f},
|
||||
"a conversion without one": {good, nil},
|
||||
"no conversion with --from": {ubuntuOnly, f},
|
||||
"another digest": {change(func(s []image.Step) []image.Step { s[1].Args[0] = "debian@sha256:bbbb"; return s }), f},
|
||||
|
||||
@@ -25,7 +25,8 @@ import (
|
||||
// OCIVM is the throwaway VM a container image is converted in (--from).
|
||||
const OCIVM = "devvm-oci-build"
|
||||
|
||||
// convertedSize is the converted disk's size; Lima grows it to base.yaml's.
|
||||
// convertedSize is the converted disk's size; Lima grows it to base's
|
||||
// (backend.BaseDiskGiB, base's origin's disk).
|
||||
const convertedSize = "20G"
|
||||
|
||||
// ociSteps is the conversion's steps: the build VM's create, configure
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/w3cj/devvm/assets"
|
||||
"github.com/w3cj/devvm/internal/backend"
|
||||
"github.com/w3cj/devvm/internal/build"
|
||||
"github.com/w3cj/devvm/internal/msg"
|
||||
@@ -136,7 +135,7 @@ func (s setup) run(c setupChoice) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sc := vm.SizeChoice{Dirs: dirs, Assets: assets.FS, Host: host, Answer: s.answer, Say: s.ui.Say, Warn: s.ui.Warn, Info: s.ui.Info}
|
||||
sc := vm.SizeChoice{Dirs: dirs, Host: host, Answer: s.answer, Say: s.ui.Say, Warn: s.ui.Warn, Info: s.ui.Info}
|
||||
if err := sc.Ask(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+2
-27
@@ -1,9 +1,7 @@
|
||||
package vm
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"io/fs"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -23,7 +21,7 @@ type Size struct {
|
||||
Disk string `json:"disk,omitempty"`
|
||||
}
|
||||
|
||||
// The parts of a size, as devvm size shows them and base.yaml names them.
|
||||
// The parts of a size, as devvm size shows them.
|
||||
const (
|
||||
KeyCPUs = "cpus"
|
||||
KeyMemory = "memory" // GiB
|
||||
@@ -251,7 +249,7 @@ func (e Settings) SetSize(ctx context.Context, s Size, global bool) error {
|
||||
return err
|
||||
}
|
||||
if global {
|
||||
return SizeChoice{Dirs: e.Dirs, Assets: e.Assets, Host: host, Info: e.Info}.Set(s)
|
||||
return SizeChoice{Dirs: e.Dirs, Host: host, Info: e.Info}.Set(s)
|
||||
}
|
||||
t, err := e.folderVM(ctx, msg.NoVMSize)
|
||||
if err != nil {
|
||||
@@ -287,26 +285,3 @@ func (e Settings) SetSize(ctx context.Context, s Size, global bool) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// BaseDisk returns the disk size in GiB that base.yaml in assets, devvm's
|
||||
// own files, gives base, and so every image and new VM (disks can't
|
||||
// shrink); 0 when it sets none.
|
||||
func BaseDisk(assets fs.FS) float64 { return baseSetting(assets, "disk") }
|
||||
|
||||
// baseSetting returns the number base.yaml in assets sets for key (cpus,
|
||||
// memory or disk, the last two in GiB); 0 when it sets none.
|
||||
func baseSetting(assets fs.FS, key string) float64 {
|
||||
f, err := assets.Open("base.yaml")
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
defer func() { _ = f.Close() }()
|
||||
s := bufio.NewScanner(f)
|
||||
for s.Scan() {
|
||||
if v, ok := strings.CutPrefix(s.Text(), key+":"); ok {
|
||||
g, _ := strconv.ParseFloat(strings.TrimSuffix(strings.TrimSpace(v), "GiB"), 64)
|
||||
return g
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -4,9 +4,7 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"testing/fstest"
|
||||
|
||||
"github.com/w3cj/devvm/assets"
|
||||
"github.com/w3cj/devvm/internal/backend"
|
||||
"github.com/w3cj/devvm/internal/msg"
|
||||
"github.com/w3cj/devvm/internal/state"
|
||||
@@ -76,15 +74,6 @@ func TestSizeCheck(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseDisk(t *testing.T) {
|
||||
if got := BaseDisk(assets.FS); got != 100 {
|
||||
t.Errorf("BaseDisk(devvm's files) = %v, want base.yaml's 100", got)
|
||||
}
|
||||
if got := BaseDisk(fstest.MapFS{}); got != 0 {
|
||||
t.Errorf("BaseDisk(no base.yaml) = %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSizeText(t *testing.T) {
|
||||
for s, want := range map[backend.Size]string{
|
||||
{CPUs: 4, MemoryGiB: 8, DiskGiB: 100}: "cpus=4 memory=8GiB disk=100GiB",
|
||||
|
||||
@@ -2,7 +2,6 @@ package vm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/fs"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -16,9 +15,8 @@ import (
|
||||
// settings.json: from flags (Set), or asked for (Ask). Nothing rebuilds,
|
||||
// and existing VMs keep their size.
|
||||
type SizeChoice struct {
|
||||
Dirs paths.Dirs
|
||||
Assets fs.FS // devvm's own files, whose base.yaml sets base's size
|
||||
Host Host
|
||||
Dirs paths.Dirs
|
||||
Host Host
|
||||
// Answer asks for a value and returns the line typed, "" for Enter;
|
||||
// Say prints the question's context, Warn a refused answer, Info
|
||||
// what's saved.
|
||||
@@ -124,12 +122,12 @@ func (c SizeChoice) ask(prompt msg.M, parse func(string) (Size, error)) string {
|
||||
}
|
||||
}
|
||||
|
||||
// Fitted is the CPUs and memory base.yaml gives base, fitted to the host
|
||||
// (backend.FitCPUs, backend.FitMemory): base.yaml's own when the host
|
||||
// has room for them.
|
||||
// Fitted is base's CPUs and memory (backend.BaseCPUs,
|
||||
// backend.BaseMemoryGiB), fitted to the host (backend.FitCPUs,
|
||||
// backend.FitMemory): base's own when the host has room for them.
|
||||
func (c SizeChoice) Fitted() Size {
|
||||
cpus := backend.FitCPUs(int(baseSetting(c.Assets, KeyCPUs)), c.Host.CPUs)
|
||||
mem := backend.FitMemory(baseSetting(c.Assets, KeyMemory), c.Host.memoryBytes())
|
||||
cpus := backend.FitCPUs(backend.BaseCPUs, c.Host.CPUs)
|
||||
mem := backend.FitMemory(backend.BaseMemoryGiB, c.Host.memoryBytes())
|
||||
return Size{CPUs: strconv.Itoa(cpus), Memory: strconv.FormatFloat(mem, 'g', -1, 64)}
|
||||
}
|
||||
|
||||
@@ -151,7 +149,7 @@ func (e creation) firstRunSize(given Size, def settings.Defaults) error {
|
||||
return err
|
||||
}
|
||||
return SizeChoice{
|
||||
Dirs: e.Dirs, Assets: e.Assets, Host: host,
|
||||
Dirs: e.Dirs, Host: host,
|
||||
Answer: e.Answer, Say: e.Say, Warn: e.Warn, Info: e.Info,
|
||||
}.Ask()
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/w3cj/devvm/assets"
|
||||
"github.com/w3cj/devvm/internal/msg"
|
||||
"github.com/w3cj/devvm/internal/paths"
|
||||
"github.com/w3cj/devvm/internal/settings"
|
||||
@@ -34,7 +33,7 @@ func (a *sizeAsker) answer(m msg.M) string {
|
||||
}
|
||||
|
||||
func (a *sizeAsker) choice(d paths.Dirs, h Host) SizeChoice {
|
||||
return SizeChoice{Dirs: d, Assets: assets.FS, Host: h, Answer: a.answer, Say: a.record, Warn: a.record, Info: a.record}
|
||||
return SizeChoice{Dirs: d, Host: h, Answer: a.answer, Say: a.record, Warn: a.record, Info: a.record}
|
||||
}
|
||||
|
||||
// saveSize saves s as new VMs' size in d's settings.json.
|
||||
|
||||
+1
-1
@@ -371,7 +371,7 @@ func (e creation) plan(ctx context.Context, o *Options, f project.Folder, b back
|
||||
if err != nil {
|
||||
return newVM{}, err
|
||||
}
|
||||
if err := n.size.Check(host, BaseDisk(e.Assets), vm); err != nil {
|
||||
if err := n.size.Check(host, backend.BaseDiskGiB, vm); err != nil {
|
||||
return newVM{}, err
|
||||
}
|
||||
if n.ports == "" {
|
||||
|
||||
Vendored
+1
-1
@@ -20,7 +20,7 @@ catg $IMAGES/ubuntu.json
|
||||
stdout '^ "release": "release-20261016",$'
|
||||
stdout '^ "digest": "sha256:[0-9a-f]{64}",$'
|
||||
stub_calls
|
||||
stdout '^limactl create --tty=false --mount-none --name=devvm-img-[0-9a-f]{12} --set \.images = \[\{"location":"file://.*/release-[0-9]{8}/ubuntu-26\.04-server-cloudimg-(arm64|amd64)\.img","arch":"(aarch64|x86_64)","digest":"sha256:[0-9a-f]{64}"\}\] --cpus=4 --memory=8 -$'
|
||||
stdout '^limactl create --tty=false --mount-none --name=devvm-img-[0-9a-f]{12} --set \.images = \[\{"location":"file://.*/release-[0-9]{8}/ubuntu-26\.04-server-cloudimg-(arm64|amd64)\.img","arch":"(aarch64|x86_64)","digest":"sha256:[0-9a-f]{64}"\}\] --cpus=4 --memory=8 --disk=100 -$'
|
||||
cmp $STUB_DIR/create-template $DEVVM_REPO/assets/base.yaml
|
||||
! exists $XDG_DATA_HOME/devvm/assets
|
||||
stdout '^limactl edit --tty=false devvm-img-[0-9a-f]{12} .*--set \.portForwards = \[\{"guestIP":"127\.0\.0\.1"'
|
||||
|
||||
Vendored
+2
-2
@@ -38,13 +38,13 @@ stdout '^==> image_ready image=base$'
|
||||
! stdout oci_waiting
|
||||
stub_calls
|
||||
! stdout '^docker'
|
||||
stdout '^limactl create --tty=false --mount-none --name=devvm-oci-build --set \.images = \[\{"location":"file://.*/release-[0-9]{8}/ubuntu-26\.04-server-cloudimg-(arm64|amd64)\.img","arch":"(aarch64|x86_64)","digest":"sha256:[0-9a-f]{64}"\}\] --set \.mounts = \[\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/vm","writable":true\},\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/oci","writable":false\}\] --cpus=4 --memory=8 -$'
|
||||
stdout '^limactl create --tty=false --mount-none --name=devvm-oci-build --set \.images = \[\{"location":"file://.*/release-[0-9]{8}/ubuntu-26\.04-server-cloudimg-(arm64|amd64)\.img","arch":"(aarch64|x86_64)","digest":"sha256:[0-9a-f]{64}"\}\] --set \.mounts = \[\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/vm","writable":true\},\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/oci","writable":false\}\] --cpus=4 --memory=8 --disk=100 -$'
|
||||
stdout '^limactl start --tty=false devvm-oci-build$'
|
||||
# With HTTPS_PROXY set, the build goes through a proxy of devvm's, which
|
||||
# alone has the host's proxy settings: the script reads that proxy's
|
||||
# address on its input first, then runs with its arguments.
|
||||
stdout '^limactl shell --workdir / devvm-oci-build sudo bash -s -- /\S*/tmp/devvm-oci\.[0-9]+/oci/build\.sh /\S*/tmp/devvm-oci\.[0-9]+/oci /\S*/tmp/devvm-oci\.[0-9]+/vm node:24@sha256:a{64} node:24@sha256:a{64} \S+ [0-9]+ /home/\S+\.guest 20G$'
|
||||
stdout '^limactl delete -f devvm-oci-build\nlimactl create --tty=false --mount-none --name=devvm-img-[0-9a-f]{12} --set \.images = \[\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/vm/disk\.raw","arch":"(aarch64|x86_64)","kernel":\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/vm/kernel","cmdline":"root=/dev/vda rw console=hvc0"\},"initrd":\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/vm/initrd"\}\}\] --cpus=4 --memory=8 -$'
|
||||
stdout '^limactl delete -f devvm-oci-build\nlimactl create --tty=false --mount-none --name=devvm-img-[0-9a-f]{12} --set \.images = \[\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/vm/disk\.raw","arch":"(aarch64|x86_64)","kernel":\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/vm/kernel","cmdline":"root=/dev/vda rw console=hvc0"\},"initrd":\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/vm/initrd"\}\}\] --cpus=4 --memory=8 --disk=100 -$'
|
||||
cmp $STUB_DIR/create-template $DEVVM_REPO/assets/base.yaml
|
||||
stdout '^limactl shell devvm-img-[0-9a-f]{12} bash -s$'
|
||||
exec sh -c 'ls "$TMPDIR"'
|
||||
|
||||
Vendored
+1
-1
@@ -27,7 +27,7 @@ env DEVVM_TEST_FREE_GIB=500
|
||||
exec devvm build base
|
||||
stdout '^==> base_fitted cpus=2 memory=3\.5$'
|
||||
stub_calls
|
||||
stdout '^limactl create --tty=false --mount-none --name=devvm-img-[0-9a-f]{12} .* --cpus=2 --memory=3\.5 -$'
|
||||
stdout '^limactl create --tty=false --mount-none --name=devvm-img-[0-9a-f]{12} .* --cpus=2 --memory=3\.5 --disk=100 -$'
|
||||
|
||||
# Sizes past the host: more CPUs than it has, or more memory than leaves
|
||||
# it 2 GiB.
|
||||
|
||||
Vendored
+5
-4
@@ -6,7 +6,7 @@
|
||||
# failing with $STUB_DIR/list-fails and hanging with $STUB_DIR/list-hangs;
|
||||
# create's template on its input (-) goes to $STUB_DIR/create-template. A
|
||||
# VM's size ("CPUS MEMORY DISK", in bytes) is $STUB_DIR/size-<name>, else 4
|
||||
# CPUs, 8 GiB and 100 GiB, which create's --cpus= and --memory= set and
|
||||
# CPUs, 8 GiB and 100 GiB, which create's --cpus=, --memory= and --disk= set and
|
||||
# edit's --cpus, --memory and --disk change. create's, clone's and edit's --set
|
||||
# go into its config (set_config, below: list shows it, with lima.yaml's env),
|
||||
# which a clone copies from its source, --mount-none takes the mounts out of,
|
||||
@@ -160,7 +160,7 @@ config_json() {
|
||||
}
|
||||
# create, clone and edit: a clone starts with its source's config, size and lima.yaml;
|
||||
# --mount-none drops the mounts, then each --set applies, as Lima's do; create's
|
||||
# --cpus=N and --memory=GiB set its size.
|
||||
# --cpus=N, --memory=GiB and --disk=GiB set its size.
|
||||
case ${1:-} in
|
||||
create | clone | edit)
|
||||
target=${names[0]:-}
|
||||
@@ -176,15 +176,16 @@ case ${1:-} in
|
||||
fi
|
||||
[[ " $* " != *" --mount-none "* ]] || rm -f "$STUB_DIR/config-$target/mounts"
|
||||
args=("$@")
|
||||
cpus=4 mem=8589934592
|
||||
cpus=4 mem=8589934592 disk=107374182400
|
||||
for ((i = 0; i < ${#args[@]}; i++)); do
|
||||
case ${args[i]} in
|
||||
--set) set_config "$target" "${args[i + 1]}" ;;
|
||||
--cpus=*) cpus=${args[i]#--cpus=} ;;
|
||||
--memory=*) mem=$(awk -v g="${args[i]#--memory=}" 'BEGIN { printf "%.0f", g * 1073741824 }') ;;
|
||||
--disk=*) disk=$(awk -v g="${args[i]#--disk=}" 'BEGIN { printf "%.0f", g * 1073741824 }') ;;
|
||||
esac
|
||||
done
|
||||
[[ $1 != create ]] || echo "$cpus $mem 107374182400" > "$STUB_DIR/size-$target" ;;
|
||||
[[ $1 != create ]] || echo "$cpus $mem $disk" > "$STUB_DIR/size-$target" ;;
|
||||
esac
|
||||
case ${1:-} in
|
||||
create)
|
||||
|
||||
Reference in new issue
Block a user