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

Allow pre-installing VS code server and extensions in development Docker image #1718

Open
qdm12 opened this issue Oct 24, 2019 · 17 comments
Open
Labels
containers Issue in vscode-remote containers feature-request Request for new features or functionality

Comments

@qdm12
Copy link

qdm12 commented Oct 24, 2019

I use a custom built Docker image across multiple projects that contains a custom shell, OS packages and programming language related packages.

However, every time I use the container for a new project, it reinstall VS code server and all the VS code extensions described devcontainer.json which can be slow.

It would be a nice addition to allow VS code server to be pre-installed with some extensions in a Docker image, so that the boot up time for a new project would be minimal.

Thank you 👍 !

@qdm12
Copy link
Author

qdm12 commented Oct 24, 2019

It mentions how to workaround this here so I will close it for now.

@qdm12 qdm12 closed this as completed Oct 24, 2019
@qdm12
Copy link
Author

qdm12 commented Oct 26, 2019

Actually this workaround does not really answer ny question, how can I manually install VS code with some default extensions in the Docker image using the Dockerfile?

@qdm12 qdm12 reopened this Oct 26, 2019
@scp-r
Copy link

scp-r commented Nov 1, 2019

I also need this feature to build a instant development environment. Currently I have to manually install extensions through vscode remote ssh

@chrmarti chrmarti added feature-request Request for new features or functionality containers Issue in vscode-remote containers labels Nov 8, 2019
@Rossco8
Copy link

Rossco8 commented May 25, 2020

Agreed. A way to pre-install the dependencies into a container, e.g.
apt-get install vs-code-server

Would be very useful

@qdm12
Copy link
Author

qdm12 commented May 25, 2020

For the VScode server binary, as it's closed source, is there an url to the binary? For which cpu architectures? Is it compiled statically (i. e. does it work with musl instead of glibc)?

For extensions, if, at docker image build time, we put the vscode (non server) binary, install extensions with it, and then remove the binary, would these extensions be valid when used server side with the vscode server program?

Thanks!

@scp-r
Copy link

scp-r commented May 25, 2020

For the VScode server binary, as it's closed source, is there an url to the binary? For which cpu architectures? Is it compiled statically (i. e. does it work with musl instead of glibc)?

For extensions, if, at docker image build time, we put the vscode (non server) binary, install extensions with it, and then remove the binary, would these extensions be valid when used server side with the vscode server program?

Thanks!

code-server can install extensions via command line:

code-server --extensions-dir ~/.vscode/extensions \
    --install-extension <extension-id or vsix file>

@qdm12
Copy link
Author

qdm12 commented May 27, 2020

Nice thanks, that should solve it. I'll report back and close the issue if it fully does 👍

@RobertoDonPedro
Copy link

I also would appreciate a feature like apt-get install vs-code-server in order to be able to preinstall the vscode server with a Dockerfile.

Personally I think the main reasons for this approach would be:

  1. Installing the vscode server through the client at runtime seems to be way to slow.
  2. The /root/.vscode-server directory where the vscode server gets installed is not persistant in Kubernetes pods (by default) and gets deleted whenever the pod gets restarted

@qdm12
Copy link
Author

qdm12 commented Jun 26, 2020

There are multiple relatively easy ways to install code-server. I had a bit of trouble setting it up on alpine. In the end I use for example to pre-install shardulm94.trailing-spaces:

USER root
RUN apk add -q --update --progress --no-cache --virtual codeserverdeps npm build-base libx11-dev libxkbfile-dev libsecret-dev python2 && \
    npm install -g --unsafe-perm @google-cloud/logging@^4.5.2 code-server && \
    code-server --extensions-dir /home/myuser/.vscode-server/extensions --install-extension shardulm94.trailing-spaces && \
    chown -R myuser /home/myuser/.vscode-server
    apk del codeserverdeps && \
    rm -rf /usr/bin/code-server /usr/lib/node_modules /root/.npm /usr/local/share/.cache/yarn
USER myuser

So that it doesn't increase the image size with dependencies for code-server (node, c libs, etc.). This seems to fix the extensions pre-installing part, and doesn't increase the image size really (although it takes a while for the docker image to build). If there is a faster way to install extensions that would be great (maybe using node and npm/yarn only).

Now remains the vscode-server pre-install at docker build stage. I don't think code-server can replace the vscode server setup in ~/.vscode-server. Is there any solution to that perhaps? Or maybe a reason this shouldn't be pre-installed in the image (i.e. vscode versioning)?

Thanks!

EDIT: Actually for extensions made to work for remote development container, this approach does not work as it installs the 'client side' of the extension on the remote container, so there is something missing on the container side or on the host (client) side.

@gionapaolini
Copy link

gionapaolini commented Oct 27, 2020

Any news on this?
My use case is that I need to attach to containers running on Kubernetes (Dev environment).
Right now every time I attach to a new container I need to wait that vscode-server is installed and then I manually have to install the debugger extension.

Installing vscode-server directly in the image would be so much simpler.

@thoratou
Copy link

+1

@PavelSosin-320
Copy link

There are so many ways to create a multi-container backend stack for the IDE:

  • Docker stack using docker-compose file for Docker stack deploy
    Podman pod with master VSCode container and side-car extension for Podman pod play
    Kubernetes multi-container Pod for deployment using Docker stack deploy or kubectl.
    Helm chart to deploy Pod with containing everything plus Proxy, ingress, egress, and configuration for Helm 3.1 tillerless for Kubernetes deployment
    Openshift template
    Too complex and heavy containers contradict the main ideas of Docker: reusable images and effective resource management.
    Every extension added to the base image means an additional number of layers and will make the container slower and slower until full degradation.
    The same number of extensions running as separate containers will share 80% of memory and run dozens of times faster.
    The new OS-less UBI container images technology will reduce the additional memory footprint to about zero per extension.
    NodeJs UBI

@fmillion
Copy link

fmillion commented Dec 6, 2021

This gist allows you to preinstall the latest VS Code server commit into a container. I simply added the contents of the file as a script to the container and executed it as a RUN step. Only thing I noticed is for whatever reason my Ubuntu container balked at the [[ test, changing it to single square brackets fixed that.

The problem now is that I still can't preinstall server-side extensions.

(base) root@e3dc5274ca98:/# /root/.vscode-server/bin/ccbaa2d27e38e5afa3e5c21c1c7bef4657064247/bin/code --extensions-dir ~/.vscode-server/bin/*/extensions --install-extension shardulm94.trailing-spaces
Command is only available in WSL or inside a Visual Studio Code terminal.

So we're still stuck on how to preinstall extensions. Installing the code server does seem to work fine though, connecting to the SSH server from Code picked up the existing install and didn't redownload it.

@adholmgren
Copy link

adholmgren commented Feb 25, 2022

This gist allows you to preinstall the latest VS Code server commit into a container. I simply added the contents of the file as a script to the container and executed it as a RUN step. Only thing I noticed is for whatever reason my Ubuntu container balked at the [[ test, changing it to single square brackets fixed that.

The problem now is that I still can't preinstall server-side extensions.

(base) root@e3dc5274ca98:/# /root/.vscode-server/bin/ccbaa2d27e38e5afa3e5c21c1c7bef4657064247/bin/code --extensions-dir ~/.vscode-server/bin/*/extensions --install-extension shardulm94.trailing-spaces
Command is only available in WSL or inside a Visual Studio Code terminal.

So we're still stuck on how to preinstall extensions. Installing the code server does seem to work fine though, connecting to the SSH server from Code picked up the existing install and didn't redownload it.

If you take that gist and add the lines

export PATH="$PATH:/root/.vscode-server/bin/${commit_sha}/bin"
code-server --install-extension your-extension-eg-ms-python.python

You can get it going with some Dockerfile instructions like

FROM your_dev_image as vscode
RUN apt-get install -y curl
COPY ./download-vs-code-server.sh /home/workspace
RUN chmod +x /home/workspace/download-vs-code-server.sh
RUN /home/workspace/download-vs-code-server.sh

@fmillion
Copy link

If you take that gist and add the lines

export PATH="$PATH:/root/.vscode-server/bin/f80445acd5a3dadef24aa209168452a3d97cc326/bin"
code-server --install-extension your-extension-eg-ms-python.python

Thank you! Looks like all that happens is that if things fail to run from the PATH it assumes you're not in a VS Code terminal?

Only thing I'd do to improve it is change the hash in the path export to the variable that is set in the gist to pull the latest commit:

export PATH="$PATH:/root/.vscode-server/bin/${commit_sha}/bin"
code-server --install-extension your-extension-eg-ms-python.python

That future-proofs the script so it'll always work with the latest VS Code server commits.

@edumotya
Copy link

edumotya commented Jun 8, 2022

One caveat, your host VS Code must be updated, otherwise your VS Code will install the host version also inside the container when attaching VS Code to the container, and you will endup having two different VS code versions inside the container.

image

Here I had c35 (v1.67.2) installed from the Dockerfile as well as dfd (v1.66.2) installed by my host VS Code. Thus, my python extension installed from the Dockerfile for VS Code v1.67.2 was incompatible with my attached VS Code.

Finally, I updated my host VS Code and everything worked like a charm. Thank you all!

@discrimy
Copy link

discrimy commented Aug 1, 2023

I created a bash script to preinstall vscode extensions inside devcontainer image using temporary vscode server with extensions list extacted from devcontainer.json file. I believe it's some sort of a hack, but I hope it would be useful.

https://gist.github.com/discrimy/6c21c10995f1914cf72cd8474d4501b2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
containers Issue in vscode-remote containers feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests