loft-sh / devpod

Codespaces but open-source, client-only and unopinionated: Works with any IDE and lets you use any cloud, kubernetes or just localhost docker.
https://devpod.sh
Mozilla Public License 2.0
8.76k stars 328 forks source link

Allow user input when starting container #968

Closed Hector-Work closed 5 months ago

Hector-Work commented 6 months ago

Is your feature request related to a problem?
Yes. Currently I am not able to execute scripts that request user input in any of the devcontainer commands (onCreateCommand, postCreateCommand, postAttachCommand, etc), because DevPod's output window does not accept input.

Which solution do you suggest?
Changing the output window to allow user input.

Which alternative solutions exist?
Running the scripts manually after the IDE has opened. I can't think of any simple way to do this automatically.

Additional context

Hector-Work commented 6 months ago

Presumably this line would need to be changed: https://github.com/loft-sh/devpod/blob/979c5467e99c980f6a252df390a003cbbc0f2fdc/desktop/src/components/Terminal/Terminal.tsx#L42C9-L42C27

pascalbreuninger commented 5 months ago

Hi @Hector-Work, thanks for the suggestion. We're hesitant to add this as it would prevent workspace from starting in environments where interactive shells aren't available by default, like browsers. Additionally, it would open up the workspace to shenanigans as users could run arbitrary commands, most likely as root.

Maybe if you explain you're problem a bit more we're able to find a solution without interactive shells?

Hector-Work commented 5 months ago

Hi @pascalbreuninger , thank you for your response. From your explanation I can see why it may not be desirable to use an interactive terminal.

However, there are situations when getting user input would be helpful. For instance, in my use case, I have a CLI tool that is run as part of the postAttachCommand. This tool asks for user input to customise the configuration and set up the workspace for their needs.

Maybe there is another way to do this?

pascalbreuninger commented 5 months ago

Yeah it's a bit of a blind spot of the spec imo. Two options I've seen being used in this scenario:

  1. If there arent' too many different configuration options, add multiple .devcontainer.json files for specific scenarios. They need to be in their own subdirectory of .devcontainer and then users can pick the ones they need by running devpod up $YOUR_REPO --devcontainer-path=".devcontainer/my-config/.devcontainer.json or passing the path as option in the Desktop App
  2. Provide a script users have to run manually after creating the workspace. It's a manual step but if it's only one it's usually manageable
Hector-Work commented 5 months ago

Thanks @pascalbreuninger. As you say, it is probably something missing from the devcontainer spec rather than devpod. I think I will have to go with your second suggestion and add something to the readme to say that the tool will have to be run manually.

Thanks again for your help.