VSCode Devcontainer Manager
Devcontainer Manager is a command line tool that manages Visual Studio Code
devcontainer configurations written in python.
Installation
Project can be installed using pip:
pip install devcontainer-manager
This installs command line utility devcontainer_manager
, see --help
option for
all available commands.
Usage
Configuration
First step is to create default master configuration with
devcontainer_manager create-template <config-path>
This creates yaml file with all available options set to default. You can then
open the file and change the options in editor.
If you specify config-path
without .yaml
suffix then it is considered
global template. Global templates are saved to
~/.devcontainer_manager/templates/<config-path>.yaml
and alias is created.
This can then be used in generate directly as config-path
, for example:
devcontainer_manager create-template python
# modify ~/.devcontainer_manager/templates/python.yaml
devcontainer_manager generate python
The following code displays all of the options and defaults
project_path: .
devcontainer:
name: '{{ project_root_basename }}'
workspace_folder: /mnt/workspace
workspace_mount: ${localWorkspaceFolder}:{{ devcontainer.workspace_folder }}
shutdown_action: none
user_env_probe: loginInteractiveShell
image: '{{ devcontainer.name }}-dev'
mounts: []
container_name: '{{ devcontainer.name }}'
container_hostname: '{{ devcontainer.name }}'
run_args: []
extensions: []
additional_options: []
docker:
file:
additional_commands: []
Note that you can use jinja2
templates in the config itself to reference other
options as displayed in container_name
and container_hostname
.
Pre-defined Variables
There are several variables that are calculated before generation and can be used
in your configs:
{{ project_root_basename }}: root directory of current project
{{ uid }}: id of current user
{{ login }}: username of current user
{{ hostname }}: hostname of current machine
Devconfig Generation
To generate the configuration
devcontainer_manager generate [config-paths]
Using default config, this would generate devcontainer.json
and overrides.yaml
(more in the Project Overrides section) files
(as docker.path is null by default).
If you specify more configs, then they are merged from left to right.
If config-paths is not specified then .devcontainer/overrides.yaml
is used for
generation if it exists.
Global Configuration
Global configuration can be found in ~/.devcontainer_manager/config.yaml
and
contains following options:
base_config: []
template_dir: templates
override_config_path: .devcontainer/overrides.yaml
default_config_path: '{{ template_dir }}/default.yaml'
Per Project Template Overrides
To edit overrides, you can manually edit generated .devcontainer/overrides.yaml
.
Once the overrides exist, you can then call each subsequent generation using
devcontainer_manager generate
This is also useful for easy generation when the master template changes.