Adding VSCode Extensions to your Code Ocean Capsule Environment

VSCode is a versatile workstation within Code Ocean with the ability to run and debug a multitude of languages and programs. The power of VSCode is supported primarily by the use of extensions, such as those used for Python debugging, Java debugging, and Jupyter notebook among others. If you install a package in the VSCode Cloud Workstation, it will not persist from session to session simply by that action. This document covers how to add extensions to a Code Ocean capsule environment so that whenever VSCode is opened, the extensions will be installed.

  1. Click Edit Post-Install Script in the Environment UI, at the bottom of the page, to create the file postInstall in the environment folder

Write a caption

2. Navigate to the postInstall file in the environment folder. There is an empty bash script.

An extension can be added to the environment. For this example a Python extension for VS Code is added.

3. Code Ocean uses a server version of VSCode, it is important to find the ID of the extension. This can be achieved by searching for the extension on the VSCode Marketplace. The webpage for the extension will display as below:

Write a caption

4. In Overview scroll down to More Info. Take note of the Unique Identifier.

For this example the unique identifier is ms-python.python.

5. Enter this codeblock into postInstall

if code-server --disable-telemetry --version; then
if [ ! -d "/.vscode/extensions" ]
    then
       echo "Directory /.vscode/extensions DOES NOT exists."
       mkdir -p /.vscode/extensions/
       fi
       
       code-server --disable-telemetry --extensions-dir=/.vscode/extensions --install-extension ms-python.python
       else
          echo "code-server not found"
       fi

Note the unique identifier is specified after the flag –install-extension. This is where in the code block you put the unique ID of the extension of choice. Should another extension need to be installed, repeat the code-server -install-extension command, with the new ID.

Note: If the author is not verified on the VSCode marketplace, difficulties installing the extension may be experienced.

When starting the VSCode up, under the Extensions tab, the extension will appear in Remote - Installed.

Last updated