VS Code Dev Containers integration with a host system
Project description
Introduction
dc2host
python package is intended to be used for interaction between VS Code running Dev Containers and other development tools that run on the host system (e.g. git difftool
etc).
It also contains a command line interface that can be used without VS Code just to open a source file from a local Git repository in GitLab/GitHub Web UI with the specified line number selected.
git difftool
example
Suppose you have your favorite GUI git difftool
configured to run from VS Code for the current file. This setup won't work when you start using Dev Containers because your host system is isolated from VS Code Server and file paths are different for what VS Code sees in a container and for what git difftool
sees on the host.
To resolve this problem dc2host
runs a simple REST server on the host that handles requests from Dev Containers and knows how to translate file paths to use them on the host.
Supported REST endpoints
run command
POST /run
{
"cwd": <container directory where from to execute the specified command>,
"args": ["command", "argument1", "argument2"],
"check": false|true - check for zero exit code
}
Example:
curl -d "{\"args\": [\"git\", \"difftool\", \"file/relative/path\"], \"cwd\": \"/workspace/directory\"}" -H "Content-Type: application/json" host.docker.internal:5000/run
open_in_browser command
Opens the specified file from a local repo in Web browser on GitHub/GitLab.
POST /open_in_browser
{
"file": <file path in a container directory>,
"lineNumber": <line number to highlight (optional)>
}
Example:
curl -d "{\"file\": \"file1.txt\", \"lineNumber\": 42}" -H "Content-Type: application/json" host.docker.internal:5000/run
Quick start
Open file "README.md" from a local directory on GitHub:
python -m dc2host open README.md
Run Flask on Windows host:
python -m flask --app dc2host.app run --debug --host=0.0.0.0
Configure VS Code "tasks.json"
{
"tasks": [
{
"label": "Open in GitHub/GitLab",
"type": "process",
"command": "curl",
"args": [
"-d",
"{\"file\": \"${file}\", \"lineNumber\": ${lineNumber}}",
"-H",
"Content-Type: application/json",
"host.docker.internal:5000/open_in_browser"
],
},
{
"label": "Diff current file",
"type": "process",
"command": "curl",
"args": [
"-d",
"{\"args\": [\"git\", \"difftool\", \"${fileBasename}\"], \"cwd\": \"${fileDirname}\"}",
"-H",
"Content-Type: application/json",
"host.docker.internal:5000/run"
],
},
{
"label": "History current file",
"type": "process",
"command": "curl",
"args": [
"-d",
"{\"args\": [\"gitk\", \"--\", \"${fileBasename}\"], \"cwd\": \"${fileDirname}\", \"check\": false}",
"-H",
"Content-Type: application/json",
"host.docker.internal:5000/run"
],
}
]
}
Configure VS Code "keybindings.json"
[
{
"key": "ctrl+k ctrl+d",
"command": "workbench.action.tasks.runTask",
"args": "Diff current file"
}
]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dc2host-1.0.0.tar.gz
.
File metadata
- Download URL: dc2host-1.0.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a75b482fe2305d95c587b7e92bdaaa5818be7125b35bd0fa7b1abc88b9e326c1 |
|
MD5 | 4665ee46fc0f2d482dafde12945ce149 |
|
BLAKE2b-256 | e884416ce4ea10527a20698b15dd4a4d9cee2503bc6ccba82612b3686df25671 |
File details
Details for the file dc2host-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: dc2host-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9eb242de775378a21ea3b9f26ea072c691c489f7b46fc2b922653e0c0bd7c10 |
|
MD5 | a7b32b868d37fc85c4f7c125319057d8 |
|
BLAKE2b-256 | 5e42866f35f29cd277fe2916b5294b34e915fa221034e53b90470d1f8fba0216 |