Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Support defining "initializeCommand" specific to an operating system #3981

Closed
dslijepcevic opened this issue Nov 8, 2020 · 6 comments
Labels
containers Issue in vscode-remote containers feature-request Request for new features or functionality

Comments

@dslijepcevic
Copy link

dslijepcevic commented Nov 8, 2020

Since initializeCommand in devcontainer.json is executed locally, to make a dev container fully portable please make it possible to define it for every operating system like we can currently do for tasks. For example:

"windows": {
    "initializeCommand": "..."
},
"linux": {
    "initializeCommand": "..."
},
"osx": {
    "initializeCommand": "..."
}
@github-actions github-actions bot added the containers Issue in vscode-remote containers label Nov 8, 2020
@chrmarti chrmarti added the feature-request Request for new features or functionality label Nov 9, 2020
@PavelSosin-320
Copy link

PavelSosin-320 commented Dec 30, 2020

Dev-container is an OCI container. OCI container is always portable. It has no own OS, it is not a VM. Its OS is the Host machine OS. Of course, Container can't modify the Host OS or execute something on the Host OS because it shares it with all running containers. Only privileged containers may have limited access to the Host OS but working in such a mode is "security suicide". The container is initialized by entry-point script or executable, not by Initialize command. It is defaulted by Dockerfile and configured by --entry-point option. There is no way to know which OS is used as a base image of the running container - it is not a part of the container's metadata. The image OS is known only inside Dockerfile - it has FROM term in the 1st line. The only exception is Windows Containers that can be run only by Docker-for-Win - hardcode.
The Initialize command is executed on the local machine and has nothing with container portability.
Do you mean devcontainer.json portability?

@dslijepcevic
Copy link
Author

Dev-container is an OCI container. OCI container is always portable. It has no own OS, it is not a VM. Its OS is the Host machine OS. Of course, Container can't modify the Host OS or execute something on the Host OS because it shares it with all running containers. Only privileged containers may have limited access to the Host OS but working in such a mode is "security suicide". The container is initialized by entry-point script or executable, not by Initialize command. It is defaulted by Dockerfile and configured by --entry-point option. There is no way to know which OS is used as a base image of the running container - it is not a part of the container's metadata. The image OS is known only inside Dockerfile - it has FROM term in the 1st line. The only exception is Windows Containers that can be run only by Docker-for-Win - hardcode.
The Initialize command is executed on the local machine and has nothing with container portability.
Do you mean devcontainer.json portability?

Of course Docker container itself is portable, but I meant the whole VSCode's .devcontainer.json thing. Initialize command that is being run on the local machine is also a part of providing that portable environment. In particular, we use initialize command to fight the shortcomings of Remote Containers extension to provide a unique project name for Docker-compose based projects (see this), so we need to run different local scripts to generate the appropriate .env file on Linux, Windows and macOS. It cannot be a single shell script command because of Windows where you might not have WSL installed. We don't want to introduce external dependencies like Python, especially not for Windows. To do that in a clean and portable way we need OS overloads for initialize command just like tasks have them to execute a command on a local machine. Initialize command is no different than a local task in that regard. I'm just saying it's a real problem that has already been solved in VSCode and Remote Containers can just mirror it.

@jesec
Copy link

jesec commented Jan 30, 2021

I use something like this.

"source=${localEnv:HOME}/.docker,target=/home/vscode/.docker,type=bind",
"source=${localEnv:HOME}/.gnupg,target=/home/vscode/.gnupg,type=bind",
"source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=bind",
"source=${localEnv:HOME}/.git-credentials,target=/home/vscode/.git-credentials,type=bind",
"source=${localEnv:HOME}/.npmrc,target=/home/vscode/.npmrc,type=bind",
"source=${localEnv:HOME}/.zsh_history,target=/home/vscode/.zsh_history,type=bind"

However, another user/machine may not have the folders/files, and the mount will fail. So I use initializeCommand to create them if necessary:

umask 077 && mkdir -p ~/.docker ~/.gnupg ~/.ssh && umask 177 && touch ~/.git-credentials ~/.npmrc ~/.zsh_history

Obviously this will not work well on Windows.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
containers Issue in vscode-remote containers feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

5 participants
@dslijepcevic @chrmarti @jesec @PavelSosin-320 and others