vscode-remote-release
vscode-remote-release copied to clipboard
code command not available in postcreatecommand when using devcontainers
Does this issue occur when all extensions are disabled?: Yes/No
Yes
- VS Code Version: 1.77
- OS Version: Ubuntu 22.04
Steps to Reproduce:
We use devcontainers for creating a consistent environment for our mono repository. In that repository we have a custom extension that runs our internal tooling. We would like to install the extension on container build such that the user always has the latest version when pulling the repository. For this we thought to run this script:
#!/bin/bash
cd "$(dirname "$0")"
npx vsce package
code --install-extension utils-0.0.1.vsix
in the postCreateCommand in the devcontainer.json
However we get this
line 6: code: command not found
In any other terminal we can run the code command, it seems we should be able to run this since it is after the container is created.
Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.78.2. Please try upgrading to the latest version and checking whether this issue remains.
Happy Coding!
Maybe running npx vsce package in the Dockerfile and listing the relative path to the vsix file in the devcontainer.json's "customizations"."vscode"."extensions" property would work.
We currently don't add code to the PATH.
If I open a new terminal, and echo $PATH, code is there. I checked bashrc, profile, /etc/profile, nothing was added.
I don't know who change my $PATH.
Could you tell me how I can use code --install-extension on postCreate.sh?
"customizations"."vscode"."extensions" can't be used for the conditional install.
any updates on this?
When I echo $PATH inside the postCreate.sh, I get
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/vscode/.local/bin
and code is not found.
But when I echo $PATH afterwards inside a terminal, I get
/vscode/vscode-server/bin/linux-x64/e7e037083ff4455cf320e344325dacb480062c3c/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/vscode/.local/bin
and code works as expected.
Additionally my colleagues and I are certain, that the usage of code inside postCreate.sh has worked in the past (earlier this year 2023), because we have used it successfully.
So what has changed in the behaviour of creating a DevContainer?
And can it get fixed shortly?
When I
echo $PATHinside the postCreate.sh, I get/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/vscode/.local/binand
codeis not found. But when Iecho $PATHafterwards inside a terminal, I get/vscode/vscode-server/bin/linux-x64/e7e037083ff4455cf320e344325dacb480062c3c/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/vscode/.local/binand
codeworks as expected. Additionally my colleagues and I are certain, that the usage ofcodeinside postCreate.sh has worked in the past (earlier this year 2023), because we have used it successfully. So what has changed in the behaviour of creating a DevContainer? And can it get fixed shortly?
This issue is still present in the following versions:
VSCode: 1.84.2 Dev Containers: v0.321.0
Any news in this topic?
We could add the server CLI to the PATH. The difficulty with the client CLI is that it needs a few environment variables set up to know how to reach VS Code and these are only available in the Integrated Terminal.
As a workaround you could try looking up the server CLI in your postCreate.sh, e.g.:
#!/bin/sh
alias code="$(ls ~/.vscode-server*/bin/*/bin/code-server* | head -n 1)"
code --help
code --install-extension /path/to/vsix
We could add the server CLI to the
PATH. The difficulty with the client CLI is that it needs a few environment variables set up to know how to reach VS Code and these are only available in the Integrated Terminal.As a workaround you could try looking up the server CLI in your
postCreate.sh, e.g.:#!/bin/sh alias code="$(ls ~/.vscode-server*/bin/*/bin/code-server* | head -n 1)" code --help code --install-extension /path/to/vsix
Can you be certain that the first entry will always be the latest code bin?
While it works in my case for now (as the GUID of 1a5daa3a0231a0fbba4f14db7ec463cf99d7768e in my case is the latest 1.84.2), it doesn't feel future proof to rely on GUID order for selecting the most recent code bin...
@chrmarti THX for the suggested solution. It started working in my case with the following adaption:
export code="$(ls ~/.vscode-server*/bin/*/bin/code-server* | head -n 1)"
$code --install-extension /path/to/vsix
@V-ed:
As long as code is just needed for adding extensions, I think, that any (even older) version of it will work.
Regards
still no official support?