Skip to content

Installing extensions from command line #171

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

Closed
top-on opened this issue Mar 9, 2019 · 23 comments
Closed

Installing extensions from command line #171

top-on opened this issue Mar 9, 2019 · 23 comments
Labels
enhancement Some improvement that isn't a feature

Comments

@top-on
Copy link

top-on commented Mar 9, 2019

It would be great to be able to script the installation of extensions,
e.g. after starting code-server in a new container.

A feature similar to VScode's code --install-extension would be very helpful.
See the example here.

Or am I missing another way to install extensions to code-server from the command line?

@sr229
Copy link
Contributor

sr229 commented Mar 11, 2019

@ThorbenJensen have you tried using ext install <package name>?

@top-on
Copy link
Author

top-on commented Mar 11, 2019

@sr229
thank you for this idea - I have just tested it.
I have the feeling that ext install <package name> does not work outside the GUI/browser?
If I am mistaken, please let me know.

I would like to be able to install extensions from the command line - before accessing code-server in the browser.
I am looking for something like the VSCode feature of working with extensions from the command line.
How it is done in VSCode is also documented here.

@jeasonstudio
Copy link
Contributor

@ThorbenJensen I guess you want to pre-load some extensions before running.
yarn task build:copy-vscode in build/tasks.ts#171 may help.

@top-on
Copy link
Author

top-on commented Mar 11, 2019

@jeasonstudio I think this goes into the right direction, thank you.
Unfortunately, my javascript is not good enough to adapt build/tasks to my needs.

Is there anything I can do (e.g. yarn ... ) to install an extension after the pre-built container is running?
I would like to enter the running container from codercom/code-server, and run a command for installation of a package.

@foresthoffman foresthoffman added the enhancement Some improvement that isn't a feature label Mar 11, 2019
@jeasonstudio
Copy link
Contributor

@ThorbenJensen For now, you can just copy extension folder to $HOME/.code-server/extensions. It will work.

cp -r $HOME/.vscode-insiders/extensions/spywhere.guides-0.9.3 $HOME/.code-server/extensions/spywhere.guides-0.9.3

@top-on
Copy link
Author

top-on commented Mar 12, 2019

@jeasonstudio Thank you for the hint.
I suppose this is not an option for my situation, considering that I just want to pull and start the container.
At maximum, I would extend the Dockerfile.

Nonetheless, I will check out code-server again in a few months.
Very impressive and useful so far!

As far as I am concerned, this issue can be closed.
Of course you can leave it open, if you feel like implementing this feature down the road.

@faustomorales
Copy link

faustomorales commented Mar 17, 2019

@ThorbenJensen I think you can do this by just extending the Dockerfile as @jeasonstudio suggests.

For example, the following installs the Preview extension. I needed it because I couldn't get the built-in Preview functions to work out-of-the-box and also it comes with Mermaid diagram support, which the built-in previewer does not.

RUN apt-get update && apt install -y bsdtar curl
RUN mkdir -p /root/.local/share/code-server/extensions
RUN curl -JL https://marketplace.visualstudio.com/_apis/public/gallery/publishers/searKing/vsextensions/preview-vscode/2.0.3/vspackage | bsdtar -xvf - extension
RUN mv extension /root/.local/share/code-server/extensions/searKing.preview-vscode-2.0.3

The lines above do the following.

  1. Install bsdtar and curl. We install bsdtar because gnutar, which ships with Ubuntu and Debian, doesn't function properly with the archives we get from the Visual Studio web site.
  2. Create an extensions subdirectory for the code-server data directory. The data directory path above (/root/.local/share/code-server/) is the default from what I can tell. You can look at the logs to verify that it's the same with your configuration. You'll see something like INFO Initializing {"data-dir":"/root/.local/share/code-server","working-dir": ...,"log-dir": ...} when starting the container.
  3. Download and extract the extension file from the Visual Studio web site. The URL follows the form https://marketplace.visualstudio.com/_apis/public/gallery/publishers/<PUBLISHER>/vsextensions/<EXTENSION-NAME>/<VERSION>/vspackage. We only extract the extension folder.
  4. Move the extension folder to a properly named folder of the form <PUBLISHER>.<EXTENSION-NAME>-<VERSION> in the extensions subdirectory.

If all goes well, you should be able to get the following.

Screen Shot 2019-03-17 at 1 05 41 PM

Hope this helps!

@yohancourbe
Copy link

yohancourbe commented Mar 17, 2019

A lightweight alternative could be to use workspace recommended extensions

@sabrehagen
Copy link

A lightweight alternative could be to use workspace recommended extensions

This is currently not supported. What needs to be done to enable workspace extensions team?

@top-on
Copy link
Author

top-on commented Mar 20, 2019

@faustomorales great ideas, thanks a lot!
It appears that the extension folder in the container I extended from codercom/code-server is located at /root/.code-server/extensions.

So, heavily inspired by what you suggested, this is the Dockerfile that works for me:

FROM codercom/code-server
RUN apt-get update && apt-get -y upgrade

# VSCode extensions
RUN apt-get install -y bsdtar curl
RUN mkdir -p /root/.code-server/extensions
RUN curl -JL https://github.com/Microsoft/vscode-python/releases/download/2019.2.5558/ms-python-release.vsix | bsdtar -xvf - extension
RUN mv extension /root/.code-server/extensions/ms-python.python-vscode-2.0.3

CMD ["code-server", "--allow-http", "--no-auth"]

If anyone is interested in testing this Dockerfile:

$ sudo docker build . -t code-server-test
$ sudo docker run -p 8443:8443 -v "${PWD}:/root/project" code-server-test

Thanks, again :-)

@coadler
Copy link
Contributor

coadler commented Apr 20, 2019

Resolved in #504

@coadler coadler closed this as completed Apr 20, 2019
@jagraj
Copy link

jagraj commented Jul 31, 2019

@faustomorales great ideas, thanks a lot!
It appears that the extension folder in the container I extended from codercom/code-server is located at /root/.code-server/extensions.

So, heavily inspired by what you suggested, this is the Dockerfile that works for me:

FROM codercom/code-server
RUN apt-get update && apt-get -y upgrade

# VSCode extensions
RUN apt-get install -y bsdtar curl
RUN mkdir -p /root/.code-server/extensions
RUN curl -JL https://github.com/Microsoft/vscode-python/releases/download/2019.2.5558/ms-python-release.vsix | bsdtar -xvf - extension
RUN mv extension /root/.code-server/extensions/ms-python.python-vscode-2.0.3

CMD ["code-server", "--allow-http", "--no-auth"]

If anyone is interested in testing this Dockerfile:

$ sudo docker build . -t code-server-test
$ sudo docker run -p 8443:8443 -v "${PWD}:/root/project" code-server-test

Thanks, again :-)

@ThorbenJensen

I tried your dockerfile above and it fails to build and here is the output from the build.
I am getting permission denied. I want to install extension and could you please provide any reference to doc or Dockerfile which works.?

docker build . -t code-server-test
Sending build context to Docker daemon  2.048kB
Step 1/7 : FROM codercom/code-server
 ---> 9ea98ff48a65
Step 2/7 : RUN apt-get update && apt-get -y upgrade
 ---> Running in c57c1d8273f9
Reading package lists...
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
The command '/bin/sh -c apt-get update && apt-get -y upgrade' returned a non-zero code: 100

@deansheather
Copy link
Member

@jagraj The recommended way to install extensions now is to use code-server --install-extension <value>. You can give it the path to a .vsix file or the ID (looks like organization.extension-name).

@top-on
Copy link
Author

top-on commented Aug 2, 2019

@jagrag I can confirm that code-server --install-extension <value> is the new install mechanism that works. You see an example in the Dockerfile here:
https://github.com/ThorbenJensen/code-server-blueprint/blob/master/Dockerfile

@mirekphd
Copy link

mirekphd commented Nov 22, 2019

@jagraj The recommended way to install extensions now is to use code-server --install-extension <value>. You can give it the path to a .vsix file or the ID (looks like organization.extension-name).

Note that while it does work, it imposes a root requirement on the containerized system, iow VS Code now works only for root-owned containers. Trying to run it as non-root (e.g. docker run -u 1001) causes blank screen to be displayed in the browser instead of VS Code (which now works only for docker run -u 0 ). If you insert code-server --install-extension code in the root-owned part of the Dockerfile (before switch to non-root user, e.g. via USER coder), the extension would not be installed (would not be visible when running the container as a non-root user, here: coder with id 1001).

@mirekphd
Copy link

mirekphd commented Nov 23, 2019

RUN mkdir -p /root/.local/share/code-server/extensions

@faustomorales , I think the default location for VS extensions can be made more general to allow for non-root containers, thus:

USER username
RUN mkdir -p ~/.local/share/code-server/extensions

@deansheather , hard-coding root folder in the default extensions location may be the reason why the new code-server --install-extension option works only for containers run with root UID.

More info
In containers run under non-root users (required e.g. in Openshift) extensions are either not available to such users or VS Code fails to appear, displaying blank screen, depending on who installed the extension in the Dockerfile, root or standard user. More precisely, calling RUN code-server --install-extension in your Dockerfile:

  • imposes root requirement if it follows USER coder in the Dockerfile (-u 10001 switch no longer works, you need to use the default -u 0 to see the VS Code web interface) or
  • fails to install the extension (for non-root users) if it precedes USER coder in the Dockerfile.

@nailsonlinux
Copy link

Thanks @faustomorales!

@sanjayme97
Copy link

sanjayme97 commented Apr 9, 2020

above solutions are not working? any more solutions? @faustomorales @ThorbenJensen @coadler

@rahulkhanna2
Copy link

@sanjayme97 I needed a container for python data science running on EC2 with code-server up and running. This is my custom dockerfile which builds successfully

FROM python:3.7.7-slim

WORKDIR /home

RUN /bin/bash -c "apt-get update -y;apt-get install wget -y"

RUN wget https://github.com/cdr/code-server/releases/download/3.2.0/code-server-3.2.0-linux-x86_64.tar.gz
RUN tar -xzvf code-server-3.2.0-linux-x86_64.tar.gz

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

ENV PASSWORD=demo

CMD /bin/bash -c "./code-server-3.2.0-linux-x86_64/code-server --install-extension ms-python.python --force --install-extension ms-azuretools.vscode-docker --force && ./code-server-3.2.0-linux-x86_64/code-server --host 0.0.0.0 --port 8989" 

See if this works. extensions can be separated to a single run command too. But I have put this up hastly and haven't tested that approach

@hgrattenthaler
Copy link

Linking to this issue, this is still an issue. Some extensions are not found

root@5844681dad51:/build# code-server --install-extension ms-vscode.cpptools
Installing extensions...
Extension 'ms-vscode.cpptools' not found.
Make sure you use the full extension ID, including the publisher, e.g.: ms-dotnettools.csharp
Failed Installing Extensions: ms-vscode.cpptools

or if you try to install them from .vsix you get something like this

root@5844681dad51:/build# code-server --install-extension clang-tidy.vsix 
Installing extensions...
Error: End of central directory record signature not found. Either not a zip file, or file is truncated.
    at v (/usr/lib/code-server/lib/vscode/out/vs/server/node/server.main.js:106:2390)
    at /usr/lib/code-server/lib/vscode/out/vs/server/node/server.main.js:106:3833
    at /usr/lib/code-server/lib/vscode/node_modules/yauzl/index.js:40:7
    at /usr/lib/code-server/lib/vscode/node_modules/yauzl/index.js:190:5
    at /usr/lib/code-server/lib/vscode/node_modules/yauzl/index.js:712:5
    at /usr/lib/code-server/lib/vscode/node_modules/yauzl/fd-slicer.js:33:7
    at FSReqCallback.wrapper [as oncomplete] (node:fs:686:5) {
  code: 'Extract',
  name: 'Extract'
}
Failed Installing Extensions: file:///build/clang-tidy.vsix

@code-asher
Copy link
Member

code-server uses Open VSX for the extension marketplace and the cpptools extension is not on there so there is unfortunately nothing we can do about it. microsoft/vscode-cpptools#12269 (comment)

As for the extract error, that makes it seem very likely that the vsix is corrupted. Are you able to unzip it on the command line? Might need to download it again.

@hgrattenthaler
Copy link

Yes, bsdtar is able to unzip the file, however this does not seem to be what code-server uses, so it fails.

@code-asher
Copy link
Member

Oh interesting. I think VS Code is using https://github.com/thejoshwolfe/yauzl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Some improvement that isn't a feature
Projects
None yet
Development

No branches or pull requests