Dev Containers

This outline covers the use of Dev Containers in the helixml/docs project.

Motivation

Dev Containers are used to provide a consistent and isolated development environment for the project. This approach ensures that all developers have the same tools and dependencies configured, regardless of their local machine setup.

Key Aspects

Dev Container Setup and Configuration

  • The Dev Container configuration is defined in the .devcontainer directory.
  • The devcontainer.json file defines the base image, extensions, and other settings for the development environment.
  • The Dockerfile defines the specific image that will be used for the Dev Container. This image includes the necessary tools, libraries, and dependencies for the project.

Using Dev Containers for Development and Testing

  • Developers can use the Dev Containers to run the project, build, test, and debug code.
  • The devcontainer.json file can be used to define specific tasks or commands that can be run within the container.
  • The Dev Container provides a dedicated environment for development and testing, ensuring that dependencies and configurations do not conflict with local machine settings.

Benefits of Using Dev Containers for Development

  • Consistent Development Environment: All developers work in the same environment, reducing potential issues related to conflicting dependencies or software versions.
  • Isolation: Dev Containers isolate the project dependencies and configurations from the host machine, preventing potential conflicts.
  • Reproducibility: The development environment is easily reproducible, allowing for consistent and reliable development across different machines.
  • Dependency Management: Dev Containers simplify dependency management, ensuring all required tools and libraries are available within the development environment.

Example:

devcontainer.json

{
            "name": "docs-dev-container",
            "image": "mcr.microsoft.com/devcontainers/base:debian",
            "features": {
              "github-codespaces": true
            },
            "extensions": [
              "ms-vscode.cmake-tools",
              "ms-azuretools.vscode-docker",
              "ms-vscode.cpptools",
              "ms-vscode.vscode-python",
              "ms-vscode.powershell"
            ],
            "postCreateCommand": "apt-get update && apt-get install -y curl && curl -sSL https://raw.githubusercontent.com/microsoft/vscode-dev-containers/v0.205.0/containers/features/python/3.10/x64/alpine/lib-python3.10-dev-build.sh | bash -s && pip install --upgrade pip && pip install pytest -y",
            "forwardPorts": [
              {
                "hostPort": 5555,
                "containerPort": 5555
              }
            ]
          }
          

Dockerfile

FROM mcr.microsoft.com/devcontainers/base:debian
          
          # Install required dependencies
          RUN apt-get update && apt-get install -y curl \
              && curl -sSL https://raw.githubusercontent.com/microsoft/vscode-dev-containers/v0.205.0/containers/features/python/3.10/x64/alpine/lib-python3.10-dev-build.sh | bash -s \
              && pip install --upgrade pip \
              && pip install pytest -y
          
          # Install project dependencies
          RUN pip install -r requirements.txt
          

This example demonstrates how the devcontainer.json file defines the base image, extensions, and other settings. The Dockerfile builds upon the base image to install necessary tools and project dependencies. The postCreateCommand in devcontainer.json configures the environment after container creation.

References