Using Visual Studio Code in Domino Workspaces




Overview

Some Domino Standard Environments support launching Visual Studio Code (VSCode) in interactive Workspaces. VSCode is an open-source multi-language editor maintained by Microsoft. Domino can serve the VSCode application to your browser with the power of code-server from Coder.com.

Prerequisites

VSCode support is available in the latest versions of the Domino Standard Environment:

Domino Standard Environment

  • quay.io/domino/standard-environment:ubuntu18-py3.8-r4.1-domino4.6

  • quay.io/domino/standard-environment:ubuntu18-py3.8-r4.1-domino4.6-gpu

  • quay.io/domino/standard-environment:ubuntu18-py3.8-r4.1-domino4.6-fuse

Domino Spark Environment

  • quay.io/domino/spark-environment:ubuntu18-py3.8-r4.1-domino4.6

  • quay.io/domino/spark-environment:ubuntu18-py3.8-r4.1-domino4.6-gpu

Domino Ray Environment

  • quay.io/domino/ray-environment:ubuntu18-py3.8-r4.1-domino4.6

  • quay.io/domino/ray-environment:ubuntu18-py3.8-r4.1-domino4.6-gpu

Domino Dask Environment

  • quay.io/domino/dask-environment:ubuntu18-py3.8-r4.1-domino4.6

  • quay.io/domino/dask-environment:ubuntu18-py3.8-r4.1-domino4.6-gpu

You can also find older style environments with vscode support if you would like to use an older version of Python or R:

  • Domino Analytics Distribution for Python 2.7

    • quay.io/domino/base:Ubuntu18_DAD_Py2.7_R3.5-20190501

  • Domino Analytics Distribution for Python 3.7

    • quay.io/domino/base:Ubuntu18_DAD_Py3.7_R3.5-20190501




Launching a VSCode Workspace

When using a VSCode-equipped Domino environment you can launch VSCode from the Workspaces Dashboard just as you would launch an RStudio or Jupyter workspace.

vscode_workspace_launch.png

If launched this way, your Workspace will open with the Domino controls around a VSCode editor. You can work with your project files in VSCode, and commit and sync with the Domino Workspace UI as normal.

Screen_Shot_2019-05-16_at_9.49.29_AM.png


You can also configure JupyterLab to have VSCode as an available notebook option. All of the environments listed above come with jupyter-server-proxy already installed, so you will only need to update your JupyterLab config to add a new notebook tile type. See Using Jupyter Server Proxy for more details on how to do this.

If launched this way, JupyterLab will open a new tab that will serve the VSCode application. This editor is running in the same Domino Run container as your JupyterLab application. However, the VSCode tab will not show the Domino Workspace controls. If you want to sync, commit, or stop your Workspace after working in VSCode, you must do so from the JupyterLab tab.




Installing VSCode extensions

You can use the extensions manager in VSCode to install extensions from the marketplace as you would usually. However, note that these extensions are installed only in the current Workspace session, and will not persist once the session is shut down.

Screen_Shot_2019-05-16_at_10.01.25_AM.png

To install persistent extensions that will be available in every new VSCode Workspace, you must build them into your environment. Use the following steps to set up such an environment.

  1. Find the extension you want to install in the Visual Studio Marketplace. In this example, we’ll install the scala-lang extension.


  2. Microsoft obscures the download URL for the extension by default, so you will need to first open your browser’s development tools, then click the Download extension link.

    Screen_Shot_2019-05-16_at_10.11.24_AM.png


  3. You can retrieve the download URL for the extension by looking at the request details in your browser’s development tools. It should end with /vspackage. Copy this URL for use in your custom environment.

    Screen_Shot_2019-05-16_at_10.14.00_AM.png


  4. In Domino, create a new environment. As the base image, you must use one of the VSCode-equipped Domino Standard Environments, listed in the prerequisites at the beginning of this article.

    Screen_Shot_2019-05-16_at_10.17.42_AM.png

  5. Add the following instructions to your new environment’s Dockerfile, replacing the folder names and example /vspackage URL with the extension URL you retrieved earlier. These commands download the extension, extract the required files, and adds them to the appropriate folder.

    USER root
    
    RUN apt-get update
    RUN apt-get install -y bsdtar
    RUN mkdir -p /home/ubuntu/.local/share/code-server/extensions/ms-python.python-2019.3.6558
    RUN cd /home/ubuntu/.local/share/code-server/extensions/ms-python.python-2019.3.6558
    RUN curl -JL https://marketplace.visualstudio.com/_apis/public/gallery/publishers/ms-python/vsextensions/python/2019.3.6558/vspackage | bsdtar -xvf - extension
    
    RUN cd /home/ubuntu/.local/share/code-server/extensions/ms-python.python-2019.3.6558/extension/ && mv * ../
    RUN chown ubuntu:ubuntu /home/ubuntu/.local/share/code-server/
    
    USER ubuntu
    
  6. When finished, click Build. Following a successful build you can use this new environment to launch VSCode Workspace sessions with your desired extensions already installed.




Installing VSCode

VSCode can be added to environments that don’t have it by adding the following to your compute environment. The base environment must be 2018-05-23 or newer.

You can add the following to your compute environment docker file instructions:

USER root

# Install VSCode (we install an older version so the python extension works)
RUN curl -fOL https://github.com/cdr/code-server/releases/download/v3.10.2/code-server_3.10.2_amd64.deb && \
    dpkg -i code-server_3.10.2_amd64.deb

# Add a VSCode start script
RUN mkdir -p /opt/domino/workspaces/vscode && \
    chown -R ubuntu:ubuntu /opt/domino/workspaces/vscode && \
    echo "#!/bin/bash" >> /opt/domino/workspaces/vscode/start && \
    echo "SETTINGS_DIR=\${DOMINO_WORKING_DIR}/.vscode" >> /opt/domino/workspaces/vscode/start && \
    echo "FILE=\${SETTINGS_DIR}/settings.json" >> /opt/domino/workspaces/vscode/start && \
    echo "# Add a user setting file if it doesn't exist. Add in DOMINO_WORKING_DIR so it persists across sessions" >> /opt/domino/workspaces/vscode/start && \
    echo "if [ ! -f \"\$FILE\" ]; then" >> /opt/domino/workspaces/vscode/start && \
    echo "sudo mkdir -p \"\${FILE%/*}\"" >> /opt/domino/workspaces/vscode/start && \
    echo "sudo chown -R ubuntu:ubuntu \${SETTINGS_DIR}" >> /opt/domino/workspaces/vscode/start && \
    echo "printf \"{" >> /opt/domino/workspaces/vscode/start && \
    echo "\t\\\"extensions.autoUpdate\\\": false," >> /opt/domino/workspaces/vscode/start && \
    echo "\t\\\"extensions.autoCheckUpdates\\\": false," >> /opt/domino/workspaces/vscode/start && \
    echo "\t\\\"python.pythonPath\\\": \\\"\$(which python)\\\"," >> /opt/domino/workspaces/vscode/start && \
    echo "\t\\\"workbench.startupEditor\\\": \\\"none\\\"," >> /opt/domino/workspaces/vscode/start && \
    echo "\t\\\"workbench.colorTheme\\\": \\\"Default Dark+\\\"" >> /opt/domino/workspaces/vscode/start && \
    echo "}\" > \${FILE}" >> /opt/domino/workspaces/vscode/start && \
    echo "fi" >> /opt/domino/workspaces/vscode/start && \
    echo "code-server \${DOMINO_WORKING_DIR} --user-data-dir \${SETTINGS_DIR} --auth none --bind-addr 0.0.0.0:8888 --extensions-dir \${HOME}/.local/share/code-server/extensions --disable-telemetry" >> /opt/domino/workspaces/vscode/start && \
    chmod +x /opt/domino/workspaces/vscode/start

USER ubuntu

Next, add the following to your compute environment’s Pluggable Workspace Tools:

vscode:
   title: "vscode"
   iconUrl: "https://raw.github.com/dominodatalab/workspace-configs/develop/workspace-logos/vscode.svg?sanitize=true"
   start: [ "/opt/domino/workspaces/vscode/start" ]
   httpProxy:
      port: 8888
      requireSubdomain: false