This little program is designed to address some limitations in air-gapped and proxy environments that currently occur due to partially missing proxy support in Visual Studio Code.
It allows for the installation of extensions in DevContainers, even when a proxy is involved, by downloading and installing them manually via Python's requests
library.
It's currently a work in progress, and complete offline installation is still missing (integrating it is a minor step), but it should be good enough to be used as "postAttachCommand"
in devcontainer.json
for environments where a proxy is involved and where automatic extension installation currently fails due to various errors.
It's a workaround for the following upstream issues in Visual Studio Code:
- #12588: Extension Proxy Support
- #29910: CLI Proxy Support
- How to make use of "code" cli command in postAttachCommand script
You can use this projects devcontainer.json
as a template or modify your Dockerfile
accordingly:
RUN pip install uvscem
(preferably after creating a virtual environment and a non-root user)
In your devcontainer.json
{
"postAttachCommand": "uvscem --config-file /path/to/devcontainer.json"
}
uVSCEM will then install (and update) all extensions listed in devcontainer.json
each time Visual Studio Code or the DevContainer is (re)started or rebuild.
Note
Ensure that your Dockerfile
(or container) contains Python 3.8 or later and pip, poetry, or pipx to install this package. Also, confirm that your PATH
variable includes the (virtual) environment where the package was installed into (or use poetry run uvscem
after installing it with poetry).
If you have a proxy (e.g. Cntlm) listening on localhost
it's best to add a line in your /etc/hosts
or C:\Windows\system32\drivers\etc\hosts
file (if you have the required admin permissions to do so):
127.0.0.1 localproxy
and configure VSCode to use that domain in (User) settings.json
.
{
"http.proxy": "http://localproxy:3128"
}
In your docker-compose.yml
you could then specify the following (this is already included in the devcontainer example in this repository):
extra_hosts:
- "host.docker.internal:host-gateway"
- "localproxy:host-gateway"
This way, some extensions within the DevContainer still got internet connectivity (if they are proxy aware). GitHub's CoPilot for example tries to use 127.0.0.1
from the host's user proxy configuration ("http.proxy":
) otherwise and unfortunately there's no possibility to configure that separately for the DevContainer.
- Jossef Harush Kadouri for this GitHub Gist on how to query the undocumented VisualStudio Code Marketplace API, which I used as blueprint for
api_client.py
. - Ian McKellar for his blog post "VSCode Remote and the command line" (notable mention: Lazy Ren@Stackoverflow for this answer pointing me in this direction).
- Michael Petrov for this answer on StackOverflow on how to test if a socket is closed in python.