Skip to content

feat(vmm-cli)!: add compose --init-script, make update take a rendered compose - #1654

Merged
kvinwang merged 9 commits into
nextfrom
feat/vmm-cli-init-script
Nov 27, 2026
Merged

kvinwang merged 9 commits into
nextfrom
feat/vmm-cli-init-script

Conversation

@kvinwang

@kvinwang kvinwang commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

vmm-cli cannot set init_script; only the web UI can, so scripts that need one patch the generated app-compose.json with jq.

update also renders the compose a second time by patching the stored one, and that copy drifts from compose: --env-file re-reads the stored compose and drops the other edits.

Fix

compose --init-script PATH reads a script from a file and can be repeated. One script is written as a string with manifest_version: 2, which guests before 0.6.0 require; several are written as an array with manifest_version: "3", which the guest requires for an array.

Breaking: update --compose now takes the app-compose.json written by compose and sends it unchanged. update loses --prelaunch-script and --swap, and --env-file no longer rewrites allowed_envs but refuses variables the compose does not allow (NAME: spec entries match NAME) and an APP_LAUNCH_TOKEN that does not match its launch_token_hash. compose --env-file now also writes launch_token_hash. update-env and update-app-compose are removed; use update --env-file and update --compose. To change any of them, run compose again:

vmm-cli.py compose --name app --docker-compose compose.yaml \
  --init-script ./a.sh --init-script ./b.sh --env-file .env --kms \
  --output app-compose.json
vmm-cli.py update <vm-id> --compose app-compose.json --env-file .env --kms-url ...

Verification

pytest dstack/vmm/src/tests/test_vmm_cli.py, with new cases for the compose shape with zero, one and two scripts, and for update sending the compose unchanged with --env-file and refusing envs outside allowed_envs or a mismatched launch token. On a TDX host (dstack-0.6.5 guest, no KMS) composes with one and two scripts, and a stopped VM updated to three scripts with update --compose, boot and run the scripts in order before dockerd.

@kvinwang
kvinwang force-pushed the feat/vmm-cli-init-script branch from e5f8953 to a1ff012 Compare November 26, 2026 03:33
Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang
kvinwang force-pushed the feat/vmm-cli-init-script branch from a1ff012 to b67c22d Compare November 26, 2026 05:26
@kvinwang kvinwang changed the title feat(vmm-cli): add compose --init-script feat(vmm-cli): add --init-script to compose and update Nov 26, 2026

@Leechael Leechael left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on a TDX host: this PR's vmm-cli.py (b67c22d) against a 0.6.6 VMM, guest image the released dstack-0.6.5, no KMS, a fresh VM per case.

Case Compose written by the CLI Guest
one --init-script manifest_version: 2, init_script is a string boots; the script runs before dockerd, app starts
two --init-script manifest_version: 2, init_script is an array refuses to boot
same file, manifest_version hand-edited to "3" array boots; both scripts run in order, then dockerd and the app
--init-script <(echo ...) script text lands in the compose not booted

So a single script works, but repeating the option gives a compose the guest rejects. dstack-prepare fails with:

Error: Failed to verify app-compose policy
Caused by:
    multiple init scripts require manifest_version >= 3; use string manifest_version "3" so older guests fail closed

Neither script runs, the VM reboots into the same error and ends up exited after the VMM's 5 restart attempts. The third row shows the guest side is fine, only the version written by the CLI is wrong.

Details inline. The PR also adds no test; a case in UpdateVmTests / next to it in test_vmm_cli.py asserting the compose shape for one and for several scripts would have caught this.

Comment thread dstack/vmm/src/vmm-cli.py Resolved
Comment thread dstack/vmm/src/vmm-cli.py Resolved
Comment thread docs/vmm-cli-user-guide.md Resolved
update patched the stored compose itself, a second copy of the rendering
in `compose` that already drifted: several init scripts kept
manifest_version 2, which guests reject, and --env-file re-read the stored
compose and dropped the other edits.

update --compose now sends the app-compose.json written by `compose`
unchanged, and update loses --prelaunch-script, --init-script and --swap.
update --env-file only encrypts the variables; allowed_envs comes from
`compose --env-file`.

compose writes manifest_version "3" when given several init scripts.

Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang kvinwang changed the title feat(vmm-cli): add --init-script to compose and update feat(vmm-cli)!: add compose --init-script, make update take a rendered compose Nov 26, 2026
Both duplicate `update`: update-app-compose is `update --compose`, and
update-env rewrote allowed_envs and launch_token_hash in the stored
compose, the last copy of the compose rendering outside `compose`.

`compose --env-file` now writes launch_token_hash for APP_LAUNCH_TOKEN, and
`update --env-file` refuses variables the compose being deployed does not
allow instead of letting the guest drop them.

Signed-off-by: Kevin Wang <wy721@qq.com>
update --env-file compared env names with whole allowed_envs entries, so a
`NAME: spec` entry would refuse NAME. Compare the names only.

update --env-file also refuses an APP_LAUNCH_TOKEN whose hash differs from
the compose's launch_token_hash, which update-env used to rewrite.

Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang

Copy link
Copy Markdown
Collaborator Author

Thanks for the test. Addressed in 9608955, 6f61b87 and 65f0b01; the scope grew into a breaking change, see the updated description: update no longer renders the compose, it takes the one compose writes.

Re-tested on teepod2 (VMM 0.6.6, guest dstack-0.6.5, no KMS, fresh VM per case):

Case Compose Guest
one --init-script manifest_version: 2, string boots; script runs before dockerd, app starts
two --init-script manifest_version: "3", array boots; both run in order before dockerd, app starts
VM deployed --stopped with one script, update --compose with three, then started stored compose becomes "3", 3 scripts boots; all three run in order, app starts
update --env-file with a name outside allowed_envs, with and without --compose unchanged CLI refuses before any update

Not covered on a host: update --env-file encrypting through KMS.

Signed-off-by: Kevin Wang <wy721@qq.com>

# Conflicts:
#	CHANGELOG.md
Signed-off-by: Kevin Wang <wy721@qq.com>

@Leechael Leechael left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked at baa4849. The three points from my last review are resolved:

  • Regenerated the composes with the new CLI from the same inputs I booted before. Two scripts now give manifest_version: "3" plus an array, identical to the file that booted on the 0.6.5 guest except for name; one script is field-for-field identical to the one that booted. No need to boot again.
  • update sending the rendered compose unchanged removes the --env-file overwrite.
  • A docker-compose YAML passed to the new update --compose is rejected by the VMM (Invalid compose file), so the changed meaning of the flag fails loudly.

Two things about the new approach, inline: the compose hash changes for unchanged inputs when the env file has APP_LAUNCH_TOKEN, and the documented replacement for update-env also rewrites the VM's KMS URL list.

Tests: nothing asserts that an env-only update sends no compose_file, and the compose tests never pass an env file, so the new launch_token_hash write is uncovered.

Comment thread dstack/vmm/src/vmm-cli.py Resolved
deploy-to-vmm.sh sets launch_token_hash with jq after compose. jq keeps an
existing key in place, so writing it before pre_launch_script changed the
bytes, and so the compose hash, for unchanged inputs.

Signed-off-by: Kevin Wang <wy721@qq.com>
update --kms-url replaces the VM's KMS URLs, so using it to encrypt
--env-file, as update-env did, dropped the other URLs. --kms-encrypt-url,
as in deploy, only picks the KMS that encrypts the env.

Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang
kvinwang enabled auto-merge November 27, 2026 00:46
@kvinwang
kvinwang merged commit 16d366e into next Nov 27, 2026
23 checks passed
@kvinwang
kvinwang deleted the feat/vmm-cli-init-script branch November 27, 2026 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants