vscode-remote-release icon indicating copy to clipboard operation
vscode-remote-release copied to clipboard

code command not available in postcreatecommand when using devcontainers

Open GillesBallegeerVintecc opened this issue 2 years ago • 10 comments

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.

GillesBallegeerVintecc avatar May 23 '23 14:05 GillesBallegeerVintecc

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!

vscodenpa avatar May 23 '23 15:05 vscodenpa

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.

chrmarti avatar May 25 '23 07:05 chrmarti

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.

majian4work avatar Jul 17 '23 11:07 majian4work

any updates on this?

remchuk avatar Aug 29 '23 13:08 remchuk

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?

DirkWibben avatar Oct 18 '23 10:10 DirkWibben

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?

This issue is still present in the following versions:

VSCode: 1.84.2 Dev Containers: v0.321.0

Any news in this topic?

DirkWibben avatar Nov 21 '23 12:11 DirkWibben

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

chrmarti avatar Nov 24 '23 09:11 chrmarti

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?

image

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...

V-ed avatar Nov 24 '23 18:11 V-ed

@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

DirkWibben avatar Nov 27 '23 10:11 DirkWibben

still no official support?

AndreaRiboni avatar May 08 '24 09:05 AndreaRiboni