Repository navigation
feat(vmm-cli)!: add compose --init-script, make update take a rendered compose - #1654
Conversation
e5f8953 to
a1ff012
Compare
Signed-off-by: Kevin Wang <wy721@qq.com>
a1ff012 to
b67c22d
Compare
Leechael
left a comment
There was a problem hiding this comment.
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.
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>
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>
|
Thanks for the test. Addressed in 9608955, 6f61b87 and 65f0b01; the scope grew into a breaking change, see the updated description: Re-tested on teepod2 (VMM 0.6.6, guest
Not covered on a host: |
Signed-off-by: Kevin Wang <wy721@qq.com> # Conflicts: # CHANGELOG.md
Signed-off-by: Kevin Wang <wy721@qq.com>
Leechael
left a comment
There was a problem hiding this comment.
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 forname; one script is field-for-field identical to the one that booted. No need to boot again. updatesending the rendered compose unchanged removes the--env-fileoverwrite.- A docker-compose YAML passed to the new
update --composeis 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.
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>
Problem
vmm-clicannot setinit_script; only the web UI can, so scripts that need one patch the generatedapp-compose.jsonwithjq.updatealso renders the compose a second time by patching the stored one, and that copy drifts fromcompose:--env-filere-reads the stored compose and drops the other edits.Fix
compose --init-script PATHreads a script from a file and can be repeated. One script is written as a string withmanifest_version: 2, which guests before 0.6.0 require; several are written as an array withmanifest_version: "3", which the guest requires for an array.Breaking:
update --composenow takes theapp-compose.jsonwritten bycomposeand sends it unchanged.updateloses--prelaunch-scriptand--swap, and--env-fileno longer rewritesallowed_envsbut refuses variables the compose does not allow (NAME: specentries matchNAME) and anAPP_LAUNCH_TOKENthat does not match itslaunch_token_hash.compose --env-filenow also writeslaunch_token_hash.update-envandupdate-app-composeare removed; useupdate --env-fileandupdate --compose. To change any of them, runcomposeagain:Verification
pytest dstack/vmm/src/tests/test_vmm_cli.py, with new cases for the compose shape with zero, one and two scripts, and forupdatesending the compose unchanged with--env-fileand refusing envs outsideallowed_envsor a mismatched launch token. On a TDX host (dstack-0.6.5guest, no KMS) composes with one and two scripts, and a stopped VM updated to three scripts withupdate --compose, boot and run the scripts in order before dockerd.