建议: exit_settings 内置选项和 --on-exit CLI 选项,用于自定义退出行为
作者: nicksieger创建于 2022年5月4日更新于 2026年9月13日
标签enhancement
This issue proposes to address the above issues and requests with a new Tiltfile builtin exit_settings() and CLI option --on-exit.
def exit_settings(
down: bool = False,
disable: bool = False,
delete_namespaces: bool = False,
callback: Function = None,
snapshot: Union[bool,str] = False,
)
"""Customize the behavior of `tilt up` or `tilt ci` when it exits (e.g., due to an interrupt or term signal).
By default, the behavior is to do nothing, leaving any existing k8s or Docker-compose resources running.
Args:
down: If true, execute the equivalent of `tilt down` at exit. The `Tiltfile` will be re-executed so that any `if config.tilt_subcommand == 'down':` conditional statements can be run. Mutually exclusive with `disable`: If both `down` and `disable` are true, `down` wins.
disable: If true, disable all resources at exit. The effect is similar to `down` except that the `Tiltfile` is not re-executed.
delete_namespaces: If true and one of `down` or `disable` is specified, delete any k8s namespaces that were created.
callback: a Starlark function to be executed at exit. Can be used to run custom logic and `local` commands. If `down` or `disable` are also specified, the callback function will be executed before resources are torn down.
snapshot: If true, Tilt will output a snapshot file named `tilt-snapshot-XXXXXX.json` at exit. If a string, represents a snapshot filename to save. A literal `%s` can be used in the pathname and will be replaced with a value that ensures the filename will be unique. CLI option --on-exit
A common flag --on-exit will be added to tilt up and tilt ci that allows specifying down, disable, delete_namespaces, or snapshot options.
内容来源: tilt-dev/tilt