<#4284 [Core feature] Vscode decorator to turn any...
# flyte-github
a
#4284 [Core feature] Vscode decorator to turn any python (
AutoContainer
) task to a vscode server
Issue created by ByronHsu Motivation: Why do you think this is important? When 1. The tasks fail and users want to debug them 2. Users start writing the task from scratch and want to develop in a container in k8s cluster (likely because only the cluster side has GPU) Flyte users might
time.sleep
the task,
ssh
inside, and develop/debug. However, using raw terminal to do so is cumbersome and unintuitive. For example, in multi-level directories structure or complex code base that need heavy navigation, users may feel pretty frustrated with the terminal environment. I propose that we can add a decorator as a flyte plugin and enable users to turn any tasks to vscode server in just one line. Goal: What should the final outcome look like, ideally?
@vscode
provides an simple way for users to run the task as a interactive vscode server with any image.
@vscode
is a decorator which users can put within
@task
and user function.
Copy code
@task
@vscode
def train():
    ...
By doing so, the task will install vscode dependencies and run a vscode server instead of the user defined functions. Also, it starts a exit handler which keeps polling the status of the heartbeat file and terminate if the server is idle for a set duration. This is very important because the pod is most likely using several GPU's, so we want to free them for other users. Heartbeat file can monitor the active connection to the code-server
As long as there is an active browser connection, code-server touches ~/.local/share/code-server/heartbeat once a minute. If you want to shutdown code-server if there hasn't been an active connection after a predetermined amount of time, you can do so by checking continuously for the last modified time on the heartbeat file. If it is older than X minutes (or whatever amount of time you'd like), you can kill code-server.
Copy code
def vscode(
    _task_function: Optional[Callable] =  None,
    max_idle_seconds: Optional[int] = 3600 * 24 * 2, # 2 days
    port: Optional[int] = 8001,
    enable: Optional[bool] = True,
    code_server_remote_path: str = "XXX",
    # The untarred directory name may be different from the tarball name
    code_server_dir_name: str = "YYY",
    plugins_remote_paths: List[str] = [
        "ZZZ",
        "KKK"
    ],
    pre_execute: Optional[Callable] = None,
):
    """
    vscode decorator modifies a container to run a VSCode server:
    1. Overrides the user function with a VSCode setup function.
    2. Download vscode server and plugins from remote to local.
    3. Launches and monitors the VSCode server.
    4. Terminates if the server is idle for a set duration.

    Parameters:
    - _task_function (function, optional): The user function to be decorated. Defaults to None.
    - max_idle_seconds (int, optional): The duration in seconds to live after no activity detected. 
    - port (int, optional): The port to be used by the VSCode server. Defaults to 8080.
    - enable (bool, optional): Whether to enable the VSCode decorator. Defaults to True.
    - code_server_remote_path (str, optional): The URL of the code-server tarball.
    - code_server_dir_name (str, optional): The name of the code-server directory.
    - plugins_remote_paths (List[str], optional): The URLs of the VSCode plugins.
    - pre_execute (function, optional): The function to be executed before the vscode setup function.
    """
Vscode example screenshot:

image▾

Describe alternatives you've considered Sleep the pod and ssh Propose: Link/Inline OR Additional context No response Are you sure this issue hasn't been raised already? ☑︎ Yes Have you read the Code of Conduct? ☑︎ Yes flyteorg/flyte