Skip to content

Installing extensions from command line #171

Closed

Description

@top-on

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?

Activity

  1. sr229 commented on Mar 11, 2019

    @sr229
    Contributor

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

  2. top-on commented on Mar 11, 2019

    @top-on
    Author

    @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.

  3. jeasonstudio commented on Mar 11, 2019

    @jeasonstudio
    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.

  4. top-on commented on Mar 11, 2019

    @top-on
    Author

    @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.

  5. jeasonstudio commented on Mar 12, 2019

    @jeasonstudio
    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
  6. top-on commented on Mar 12, 2019

    @top-on
    Author

    @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.

  7. faustomorales commented on Mar 17, 2019

    @faustomorales

    @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!

  8. yohancourbe commented on Mar 17, 2019

    @yohancourbe

    A lightweight alternative could be to use workspace recommended extensions

  9. sabrehagen commented on Mar 19, 2019

    @sabrehagen

    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?

  10. top-on commented on Mar 20, 2019

    @top-on
    Author

    @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 :-)

  11. coadler commented on Apr 20, 2019

    @coadler
    Contributor

    Resolved in #504

  12. jagraj commented on Jul 31, 2019

    @jagraj

    @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
    
  13. deansheather commented on Aug 2, 2019

    @deansheather
    Collaborator

    @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).

  14. top-on commented on Aug 2, 2019

    @top-on
    Author

    @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

  15. mirekphd commented on Nov 22, 2019

    @mirekphd

    @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).

  16. mirekphd commented on Nov 23, 2019

    @mirekphd

    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.
  17. nailson-landim commented on Jan 26, 2020

    @nailson-landim
  18. sanjayme97 commented on Apr 9, 2020

    @sanjayme97

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

  19. rahulkhanna2 commented on May 13, 2020

    @rahulkhanna2

    @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

  20. hgrattenthaler commented on Aug 15, 2024

    @hgrattenthaler

    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
    
  21. code-asher commented on Aug 16, 2024

    @code-asher
    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.

  22. hgrattenthaler commented on Aug 16, 2024

    @hgrattenthaler

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

  23. code-asher commented on Aug 16, 2024

    @code-asher
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSome improvement that isn't a feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions