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

Cannot run devcontainer-cli outside of its command folder (Possible fix)

Open plokko opened this issue 3 years ago • 5 comments

I can't say when it started or if it was after a devcontainer update or somethig else but devcontainer cli command stopped working from WSL. Now i'm testing it on version 0.295.0 but previous versions or pre-release still do not work.

The command devcontainer --help (or other commands) works fine inside Windows (in cmd) but hangs indefinitely in wsl console. I debugged the script and it works fine in WLS if i run inside devcontainer command folder (if i cd into '/mnt/c/Users//AppData/Roaming/Code/User/globalStorage/ms-vscode-remote.remote-containers/cli-bin/' folder that i got with which devcontainer).

I managed to make it work by adding a cd $basedir on line 47 (two lines before exit $? in wsl part of the final if)

I will write here my temporary, please do add a proper fix to this problem.

My temporary fix

#!/bin/sh
script_file=$0
while [ -h "$script_file" ]; do
        script_file=$(readlink $script_file)
done
basedir=$(dirname "$(echo "$script_file" | sed -e 's,\\,/,g')")

# This file is placed in a stable (version-independent) location
# and forwards to the currently installed version

# WSL detection borrowed from VS Code
IN_WSL=false
if [ -n "$WSL_DISTRO_NAME" ]; then
        # $WSL_DISTRO_NAME is available since WSL builds 18362, also for WSL2
        IN_WSL=true
else
        WSL_BUILD=$(uname -r | sed -E 's/^[0-9.]+-([0-9]+)-Microsoft.*|.*/\1/')
        if [ -n "$WSL_BUILD" ]; then
                IN_WSL=true
        fi
fi
VSCODE_PATH=$(cat "$basedir/vscode-path")
DEVCONTAINER_CLI_PATH=$script_file
REMOTE_CONTAINERS_PATH=
if [ -f "$basedir/remote-containers-path" ]; then
        REMOTE_CONTAINERS_PATH=$(cat "$basedir/remote-containers-path")
        if [ $IN_WSL = true ]; then
                REMOTE_CONTAINERS_PATH=$(wslpath -u $REMOTE_CONTAINERS_PATH)
        fi
        if [ ! -f "$REMOTE_CONTAINERS_PATH/dev-containers-user-cli/cli.js" ]; then
                REMOTE_CONTAINERS_PATH=
        fi
fi

if [ -z "$REMOTE_CONTAINERS_PATH" ]; then
        echo "Failed to determine Dev Containers path"
        exit 1
fi

if [ $IN_WSL = true ]; then
        export WSLENV="ELECTRON_RUN_AS_NODE/w:DEVCONTAINER_CLI_PATH/p:IN_WSL:WSL_DISTRO_NAME:$WSLENV"
        CLI=$(wslpath -m "$REMOTE_CONTAINERS_PATH/dev-containers-user-cli/cli.js")
        ELECTRON=$(wslpath -u "$VSCODE_PATH")

        # TODO - piping to `cat` is a temporary workaround for the CRLF->LF conversion
        # that occurs when calling Windows Electron binary from WSL
        cd $basedir
        IN_WSL=$IN_WSL DEVCONTAINER_CLI_PATH="$DEVCONTAINER_CLI_PATH" ELECTRON_RUN_AS_NODE=1 "$ELECTRON" --ms-enable-electron-run-as-node "$CLI" "$@" | cat
        exit $?
else
        ELECTRON="$VSCODE_PATH"
        CLI=$REMOTE_CONTAINERS_PATH/dev-containers-user-cli/cli.js
        DEVCONTAINER_CLI_PATH="$DEVCONTAINER_CLI_PATH" ELECTRON_RUN_AS_NODE=1 "$ELECTRON" --ms-enable-electron-run-as-node "$CLI" "$@"
        exit $?
fi

Original file

#!/bin/sh
script_file=$0
while [ -h "$script_file" ]; do
        script_file=$(readlink $script_file)
done
basedir=$(dirname "$(echo "$script_file" | sed -e 's,\\,/,g')")

# This file is placed in a stable (version-independent) location
# and forwards to the currently installed version

# WSL detection borrowed from VS Code
IN_WSL=false
if [ -n "$WSL_DISTRO_NAME" ]; then
        # $WSL_DISTRO_NAME is available since WSL builds 18362, also for WSL2
        IN_WSL=true
else
        WSL_BUILD=$(uname -r | sed -E 's/^[0-9.]+-([0-9]+)-Microsoft.*|.*/\1/')
        if [ -n "$WSL_BUILD" ]; then
                IN_WSL=true
        fi
fi
VSCODE_PATH=$(cat "$basedir/vscode-path")
DEVCONTAINER_CLI_PATH=$script_file
REMOTE_CONTAINERS_PATH=
if [ -f "$basedir/remote-containers-path" ]; then
        REMOTE_CONTAINERS_PATH=$(cat "$basedir/remote-containers-path")
        if [ $IN_WSL = true ]; then
                REMOTE_CONTAINERS_PATH=$(wslpath -u $REMOTE_CONTAINERS_PATH)
        fi
        if [ ! -f "$REMOTE_CONTAINERS_PATH/dev-containers-user-cli/cli.js" ]; then
                REMOTE_CONTAINERS_PATH=
        fi
fi

if [ -z "$REMOTE_CONTAINERS_PATH" ]; then
        echo "Failed to determine Dev Containers path"
        exit 1
fi

if [ $IN_WSL = true ]; then
        export WSLENV="ELECTRON_RUN_AS_NODE/w:DEVCONTAINER_CLI_PATH/p:IN_WSL:WSL_DISTRO_NAME:$WSLENV"
        CLI=$(wslpath -m "$REMOTE_CONTAINERS_PATH/dev-containers-user-cli/cli.js")
        ELECTRON=$(wslpath -u "$VSCODE_PATH")

        # TODO - piping to `cat` is a temporary workaround for the CRLF->LF conversion
        # that occurs when calling Windows Electron binary from WSL
        IN_WSL=$IN_WSL DEVCONTAINER_CLI_PATH="$DEVCONTAINER_CLI_PATH" ELECTRON_RUN_AS_NODE=1 "$ELECTRON" --ms-enable-electron-run-as-node "$CLI" "$@" | cat
        exit $?
else
        ELECTRON="$VSCODE_PATH"
        CLI=$REMOTE_CONTAINERS_PATH/dev-containers-user-cli/cli.js
        DEVCONTAINER_CLI_PATH="$DEVCONTAINER_CLI_PATH" ELECTRON_RUN_AS_NODE=1 "$ELECTRON" --ms-enable-electron-run-as-node "$CLI" "$@"
        exit $?
fi

Note: Opening the project with VsCode and then running "Open in devcontainer" always work but i do prefer running the command directly from the console as it's faster and i have a LOT of devcontainer projects.

plokko avatar Jun 19 '23 11:06 plokko

Sorry my bad, devcontainer --help works and devcontainer open does not hang like before and give some output (ex: "[457 ms] @devcontainers/cli 0.42.0. Node.js v16.17.1. win32 10.0.19045 x64.") but it does not open VsCode so it's still unfixed.

If i run from its folder it gives some additional feedback

/mnt/c/Users/Plokko/AppData/Roaming/Code/User/globalStorage/ms-vscode-remote.remote-containers/cli-bin$ ./devcontainer open /absolute/path-to-project
Failed to load user settings
Error: Failed to determine user settings path from: devcontainer
    at w4 (C:\Users\Plokko\.vscode\extensions\ms-vscode-remote.remote-containers-0.295.0\dev-containers-user-cli\dist\node\devContainersUserCLI.js:225:1702)
    at m4 (C:\Users\Plokko\.vscode\extensions\ms-vscode-remote.remote-containers-0.295.0\dev-containers-user-cli\dist\node\devContainersUserCLI.js:224:5092)
    at Object.handler (C:\Users\Plokko\.vscode\extensions\ms-vscode-remote.remote-containers-0.295.0\dev-containers-user-cli\dist\node\devContainersUserCLI.js:224:4430)
    at C:\Users\Plokko\.vscode\extensions\ms-vscode-remote.remote-containers-0.295.0\dev-containers-user-cli\dist\node\devContainersUserCLI.js:78:27299
    at Ms (C:\Users\Plokko\.vscode\extensions\ms-vscode-remote.remote-containers-0.295.0\dev-containers-user-cli\dist\node\devContainersUserCLI.js:78:23357)
    at wx.handleValidationAndGetResult (C:\Users\Plokko\.vscode\extensions\ms-vscode-remote.remote-containers-0.295.0\dev-containers-user-cli\dist\node\devContainersUserCLI.js:78:27282)
    at wx.applyMiddlewareAndGetResult (C:\Users\Plokko\.vscode\extensions\ms-vscode-remote.remote-containers-0.295.0\dev-containers-user-cli\dist\node\devContainersUserCLI.js:78:27902)
    at wx.runCommand (C:\Users\Plokko\.vscode\extensions\ms-vscode-remote.remote-containers-0.295.0\dev-containers-user-cli\dist\node\devContainersUserCLI.js:78:25645)
    at [runYargsParserAndExecuteCommands] (C:\Users\Plokko\.vscode\extensions\ms-vscode-remote.remote-containers-0.295.0\dev-containers-user-cli\dist\node\devContainersUserCLI.js:136:7269)
    at Fx.parse (C:\Users\Plokko\.vscode\extensions\ms-vscode-remote.remote-containers-0.295.0\dev-containers-user-cli\dist\node\devContainersUserCLI.js:134:1736)

plokko avatar Jun 19 '23 12:06 plokko

Same problem. It worked and one day it stopped... Give output:

"[782 ms] @devcontainers/cli 0.46.0. Node.js v16.17.1. win32 10.0.19045 x64."

but vscode does not open the project.

N1ebieski avatar Jul 18 '23 19:07 N1ebieski

I observe the same issue both on WSL and in Windows natively; the log line shows but VS Code is never opened.

PS C:\Users\conno\Github\js-debug-demos\node> cat .\.devcontainer\devcontainer.json
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/debian
{
        "name": "Debian",
        // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
        "image": "mcr.microsoft.com/devcontainers/base:bullseye",

        // Features to add to the dev container. More info: https://containers.dev/features.
        // "features": {},

        // Use 'forwardPorts' to make a list of ports inside the container available locally.
        // "forwardPorts": [],

        // Configure tool-specific properties.
        // "customizations": {},

        // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
        "remoteUser": "root"
}
PS C:\Users\conno\Github\js-debug-demos\node> devcontainer-insiders open ./
[259 ms] @devcontainers/cli 0.50.0. Node.js v16.17.1. win32 10.0.22621 x64.

connor4312 avatar Jul 27 '23 18:07 connor4312

Also seeing this

avdi avatar Mar 01 '24 15:03 avdi

I'm still seeing this too.

[235 ms] @devcontainers/cli 0.72.0. Node.js v20.18.1. win32 10.0.22631 x64.

isaacdlfabric avatar Dec 18 '24 15:12 isaacdlfabric