cirruslabs / orchard

Orchestrator for running Tart Virtual Machines on a cluster of Apple Silicon devices
Other
194 stars 16 forks source link

VM Restart Policy #68

Closed fkorotkov closed 1 year ago

fkorotkov commented 1 year ago

Let's introduce a RestartPolicy filed for a VM so users can customize what happens when a startup script fails for example. I propose to have 3 options:

  1. Never - same behaviour as right now. A VM just goes into Failed status.
  2. Always - just starts VM and runs the startup script again.
  3. AlwaysErase - deletes the existing VM, clones it again and runs it.

Let's also make sure startup scripts have some predefined environment variables like ORCHARD_WORKER_NAME, TART_IMAGE and ORCHARD_VM_NAME/ORCHARD_VM_UID.

I see one major AlwaysErase use case: running ephemeral CI workers that are getting recreated after every job.

orchard create vm --image ghcr.io/cirruslabs/macos-ventura-base:latest \
    --restart-policy=AlwaysErase \
    --startup-script=@startupscript.sh \
    --env GITHUB_TOKEN=$GITHUB_TOKEN \
    worker-1

Where startupscript.sh looks like:

cd ~/actions-runner
./config.sh --url https://github.com/cirruslabs --name $ORCHARD_VM_NAME --labels "orchard,$TART_IMAGE" --token $GITHUB_TOKEN --ephemeral
./run.sh

exit 1 # so AlwaysErase restart policy will re-create the VM
kondratk commented 3 months ago

Hey @fkorotkov! I can see you've skipped AlwaysErase during the implementation. Is there any alternative to set up ephemeral vms, or it's not supported yet?