mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
feat(vm): a new VM's tools resolve while its image builds
A first run resolved the tools' versions, downloading devvm's own mise first, only after base had built: 10 s on the mini, 5 s on fedora, in series. Neither needs the other, so create now starts Versions.Lock in the background as an image starts to build (resolveWhile's start, which build.Env.Building calls once an image is found unbuilt and its features are chosen) and waits for it after, cancelling it when the build fails. When every image is built already, nothing starts in the background, and Files resolves in the foreground with its status lines as before. While the build runs, the resolve says nothing, as the build has the terminal: a held Reporter keeps its messages, shows no status line and refuses every question as without a terminal, and its commands' lines in the run log are tagged resolve. Once the build ends, done releases it: what it held is said, what it does from then on shows, and devvm waits under resolving_tools when it's still running. done returns its error, so a failure is said once and the launch doesn't resolve again. A VM whose lock is already there reads it at once. TestHeld, TestResolveShowsAfterBuild and TestBuildingCalled fail when held shows a status line, when the wait shows none, and when Building isn't called. Docs: images.md's Versions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
8 files changed
+400
-3
No files matched your search
+1
-1
@@ -222,7 +222,7 @@ These changes are on `main` and go out in the next release.
|
||||
|
||||
### Highlights
|
||||
|
||||
- A first run is faster: shared tool images build side by side, and it downloads less ([details](https://next.devvm.dev/docs/releases/0.2.0/#a-faster-first-run)).
|
||||
- A first run is about a quarter faster: shared tool images build side by side and the tools resolve while base builds, and it downloads less ([details](https://next.devvm.dev/docs/releases/0.2.0/#a-faster-first-run)).
|
||||
- A first run now survives a network that cuts or stalls connections: each download is tried again, and Ubuntu's cloud image and base's and layers' downloads go on from where they stopped ([details](https://next.devvm.dev/docs/releases/0.2.0/#a-first-run-on-a-bad-network)).
|
||||
- devvm keeps Ubuntu's cloud image in its own folder, so Lima's cache no longer grows with each release, and `devvm space` and `devvm gc --caches` show and free it ([details](https://next.devvm.dev/docs/releases/0.2.0/#ubuntus-cloud-image-in-devvms-folder)).
|
||||
|
||||
|
||||
@@ -207,6 +207,8 @@ mise's registry decides where a tool comes from, and a mise release can change i
|
||||
|
||||
The resolving runs on this machine with a mise of devvm's own. That mise is a pinned release, which devvm downloads once into `~/.local/share/devvm/cache/mise/<version>` as its `.tar.gz`, a third of the binary's size, and checks against its SHA-256 before it takes the binary out and runs it (`mise_checksum`). A download that gets no answer, loses it partway or gets a 408, 429 or server error is tried again up to three times, after one second and then twice as long each time, and any other answer fails it at once (`mise_download_failed`). One devvm downloads it at a time, holding `~/.local/share/devvm/cache/mise/download.lock`, and another waits for it under a status line (`mise_waiting`) and then takes what it kept. The download goes into a folder of its own, which the next download takes away when a killed run left it, and devvm hashes the archive again through the file it then unpacks, so the binary comes from the bytes it checked. devvm never uses the mise you have installed, and nothing it does reaches your own mise config. Each run of that mise gets temporary folders for its data, cache, state and config, which devvm deletes afterwards, so `cache/mise/<version>` holds only the binary. `devvm gc` deletes the folders of other versions, unless one changed in the last hour.
|
||||
|
||||
A new VM's tools resolve while its image builds, as neither needs the other. The resolve starts once an image starts to build, after the build's questions, and when every image is built already, devvm resolves them before the tool images build, with its status lines as usual. The resolve says nothing while the build runs, because the build has the terminal. devvm holds back what the resolve says until the build ends, shows no status line for it, refuses any question it would ask, and starts its commands' lines in the run log with `[resolve]`. When the build ends with the resolve still running, devvm shows what the resolve does from then on, and waits for it under a status line of its own (`resolving_tools`). When the resolve fails, devvm says so once, after the build, and the launch fails, and when the build fails, devvm stops the resolve.
|
||||
|
||||
Sometimes a tool's newest version isn't published for every platform yet, for example when a release is still uploading, when a tag has no release, or for a few days after a Node release until its musl builds appear. A version counts as published only where its lock entry has a download with a checksum, since mise checks the download against it. devvm then takes the newest of the next five older versions that is published everywhere, and says so (`tool_stepped_back`). When none of them is, devvm says that too (`tool_no_download`). The next check tries the newest version again.
|
||||
|
||||
A new VM gets the lock's versions, and devvm checks the lock again first when the last check was more than a day ago. When a check fails, devvm uses the versions it found last (`tools_check_failed`). When the shared tools' `mise.toml` changes, as it can in a devvm upgrade, devvm resolves the tools again. A VM lists its tool images in its state, so a newer version never changes a VM that has an older one. Older versions that no VM has are unused, and `devvm gc` deletes them.
|
||||
|
||||
@@ -116,7 +116,7 @@ Run `devvm update` in each existing VM's folder, and give the first one several
|
||||
|
||||
### A faster first run
|
||||
|
||||
A first run with the defaults took about two and a half minutes on a fast link, and a third of that came after base was built. The shared tool images built one after another. Now up to four tool images build side by side, each in a build VM of 2 GiB and 2 CPUs. devvm runs only as many as this machine has room for after keeping 6 GiB and 2 CPUs for itself and the memory of devvm's running VMs, and as many as the free disk allows ([building tools](../internals/images.md#building-tools)).
|
||||
A first run with the defaults took about two and a half minutes on a fast link, and a third of that came after base was built. The shared tool images built one after another, and the tools' versions were resolved only once base was done. Now up to four tool images build side by side, each in a build VM of 2 GiB and 2 CPUs. devvm runs only as many as this machine has room for after keeping 6 GiB and 2 CPUs for itself and the memory of devvm's running VMs, and as many as the free disk allows. The tools' versions now resolve while base builds. On an M4 Mac mini the defaults' first run went from 156 to 118 seconds, and on an x86_64 Linux host from 159 to 125 ([building tools](../internals/images.md#building-tools)).
|
||||
|
||||
A first run also downloads less. devvm's own mise comes as its `.tar.gz`, in base and on this machine, a third of the binary's size.
|
||||
|
||||
|
||||
@@ -62,6 +62,11 @@ type Env struct {
|
||||
// FreeSpace returns the free space on the volume holding a path
|
||||
// (platform.Host's), checked before each build; nil checks none.
|
||||
FreeSpace func(path string) (uint64, error)
|
||||
// Building, when set, is called as an image starts to build, once its
|
||||
// features are chosen and it's found unbuilt, and never when every
|
||||
// image is built: what runs beside a build (a new VM's tools'
|
||||
// resolve) starts then. It may be called for each image built.
|
||||
Building func()
|
||||
|
||||
// looked is set once lookUp has run, which holds lookMu: builds on
|
||||
// one Env may run at once.
|
||||
@@ -362,6 +367,9 @@ func (b Builds) buildOnce(ctx context.Context, name image.Name) error {
|
||||
if err != nil || done {
|
||||
return err
|
||||
}
|
||||
if b.Building != nil {
|
||||
b.Building()
|
||||
}
|
||||
if err := b.Review.RequireFor(b.Backend, name.String(), spec.Features()...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -350,6 +350,31 @@ func TestBuild(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Building is called as an image starts to build, before the backend
|
||||
// builds it, and never when every image is built: a new VM's tools
|
||||
// resolve beside a build alone.
|
||||
func TestBuildingCalled(t *testing.T) {
|
||||
b, f := testEnv(t)
|
||||
var at []int // how many backend calls there were at each Building
|
||||
b.Building = func() { at = append(at, len(f.Methods())) }
|
||||
if err := (Builds{b}).Build(t.Context(), "foo"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(at) == 0 {
|
||||
t.Fatal("Building not called for a build")
|
||||
}
|
||||
if first := slices.Index(f.Methods(), "BuildImage"); first < at[0] {
|
||||
t.Errorf("Building called after the backend began to build (call %d, build %d)", at[0], first)
|
||||
}
|
||||
at = nil
|
||||
if err := (Builds{b}).Build(t.Context(), "foo"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(at) != 0 {
|
||||
t.Errorf("Building called %d times with every image built", len(at))
|
||||
}
|
||||
}
|
||||
|
||||
// A built-in layer runs devvm's script, not the user's of the same name.
|
||||
func TestBuildBuiltinLayer(t *testing.T) {
|
||||
b, f := testEnv(t)
|
||||
|
||||
@@ -369,6 +369,7 @@ func devvmGoroutineSites() map[string]string {
|
||||
"internal/vm/clonelfs.go: vmLFS.bring": "bring, on done, once the VM's stream has ended and the pipe is closed",
|
||||
"internal/vm/cloneseed.go: seeder.sendTar": detached + "the tar's writer, which ends at its next write once sendTar closes the pipe",
|
||||
"internal/vm/desktop.go: Desktop.serve": detached + "the VM's check, which serve's deferred cancel ends",
|
||||
"internal/vm/up.go: resolveWhile": "the done it returns, which create calls once its image is built or has failed",
|
||||
"internal/vm/desktop.go: sshChannel.Close": "Close, which waits for ssh's Wait, killing it after channelClose",
|
||||
"internal/vm/env.go: folderWithin": detached + "a look at a folder whose disk may hang, such as an NFS share's, left to finish on its own after folderWait",
|
||||
"internal/vm/home.go: remaking.saveHome": "saveHome, on copied, once the VM's tar has ended and the pipe is closed",
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
package vm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sync"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/devvmhq/devvm/assets"
|
||||
"github.com/devvmhq/devvm/internal/msg"
|
||||
"github.com/devvmhq/devvm/internal/paths"
|
||||
"github.com/devvmhq/devvm/internal/platform"
|
||||
"github.com/devvmhq/devvm/internal/tools"
|
||||
)
|
||||
|
||||
// resolveWhile reads the tools lock in the background and its done waits
|
||||
// for it, stopped first or not; with no tools it does nothing. Both end,
|
||||
// so a launch never leaves it running.
|
||||
func TestResolveWhile(t *testing.T) {
|
||||
d := paths.Dirs{Data: t.TempDir(), Config: t.TempDir()}
|
||||
config, err := fs.ReadFile(assets.FS, "shared-tools/mise.toml")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
lock, err := os.ReadFile(filepath.Join("..", "..", "testdata", "mise.lock"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for name, data := range map[string][]byte{d.ToolLock(): lock, d.ToolLockConfig(): config} {
|
||||
if err := os.WriteFile(name, data, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
var said []string
|
||||
env := tools.New(d, assets.FS, "0.1.0-test", &msg.Fake{OnInfo: func(m msg.M) { said = append(said, m.ID()) }}, platform.Host{})
|
||||
v := tools.Versions{Env: env}
|
||||
start, done := resolveWhile(t.Context(), v, false)
|
||||
start()
|
||||
if err := done(false); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
for _, stop := range []bool{false, true} {
|
||||
start, done := resolveWhile(t.Context(), v, true)
|
||||
start()
|
||||
start() // once, however many images build
|
||||
if err := done(stop); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
// Nothing built, so nothing started: done has nothing to wait for,
|
||||
// and the launch resolves in the foreground (Files).
|
||||
if _, done := resolveWhile(t.Context(), v, true); done(false) != nil {
|
||||
t.Error("done without a start failed")
|
||||
}
|
||||
if len(said) != 0 {
|
||||
t.Errorf("said %q: the lock was there, so nothing resolved", said)
|
||||
}
|
||||
}
|
||||
|
||||
// held keeps what's said until release, in order, shows no status line
|
||||
// and asks nothing, refusing each question as without a terminal; once
|
||||
// released, everything goes through.
|
||||
func TestHeld(t *testing.T) {
|
||||
var said, showed []string
|
||||
asked := false
|
||||
h := &held{Reporter: &msg.Fake{
|
||||
OnInfo: func(m msg.M) { said = append(said, "info "+m.ID()) },
|
||||
OnWarn: func(m msg.M) { said = append(said, "warn "+m.ID()) },
|
||||
OnStatus: func(m msg.M) { showed = append(showed, m.ID()) },
|
||||
OnAsk: func(msg.M) bool { asked = true; return true },
|
||||
Terminal: true,
|
||||
}}
|
||||
h.Info(msg.ResolvingTools())
|
||||
h.Warn(msg.ToolsNeedResolve())
|
||||
h.Status(msg.DownloadingMise("1"))()
|
||||
q := msg.ResolvingTools().AnsweredBy("--yes")
|
||||
if yes, err := h.Ask(q); yes || err == nil || asked {
|
||||
t.Errorf("Ask while held = %v, %v, asked %v: want it refused", yes, err, asked)
|
||||
}
|
||||
if _, err := h.Confirm(q); err == nil || asked {
|
||||
t.Errorf("Confirm while held = %v, asked %v: want it refused", err, asked)
|
||||
}
|
||||
if _, err := h.Answer(q); err == nil || asked {
|
||||
t.Errorf("Answer while held = %v, asked %v: want it refused", err, asked)
|
||||
}
|
||||
if len(said) != 0 || len(showed) != 0 {
|
||||
t.Fatalf("while held: said %q, showed %q", said, showed)
|
||||
}
|
||||
h.release()
|
||||
if want := []string{"info resolving_tools", "warn tools_need_resolve"}; !slices.Equal(said, want) {
|
||||
t.Errorf("released: said %q, want %q", said, want)
|
||||
}
|
||||
h.Info(msg.ResolvingTools())
|
||||
h.Status(msg.DownloadingMise("1"))()
|
||||
if yes, err := h.Ask(q); !yes || err != nil {
|
||||
t.Errorf("Ask once released = %v, %v", yes, err)
|
||||
}
|
||||
if len(said) != 3 || !slices.Equal(showed, []string{"downloading_mise"}) {
|
||||
t.Errorf("once released: said %q, showed %q", said, showed)
|
||||
}
|
||||
}
|
||||
|
||||
// A resolve still running when base's build ends, or when base was built
|
||||
// already and the build was quick, shows what it does from then on, under
|
||||
// a status line of its own while devvm waits for it.
|
||||
func TestResolveShowsAfterBuild(t *testing.T) {
|
||||
d := paths.Dirs{Data: t.TempDir(), Config: t.TempDir()}
|
||||
fifo := filepath.Join(t.TempDir(), "go")
|
||||
if err := syscall.Mkfifo(fifo, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var mu sync.Mutex
|
||||
var showed []string
|
||||
r := &msg.Fake{OnStatus: func(m msg.M) {
|
||||
mu.Lock()
|
||||
showed = append(showed, m.ID())
|
||||
mu.Unlock()
|
||||
if m.ID() == "resolving_tools" {
|
||||
// The stub mise goes on once devvm shows it waits.
|
||||
go func() {
|
||||
if f, err := os.OpenFile(fifo, os.O_WRONLY, 0); err == nil { //nolint:gosec // the test's own fifo
|
||||
_ = f.Close()
|
||||
}
|
||||
}()
|
||||
}
|
||||
}}
|
||||
env := tools.New(d, assets.FS, "0.1.0-test", r, platform.Host{})
|
||||
env.Mise = filepath.Join(t.TempDir(), "mise")
|
||||
if err := os.WriteFile(env.Mise, []byte("#!/bin/sh\nread x < "+fifo+"\nexit 1\n"), 0o700); err != nil { //nolint:gosec // a program: the resolve runs it
|
||||
t.Fatal(err)
|
||||
}
|
||||
// A resolve that never shows its wait ends with the test's deadline
|
||||
// rather than hang.
|
||||
ctx, cancel := context.WithTimeout(t.Context(), time.Minute)
|
||||
defer cancel()
|
||||
start, done := resolveWhile(ctx, tools.Versions{Env: env}, true)
|
||||
start()
|
||||
if err := done(false); err == nil || ctx.Err() != nil {
|
||||
t.Errorf("done = %v, context %v: want the resolve's failure", err, ctx.Err())
|
||||
}
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if !slices.Contains(showed, "resolving_tools") {
|
||||
t.Errorf("showed %q while devvm waited, want resolving_tools", showed)
|
||||
}
|
||||
}
|
||||
|
||||
// A resolve in the background says nothing while base builds: no status
|
||||
// line, and what it says waits for done, which says it once with its
|
||||
// failure; a resolve still running when done stops it ends at once.
|
||||
func TestResolveWhileQuiet(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
mise string // its script
|
||||
stop bool
|
||||
wantErr bool
|
||||
want []string // said, once done
|
||||
}{
|
||||
{name: "fails", mise: "exit 1", wantErr: true, want: []string{"resolving_tools"}},
|
||||
{name: "stopped while it runs", mise: "exec sleep 600", stop: true, want: []string{"resolving_tools"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
d := paths.Dirs{Data: t.TempDir(), Config: t.TempDir()}
|
||||
var mu sync.Mutex
|
||||
var said, showed []string
|
||||
r := &msg.Fake{
|
||||
OnInfo: func(m msg.M) { mu.Lock(); said = append(said, m.ID()); mu.Unlock() },
|
||||
OnStatus: func(m msg.M) { mu.Lock(); showed = append(showed, m.ID()); mu.Unlock() },
|
||||
}
|
||||
env := tools.New(d, assets.FS, "0.1.0-test", r, platform.Host{})
|
||||
env.Mise = filepath.Join(t.TempDir(), "mise")
|
||||
if err := os.WriteFile(env.Mise, []byte("#!/bin/sh\n"+tc.mise+"\n"), 0o700); err != nil { //nolint:gosec // a program: the resolve runs it
|
||||
t.Fatal(err)
|
||||
}
|
||||
start, done := resolveWhile(t.Context(), tools.Versions{Env: env}, true)
|
||||
start()
|
||||
mu.Lock()
|
||||
early, earlyShowed := slices.Clone(said), slices.Clone(showed)
|
||||
mu.Unlock()
|
||||
err := done(tc.stop)
|
||||
if (err != nil) != tc.wantErr {
|
||||
t.Errorf("done = %v, want an error %v", err, tc.wantErr)
|
||||
}
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if len(early) != 0 || len(earlyShowed) != 0 || !slices.Equal(said, tc.want) {
|
||||
t.Errorf("said %q and showed %q before done, %q after; want %q after alone", early, earlyShowed, said, tc.want)
|
||||
}
|
||||
// Stopped, it shows nothing; waited for, only its own wait.
|
||||
if slices.ContainsFunc(showed, func(s string) bool { return tc.stop || s != "resolving_tools" }) {
|
||||
t.Errorf("showed %q", showed)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
+162
-1
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
@@ -202,6 +203,154 @@ type newVM struct {
|
||||
history string
|
||||
}
|
||||
|
||||
// resolveWhile resolves the tools lock in the background, when want is
|
||||
// true, once start is called (Versions.Lock: at once when it has one),
|
||||
// downloading the host's mise first where it must, so a first run does
|
||||
// that while its image builds: start is called as an image starts to
|
||||
// build (build.Env.Building), and never when every image is built. It
|
||||
// says nothing while the build has the terminal: its messages wait for
|
||||
// done (held), it shows no status line, it asks nothing, and its
|
||||
// commands' lines in the run log are named for it (msg.WithLogTag). done
|
||||
// waits for it, cancelling it first when stop is true. Waited for, what
|
||||
// it held is said, and from then on it shows what it does, under
|
||||
// resolving_tools while devvm waits; it returns its error, said once, and
|
||||
// Files reads the lock it left rather than resolving again. Stopped, it
|
||||
// says what it held and returns nil. Never started, done returns nil, and
|
||||
// Files resolves in the foreground.
|
||||
func resolveWhile(ctx context.Context, v tools.Versions, want bool) (start func(), done func(stop bool) error) {
|
||||
if !want {
|
||||
return func() {}, func(bool) error { return nil }
|
||||
}
|
||||
ctx, cancel := context.WithCancel(msg.WithLogTag(ctx, "resolve"))
|
||||
h := &held{Reporter: v.Reporter}
|
||||
env := *v.Env
|
||||
env.Reporter = h
|
||||
var (
|
||||
once sync.Once
|
||||
started bool
|
||||
err error
|
||||
)
|
||||
ended := make(chan struct{})
|
||||
start = func() {
|
||||
once.Do(func() {
|
||||
started = true
|
||||
go func() {
|
||||
defer close(ended)
|
||||
_, err = tools.Versions{Env: &env}.Lock(ctx)
|
||||
}()
|
||||
})
|
||||
}
|
||||
return start, func(stop bool) error {
|
||||
defer cancel()
|
||||
once.Do(func() {}) // no start from now on
|
||||
if !started {
|
||||
return nil
|
||||
}
|
||||
if stop {
|
||||
cancel()
|
||||
<-ended
|
||||
h.release()
|
||||
return nil
|
||||
}
|
||||
h.release()
|
||||
select {
|
||||
case <-ended:
|
||||
default:
|
||||
wait := v.Status(msg.ResolvingTools())
|
||||
<-ended
|
||||
wait()
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// held is a Reporter for work beside another's on the terminal: until
|
||||
// release, what its messages say waits, it shows no status line, and it
|
||||
// refuses every question as devvm does without a terminal, so nothing it
|
||||
// asks lands over the other's. Once released, it says what it kept, in
|
||||
// order, and everything goes through.
|
||||
type held struct {
|
||||
msg.Reporter
|
||||
mu sync.Mutex
|
||||
kept []func()
|
||||
live bool
|
||||
// saying is held while what's kept is said, so nothing said once
|
||||
// released comes before it.
|
||||
saying sync.Mutex
|
||||
}
|
||||
|
||||
// keep runs f once released, or keeps it until then.
|
||||
func (h *held) keep(f func()) {
|
||||
h.mu.Lock()
|
||||
if !h.live {
|
||||
h.kept = append(h.kept, f)
|
||||
h.mu.Unlock()
|
||||
return
|
||||
}
|
||||
h.mu.Unlock()
|
||||
h.saying.Lock()
|
||||
defer h.saying.Unlock()
|
||||
f()
|
||||
}
|
||||
|
||||
// released reports whether release has run.
|
||||
func (h *held) released() bool {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
return h.live
|
||||
}
|
||||
|
||||
func (h *held) Info(m msg.M) { h.keep(func() { h.Reporter.Info(m) }) }
|
||||
func (h *held) Say(m msg.M) { h.keep(func() { h.Reporter.Say(m) }) }
|
||||
func (h *held) Note(m msg.M) { h.keep(func() { h.Reporter.Note(m) }) }
|
||||
func (h *held) Warn(m msg.M) { h.keep(func() { h.Reporter.Warn(m) }) }
|
||||
func (h *held) LogNote() { h.keep(h.Reporter.LogNote) }
|
||||
|
||||
// Status shows nothing until release: the work's own status line would
|
||||
// hide the one on the terminal.
|
||||
func (h *held) Status(m msg.M) func() {
|
||||
if !h.released() {
|
||||
return func() {}
|
||||
}
|
||||
return h.Reporter.Status(m)
|
||||
}
|
||||
|
||||
// Ask, Confirm and Answer refuse until release, as without a terminal.
|
||||
func (h *held) Ask(q msg.Question) (bool, error) {
|
||||
if !h.released() {
|
||||
return false, q.Refused(false)
|
||||
}
|
||||
return h.Reporter.Ask(q)
|
||||
}
|
||||
|
||||
func (h *held) Confirm(q msg.Question) (bool, error) {
|
||||
if !h.released() {
|
||||
return false, q.Refused(false)
|
||||
}
|
||||
return h.Reporter.Confirm(q)
|
||||
}
|
||||
|
||||
func (h *held) Answer(q msg.Question) (string, error) {
|
||||
if !h.released() {
|
||||
return "", q.Refused(false)
|
||||
}
|
||||
return h.Reporter.Answer(q)
|
||||
}
|
||||
|
||||
// release says what was held, in order, once, and lets everything through
|
||||
// from then on.
|
||||
func (h *held) release() {
|
||||
h.saying.Lock()
|
||||
defer h.saying.Unlock()
|
||||
h.mu.Lock()
|
||||
kept := h.kept
|
||||
h.kept, h.live = nil, true
|
||||
h.mu.Unlock()
|
||||
for _, f := range kept {
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
// creation makes a new VM: its plan, its build and its cleanup.
|
||||
type creation struct{ Launch }
|
||||
|
||||
@@ -227,7 +376,19 @@ func (e creation) create(ctx context.Context, o Options, f project.Folder, b bac
|
||||
if len(n.tools) > 0 && versions.CheckDue() {
|
||||
versions.Check(ctx)
|
||||
}
|
||||
if err := (build.Builds{Env: n.builder}).Build(ctx, n.img); err != nil {
|
||||
// The tools' versions resolve while its image builds, as neither
|
||||
// needs the other: from when an image starts to build, after the
|
||||
// build's questions, and in the foreground (Files) when every image
|
||||
// is built already.
|
||||
start, resolved := resolveWhile(ctx, versions, len(n.tools) > 0)
|
||||
n.builder.Building = start
|
||||
err = (build.Builds{Env: n.builder}).Build(ctx, n.img)
|
||||
n.builder.Building = nil
|
||||
if err != nil {
|
||||
_ = resolved(true) // stopped for the build's failure, which is said
|
||||
return err
|
||||
}
|
||||
if err := resolved(false); err != nil {
|
||||
return err
|
||||
}
|
||||
chain, err := n.builder.Chain(n.img)
|
||||
|
||||
Reference in new issue
Block a user