-
Notifications
You must be signed in to change notification settings - Fork 183
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
improved devcontainer support? #520
Comments
First of all, I think it is necessary for you to understand the status of devcontainer (microsoft/vscode-dev-containers#1589). For a long time, devcontainer could only be handled from the proprietary vscode extension available only on Visual Studio Code, but Microsoft has recently moved this to an open source implementation. In parallel, they are working on implementing a feature called devcontainer features, which will add functionality on the containers. This is effectively a more generalized version of the Rocker Scripts that exist in this repository. For example, the contents of the script can be imported into any debian-based container by building devcontainer from the following json file. "name": "my-project-devcontainer",
"image": "rocker/tidyverse", // Any generic, debian-based image.
"features": {
"ghcr.io/devcontainers/features/common-utils:1": {
"version": "latest"
}
} As devcontainer featuers spread, shell scripts for installing any software should be able to be shared among arbitrary Debian base images, eliminating the need to add shell scripts in the repository for building containers on a dare. Also, in relation to devcontainer's move to OSS, it would make sense to move the R definition to the Rocker project, since https://github.com/microsoft/vscode-dev-containers is scheduled to be archived in the near future.
Yes, that is not necessary, see revodavid/devcontainers-rstudio#2. |
Thanks @eitsupi , this is super as always. Definitely helps to understand a bit more of the big picture goals Microsoft has with devcontainers, and glad to see they have open-sourced the project. (Though is the devcontainer.json yet consumed by any third-party tooling (i.e. outside of vscode / codespaces?) I think I understand and like their distinction between 'development' and 'production' containers in the overview page, but still not really sure I see quite how devcontainers fits within the larger ecosystem of building & orchestrating container-based workflows. Is a More immediately, I'd be happy to see the devcontainer R-definition move here if the existing container is to be archived. Thanks for linking that PR too, agree 💯 on that. I like @revodavid's example repo, but it feels like that repo has a size-able code base in it that could be moved upstream (e.g. here / part of the "R definition"), rather than be stuff every single repo needs to duplicate, right? |
If you want to know how to use devcontainer.json in general, it is also used in the RStudio IDE development. pandas has also included devcontainer.json in its repository for several years, making it available for use in development.
The Dev Container CLI is a stand-alone CLI tool.
This is very similar to compose file,
I haven't followed much discussion on this either (since I only use docker and docker compose), but if you look at https://github.com/microsoft/vscode-remote-release and https://github.com/devcontainers/spec you will find some discussions. At this stage it can only be combined with docker compose.
Yes, the files in that repository were copied and modified from https://github.com/microsoft/vscode-dev-containers (as is common usage).
Thanks! |
Thanks, this is all helpful. Right, I've noticed the delay in deploy, and also that each of these repos is building a 50+ line Dockerfile that, among other things, involves running a ~ 450 line debian-common.sh bash script. It seems that it would be desirable to have much of that install / config prebuilt into an upstream rocker container, both to achieve faster deploys and also to avoid duplicating code that could then diverge. Individual repos would I guess still contain a Dockerfile as well as the devcontainer.json file, but it could be one that was considerably more concise then, right? I guess the next step would be to bring the devcontainer R-definition in over here? |
Yes! But, I believe it is better to create a new repository. The downside of using the devcontainer CLI is that we can't use If we do not use the devcontainer CLI, we may need to copy this script directly from the GitHub repository for synchronization and use it for builds. In any case, I would be happy to try my own repository on how to do this and bring it to rocker-org after I have successfully done so. |
Here is a very early prototype. This can be used as a pre-built devcontainer by building and pushing it with the devcontainer cli. |
@cboettig We can now manage container configuration with json files, as in this repository, and GitHub Actions can build and push. Future, I am wondering if this can be brought to rocker-org. |
Thanks @eitsupi , this is great. All right with you to transfer the repo to rocker-org and see what we can do with it? Would it be possible to change the configuration such that the RStudio instance opens in the working directory of the cloned repository as an 'open project', thus allowing RStudio's git panel to also accurately reflect the github repo from which the devcontainer was launched? Currently I think that issue is the biggest ergonomic barrier to making the devcontainer practical for RStudio-based training events etc. |
👍
It appears that the default working directory can be changed by editing {
"initial_working_directory": "/workspaces"
} If this folder does not exist, it will fall back to However, the current rocker/rstudio uses an old configuration file, so rocker-versioned2/scripts/default_user.sh Lines 16 to 20 in 9423d18
Fortunately, RStudio started using the new configuration file in the |
Fantastic to see this conversation getting started. I have been using devcontainers for R-projects during the last year, and they are a gamechanger for onboarding collaborators with less Docker-experience. Just clone the repo using the remote-extension and you are up and running. Getting the working directory for RStudio to default to "postCreateCommand": "echo \"setwd('${containerWorkspaceFolder}')\" >> /usr/local/lib/R/etc/Rprofile.site" I struggled with permissions for saving files to this folder from RStudio, so I had to add chown -R rstudio ${containerWorkspaceFolder} This works fine in RStudio but breaks the git-integration in WSL2 (see microsoft/vscode-remote-release#6683 and devcontainers/cli#98), so I had to add: git config --global --add safe.directory ${containerWorkspaceFolder}" So it ends up being alot more ugly than it should be "postCreateCommand": "echo \"setwd('${containerWorkspaceFolder}')\" >> /usr/local/lib/R/etc/Rprofile.site && chown -R rstudio ${containerWorkspaceFolder} && git config --global --add safe.directory ${containerWorkspaceFolder}" Would love to hear if you have any experience with other approaches, @eitsupi My current .devcontainer.json-file for a shiny server looks like this: {
"name": "name",
"dockerFile": "Dockerfile",
"overrideCommand": false,
"postCreateCommand": "echo \"setwd('${containerWorkspaceFolder}')\" >> /usr/local/lib/R/etc/Rprofile.site && chown -R rstudio ${containerWorkspaceFolder} && git config --global --add safe.directory ${containerWorkspaceFolder}",
"build": { "args": { "LOCAL_DEVCONTAINER": "true"}},
"containerEnv": {
"DISABLE_AUTH": "true",
"ROOT": "true"
},
"extensions": [
"REditorSupport.r"
],
"appPort": [
"127.0.0.1:8787:8787",
"127.0.0.1:3838:3838"
]
} I prefer to have RStudio available in the devcontainter, but not when running deploying to the cloud. Hence, I add the ARG LOCAL_DEVCONTAINER
RUN if [ -n "$LOCAL_DEVCONTAINER" ] ; then /rocker_scripts/install_rstudio.sh ; fi Works great with the exception that it does not carry forward my local git credentials due to the issue above. |
Hi @thohan88, thanks to sharing that!
I was taking the approach of using docker compose as I wrote in this Japanese article. The config files look like these: {
"name": "rocker_rstudio",
"dockerComposeFile": [],
"service": "rstudio",
"workspaceFolder": "/home/rstudio/works",
"settings": {
"r.rterm.linux": "/usr/local/bin/radian",
"r.bracketedPaste": true,
"r.plot.useHttpgd": true,
"[r]": {
"editor.wordSeparators": "`~!@#%$^&*()-=+[{]}\\|;:'\",<>/?"
}
},
"extensions": ["REditorSupport.r"],
"shutdownAction": "none",
"remoteUser": "rstudio"
} services:
rstudio:
build:
context: ./.devcontainer
container_name: rocker_rstudio
ports:
- "8787:8787"
volumes:
- ./.rstudio_config:/home/rstudio/.config
- ./works:/home/rstudio/works Instead of changing RStudio's settings, we can set The downside of this approach is more configuration files and RStudio is always running and consuming resources... |
Now experimental docker image This image has {
"image": "ghcr.io/rocker-org/devcontainer/tidyverse:4",
"customizations": {
"vscode": {
"settings": {
"r.rterm.linux": "/usr/local/bin/radian",
"r.bracketedPaste": true,
"r.plot.useHttpgd": true,
"[r]": {
"editor.wordSeparators": "`~!@#%$^&*()-=+[{]}\\|;:'\",<>/?"
}
},
"extensions": ["reditorsupport.r", "rdebugger.r-debugger"]
}
},
"remoteUser": "rstudio"
} @cboettig Do you think you can close this in favor of https://github.com/rocker-org/devcontainer-images? |
definitely! closing in favor of further development under https://github.com/rocker-org/devcontainer-images |
Looking at the amazing work @eitsupi and @revodavid have done with devcontainer standard (particularly for deploy on codespaces, which looks rather promising in some contexts), I'm wondering if we should support more of that boilerplate here. Not sure if that would b best as an additional image in the stack or (probably better) an additional bash script in
rocker_scripts
that can bundle up at least some of the additional things that get added to the devcontainer Dockerfile and debian script.(There's also a lot in there I haven't quite wrapped my head around or am unsure about. e.g. see revodavid/devcontainers-rstudio#1, I'm not sure that we want to use separate users
vscode
andrstudio
on the same VM? seems to create a minor issue for git too?) Thoughts / ideas / objections welcome!The text was updated successfully, but these errors were encountered: