Link Search Menu Expand Document

Devcontainer

Devcontainer is a Visual Studio Code feature that enables to do development in Docker containers. Since IDE has native support for Docker-based development environments the usual drawbacks of such environments have been eliminated. The IDE will launch the necessary docker image that contains a comprehensive development environment, as well as will mount all the necessary volumes. Since the devcontainer configuration can be checked into the Git repo, it can be easily maintained in a team environment. The Docker host can be either the local machine (including Docker Desktop on macOS) or remote docker host (e.g. powerful cloud VM, or a server running in a private network).

Using devcontainer enabled projects

The Napkin Docker image uses VSCode devcontainer as a base. It is based on Ubuntu Hirsute and includes Napkin, Git, and other common utilities. If other tools are necessary, one can further extend by adding extra layers with Dockerfile as described in this document.

First, clone your Git repo as usual. Next, select “Reopen folder in container” when prompted. IDE will reload and open your project in a Docker-based environment with Napkin and other development tools available.

Configuring the devcontainer in a new project

If you have used napkin init to create your project all necessary files have already been created for you.

Minimal setup

Add .devcontainer.json file to the project root, then select “Reopen folder in Container”.

.devcontainer.json

{
  "name": "Napkin Project",
  "image": "soostone/napkin-exe",
  "settings": {
    "yaml.schemas": {"/usr/share/napkin/spec-schema.json": "spec*.yaml"}
  },
  "extensions": [
    "haskell.haskell",
    "redhat.vscode-yaml",
    "eamodio.gitlens",
    "ms-azuretools.vscode-docker",
    "shinichi-takii.sql-bigquery",
    "ms-ossdata.vscode-postgresql"
  ],
  "forwardPorts": [9901], // optional, can rely on auto forward, needed only for BigQuery
  "remoteUser": "napkin"
}

Advanced setup with extra development tools

Should extra development tools be necessary, you can extend your development environment by extending the Napkin image with extra layers. Remember to select “Rebuild container” whenever you update .devcontainer.json or Dockerfile. Please refer to the manual for more information.

.devcontainer.json

{
  "name": "Napkin Project",
  "build": {
    "dockerfile": "Dockerfile",
    "context": "../",
    // Update 'NAPKIN_DOCKER_TAG' to upgrade napkin
    "args": { "NAPKIN_DOCKER_TAG": "v1.2.3" }
  },

  // Set *default* container specific settings.json values on container create.
  "settings": {
    "yaml.schemas": {"/usr/share/napkin/spec-schema.json": "spec*.yaml"}
  },

  // Add the IDs of extensions you want to be installed when the container is created.
  "extensions": [
    "haskell.haskell",
    "redhat.vscode-yaml",
    "eamodio.gitlens",
    "ms-azuretools.vscode-docker",
    "shinichi-takii.sql-bigquery",
    "ms-ossdata.vscode-postgresql"
  ],
  // Use 'forwardPorts' to make a list of ports inside the container available locally.
  "forwardPorts": [9901],

  // Use 'postCreateCommand' to run commands after the container is created.
  // "postCreateCommand": "uname -a",

  // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
  "remoteUser": "napkin"
}

Dockerfile

ARG NAPKIN_DOCKER_TAG
FROM soostone/napkin-exe:$NAPKIN_DOCKER_TAG

## You can extend your development environment by installing extra packages from ubuntu
# RUN apt-get update && apt-get install -y extra-package
## Or from nixos
# RUN nix-env -f "<nixpkgs>" -iA extra-package