Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions packages/orchestrator/cmd/resume-build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func main() {
cmdPause := flag.String("cmd-pause", "", "execute command in sandbox, then pause on success")
cmdSignalPause := flag.String("cmd-signal-pause", "", "execute command in sandbox, then wait for SIGUSR1 before pausing")
optimize := flag.Bool("optimize", false, "collect fresh prefetch mapping after pause (resumes snapshot to record page faults)")
shell := flag.Bool("shell", false, "attach an interactive PTY shell via envd (no sshd required in the sandbox)")

flag.Parse()

Expand Down Expand Up @@ -125,6 +126,10 @@ func main() {
log.Fatal("-optimize is incompatible with -iterations (benchmarking doesn't upload)")
}

if *shell && (isCmdMode || isPauseMode || *iterations > 0) {
log.Fatal("-shell can only be used in interactive mode (no -cmd, no pause flags, no -iterations)")
}

// Generate new build ID if not specified and pause mode is enabled
outputBuildID := *toBuild
if isPauseMode && outputBuildID == "" {
Expand Down Expand Up @@ -159,7 +164,7 @@ func main() {
iterations: *iterations,
}

err := run(ctx, *fromBuild, *iterations, *coldStart, *noPrefetch, *noEgress, *verbose, pauseOpts, runOpts)
err := run(ctx, *fromBuild, *iterations, *coldStart, *noPrefetch, *noEgress, *verbose, *shell, pauseOpts, runOpts)
cancel()

if err != nil {
Expand Down Expand Up @@ -274,6 +279,7 @@ type runner struct {
cache *template.Cache
coldStart bool
noPrefetch bool
shell bool
config cfg.BuilderConfig
storage storage.StorageProvider
}
Expand Down Expand Up @@ -314,11 +320,23 @@ func (r *runner) interactive(ctx context.Context) error {

fmt.Printf("✅ Running (resumed in %s)\n", time.Since(t0))
fmt.Printf(" sudo nsenter --net=/var/run/netns/%s ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@169.254.0.21\n", sbx.Slot.NamespaceID())
fmt.Println("Ctrl+C to stop")

defer func() {
fmt.Println("🧹 Cleanup...")
sbx.Close(context.WithoutCancel(ctx))
}()

if r.shell {
err := attachShell(ctx, sbx)
if err != nil && !isShellExited(err) {
return err
}

return nil
}

fmt.Println("Ctrl+C to stop")
<-ctx.Done()
fmt.Println("🧹 Cleanup...")
sbx.Close(context.WithoutCancel(ctx))

return nil
}
Expand Down Expand Up @@ -959,7 +977,7 @@ func (r *runner) benchmark(ctx context.Context, n int) error {
return lastErr
}

func run(ctx context.Context, buildID string, iterations int, coldStart, noPrefetch, noEgress, verbose bool, pauseOpts pauseOptions, runOpts runOptions) error {
func run(ctx context.Context, buildID string, iterations int, coldStart, noPrefetch, noEgress, verbose, shell bool, pauseOpts pauseOptions, runOpts runOptions) error {
// Silence other loggers unless verbose mode
var l logger.Logger
if !verbose {
Expand Down Expand Up @@ -1122,6 +1140,7 @@ func run(ctx context.Context, buildID string, iterations int, coldStart, noPrefe
cache: cache,
coldStart: coldStart,
noPrefetch: noPrefetch,
shell: shell,
config: config.BuilderConfig,
storage: persistence,
sbxConfig: sbxCfg,
Expand Down
Loading
Loading