devspace-sh / devspace

DevSpace - The Fastest Developer Tool for Kubernetes ⚡ Automate your deployment workflow with DevSpace and develop software directly inside Kubernetes.
https://devspace.sh
Apache License 2.0
4.22k stars 353 forks source link

VSCode SSH on Windows doesn't work #2686

Open xgalaxy opened 11 months ago

xgalaxy commented 11 months ago

What happened? Using devspace dev and then connecting VS Code via SSH to launch editor does not work on Windows. Same exact project in MacOs works fine.

If I recreate the project using skaffold the Attach to Container option works fine on Windows or MacOs. Using Attach to Container for skaffold as they don't offer an easier way to connect like devspace does.

I am also able to connect via terminal just fine using either devspace or skaffold on Windows and MacOs.

What did you expect to happen instead? I expect that on Windows I should be able to launch VSCode into the container via SSH.

My devspace.yaml:

version: v2beta1
name: pulsarkube

# images:
#   account-persist:
#     image: account-persist
#     dockerfile: k8s/account_persist/Dockerfile
#     context: .

deployments:
  account-persist:
    kubectl:
      manifests:
        - k8s
      kustomize: true

dev:
  account-persist:
    imageSelector: account-persist
    devImage: golang:1.20-bookworm
    sync:
      - path: .:/app
        excludePaths:
          - '.git'
          - '.idea'
          - 'cmd'
          - 'k8s'
          - '!cmd/account_persist/'
    terminal:
      command: cmd/account_persist/start.sh
      workDir: /app
    ssh:
      enabled: true
    # proxyCommands:
    #   - command: devspace
    #   - command: kubectl
    #   - command: helm
    #   - gitCredentials: true

Local Environment:

FabianKramm commented 11 months ago

@xgalaxy thanks for reporting this issue! Strange what is the exact error you get from vscode?

xgalaxy commented 11 months ago

Normally I'd take this problem to VSCode SSH team. But it appears to be only an issue when devspace is involved. So I'm not sure whats going on? Anyway, here is some log output:

[14:14:16.682] Log Level: 2
[14:14:16.697] SSH Resolver called for "ssh-remote+account-persist.pulsarkube.devspace", attempt 1
[14:14:16.697] "remote.SSH.useLocalServer": false
[14:14:16.697] "remote.SSH.showLoginTerminal": false
[14:14:16.697] "remote.SSH.remotePlatform": {}
[14:14:16.697] "remote.SSH.path": undefined
[14:14:16.697] "remote.SSH.configFile": undefined
[14:14:16.697] "remote.SSH.useFlock": true
[14:14:16.698] "remote.SSH.lockfilesInTmp": false
[14:14:16.698] "remote.SSH.localServerDownload": auto
[14:14:16.698] "remote.SSH.remoteServerListenOnSocket": false
[14:14:16.698] "remote.SSH.showLoginTerminal": false
[14:14:16.698] "remote.SSH.defaultExtensions": []
[14:14:16.698] "remote.SSH.loglevel": 2
[14:14:16.698] "remote.SSH.enableDynamicForwarding": true
[14:14:16.698] "remote.SSH.enableRemoteCommand": false
[14:14:16.698] "remote.SSH.serverPickPortsFromRange": {}
[14:14:16.698] "remote.SSH.serverInstallPath": {}
[14:14:16.702] VS Code version: 1.81.0
[14:14:16.702] Remote-SSH version: remote-ssh@0.102.0
[14:14:16.702] win32 x64
[14:14:16.704] SSH Resolver called for host: account-persist.pulsarkube.devspace
[14:14:16.705] Setting up SSH remote "account-persist.pulsarkube.devspace"
[14:14:16.707] Using commit id "6445d93c81ebe42c4cbd7a60712e0b17d9463e97" and quality "stable" for server
[14:14:16.711] Install and start server if needed
[14:14:20.088] Checking ssh with "C:\WINDOWS\system32\ssh.exe -V"
[14:14:20.092] Got error from ssh: spawn C:\WINDOWS\system32\ssh.exe ENOENT
[14:14:20.093] Checking ssh with "C:\WINDOWS\ssh.exe -V"
[14:14:20.095] Got error from ssh: spawn C:\WINDOWS\ssh.exe ENOENT
[14:14:20.096] Checking ssh with "C:\WINDOWS\System32\Wbem\ssh.exe -V"
[14:14:20.099] Got error from ssh: spawn C:\WINDOWS\System32\Wbem\ssh.exe ENOENT
[14:14:20.099] Checking ssh with "C:\WINDOWS\System32\WindowsPowerShell\v1.0\ssh.exe -V"
[14:14:20.101] Got error from ssh: spawn C:\WINDOWS\System32\WindowsPowerShell\v1.0\ssh.exe ENOENT
[14:14:20.101] Checking ssh with "C:\WINDOWS\System32\OpenSSH\ssh.exe -V"
[14:14:20.228] > OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2

[14:14:20.233] Running script with connection command: "C:\WINDOWS\System32\OpenSSH\ssh.exe" -T -D 64234 "account-persist.pulsarkube.devspace" bash
[14:14:20.236] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[14:14:20.456] > ]0;C:\WINDOWS\System32\cmd.exe
[14:14:20.457] Got some output, clearing connection timeout
[14:14:20.518] > ad8bfd5da20f: running
[14:14:20.548] > Acquiring lock on /root/.vscode-server/bin/6445d93c81ebe42c4cbd7a60712e0b17d9463
> e97/vscode-remote-lock..6445d93c81ebe42c4cbd7a60712e0b17d9463e97
> Installing to /root/.vscode-server/bin/6445d93c81ebe42c4cbd7a60712e0b17d9463e97.
> ..
> ad8bfd5da20f%%1%%
[14:14:20.564] > Downloading with wget
[14:14:22.661] > Download complete
[14:14:22.692] > ad8bfd5da20f%%2%%
> tar --version:
> tar (GNU tar) 1.34
> Copyright (C) 2021 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.
> 
> Written by John Gilmore and Jay Fenlason.
[14:14:24.814] > Checking /root/.vscode-server/.6445d93c81ebe42c4cbd7a60712e0b17d9463e97.log and 
> /root/.vscode-server/.6445d93c81ebe42c4cbd7a60712e0b17d9463e97.pid for a running
>  server
> Running ssh connection command... /root/.vscode-server/bin/6445d93c81ebe42c4cbd7
> a60712e0b17d9463e97/bin/code-server --start-server --host=127.0.0.1 --accept-ser
> ver-license-terms --enable-remote-auto-shutdown --port=0 --telemetry-level all  
>  &> "/root/.vscode-server/.6445d93c81ebe42c4cbd7a60712e0b17d9463e97.log" < /dev/
> null
> printenv:
>        =/tmp/devspacehelper
>     KUBERNETES_SERVICE_PORT_HTTPS=443
>     KUBERNETES_SERVICE_PORT=443
>     HOSTNAME=account-persist-devspace-7984686967-md2kx
>     PWD=/go
>     HOME=/root
>     KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
>     VSCODE_AGENT_FOLDER=/root/.vscode-server
>     GOLANG_VERSION=1.20.7
>     SHLVL=1
>     KUBERNETES_PORT_443_TCP_PROTO=tcp
>     KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
>     KUBERNETES_SERVICE_HOST=10.96.0.1
>     KUBERNETES_PORT=tcp://10.96.0.1:443
>     KUBERNETES_PORT_443_TCP_PORT=443
>     PATH=/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr
> /bin:/sbin:/bin
>     GOPATH=/go
>     _=/usr/bin/printenv
>     OLDPWD=/root/.vscode-server/bin/6445d93c81ebe42c4cbd7a60712e0b17d9463e97    
> rm: cannot remove '/root/.vscode-server/.6445d93c81ebe42c4cbd7a60712e0b17d9463e9
> 7.token': No such file or directory
[14:14:24.835] > 
[14:14:24.881] > Spawned remote server: 716
> Waiting for server log...
[14:14:24.906] > 
> Waiting for server log...
[14:14:24.928] > 
[14:14:24.957] > Waiting for server log...
[14:14:24.988] > Waiting for server log...
[14:14:25.019] > Waiting for server log...
[14:14:25.082] >  
> *
> * Visual Studio Code Server
> *
> * By using the software, you agree to
> * the Visual Studio Code Server License Terms (https://aka.ms/vscode-server-lice
> nse) and
> * the Microsoft Privacy Statement (https://privacy.microsoft.com/en-US/privacyst
> atement).
> *
> 
[14:14:25.100] > ad8bfd5da20f: start
> SSH_AUTH_SOCK====
> DISPLAY====
> webUiAccessToken====
> listeningOn==43385==
> osReleaseId==debian==
> arch==x86_64==
> vscodeArch==x64==
> bitness==64==
> tmpDir==/tmp==
> platform==linux==
> unpackResult==success==
> didLocalDownload==0==
> downloadTime==2128==
> installTime==2144==
> extInstallTime====
> serverStartTime==261==
> connectionToken==1aa11aaa-aaaa-1aaa-1a11-111a11111a11==
> ad8bfd5da20f: end
[14:14:25.100] Received install output: 
SSH_AUTH_SOCK====
DISPLAY====
webUiAccessToken====
listeningOn==43385==
osReleaseId==debian==
arch==x86_64==
vscodeArch==x64==
bitness==64==
tmpDir==/tmp==
platform==linux==
unpackResult==success==
didLocalDownload==0==
downloadTime==2128==
installTime==2144==
extInstallTime====
serverStartTime==261==
connectionToken==1aa11aaa-aaaa-1aaa-1a11-111a11111a11==

[14:14:25.100] Remote server is listening on 43385
[14:14:25.100] Parsed server configuration: {"serverConfiguration":{"remoteListeningOn":{"port":43385},"osReleaseId":"debian","arch":"x86_64","webUiAccessToken":"","sshAuthSock":"","display":"","tmpDir":"/tmp","platform":"linux","connectionToken":"1aa11aaa-aaaa-1aaa-1a11-111a11111a11"},"downloadTime":2128,"installTime":2144,"serverStartTime":261,"installUnpackCode":"success"}
[14:14:25.104] Starting forwarding server. localPort 64256 -> socksPort 64234 -> remotePort 43385
[14:14:25.105] Forwarding server listening on 64256
[14:14:25.105] Waiting for ssh tunnel to be ready
[14:14:25.106] [Forwarding server 64256] Got connection 0
[14:14:25.107] Tunneled 43385 to local port 64256
[14:14:25.107] Resolved "ssh-remote+account-persist.pulsarkube.devspace" to "127.0.0.1:64256"
[14:14:25.119] ------

[14:14:25.121] > 
[14:14:25.127] [Forwarding server 64256] Got connection 1
[14:14:25.387] [Forwarding server 64256] Got connection 2
[14:14:29.128] Failed to write `remote.SSH.remotePlatform`: CodeExpectedError: Unable to write to User Settings because remote.SSH.remotePlatform is not a registered configuration.
[14:14:48.351] ------

[14:14:48.351] SSH Resolver called for "ssh-remote+account-persist.pulsarkube.devspace", attempt 2, (Reconnection)
[14:14:48.352] SSH Resolver called for host: account-persist.pulsarkube.devspace
[14:14:48.352] Setting up SSH remote "account-persist.pulsarkube.devspace"
[14:14:48.354] Using commit id "6445d93c81ebe42c4cbd7a60712e0b17d9463e97" and quality "stable" for server
[14:14:48.358] Install and start server if needed
[14:14:51.019] Running script with connection command: "C:\WINDOWS\System32\OpenSSH\ssh.exe" -T -D 64312 "account-persist.pulsarkube.devspace" bash
[14:14:51.022] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[14:14:51.232] > ]0;C:\WINDOWS\System32\cmd.exe
[14:14:51.233] Got some output, clearing connection timeout
[14:14:51.311] > 2cbb956f7ef6: running
[14:14:51.501] > Acquiring lock on /root/.vscode-server/bin/6445d93c81ebe42c4cbd7a60712e0b17d9463
> e97/vscode-remote-lock..6445d93c81ebe42c4cbd7a60712e0b17d9463e97
[14:14:51.517] > Found existing installation at /root/.vscode-server/bin/6445d93c81ebe42c4cbd7a60
> 712e0b17d9463e97...
> Checking /root/.vscode-server/.6445d93c81ebe42c4cbd7a60712e0b17d9463e97.log and 
> /root/.vscode-server/.6445d93c81ebe42c4cbd7a60712e0b17d9463e97.pid for a running
>  server
> Looking for server with pid: 716
[14:14:51.586] > Running ssh connection command... /root/.vscode-server/bin/6445d93c81ebe42c4cbd7
> a60712e0b17d9463e97/bin/code-server --start-server --host=127.0.0.1 --accept-ser
> ver-license-terms --enable-remote-auto-shutdown --port=0 --telemetry-level all  
>  &> "/root/.vscode-server/.6445d93c81ebe42c4cbd7a60712e0b17d9463e97.log" < /dev/
> null
> printenv:
>        =/tmp/devspacehelper
>     KUBERNETES_SERVICE_PORT_HTTPS=443
>     KUBERNETES_SERVICE_PORT=443
>     HOSTNAME=account-persist-devspace-7984686967-md2kx
>     PWD=/go
>     HOME=/root
>     KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443       
>     VSCODE_AGENT_FOLDER=/root/.vscode-server
>     GOLANG_VERSION=1.20.7
>     SHLVL=1
>     KUBERNETES_PORT_443_TCP_PROTO=tcp
>     KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
>     KUBERNETES_SERVICE_HOST=10.96.0.1
>     KUBERNETES_PORT=tcp://10.96.0.1:443
>     KUBERNETES_PORT_443_TCP_PORT=443
>     PATH=/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr
> /bin:/sbin:/bin
>     GOPATH=/go
>     _=/usr/bin/printenv
[14:14:51.594] > 
> Removing old logfile at /root/.vscode-server/.6445d93c81ebe42c4cbd7a60712e0b17d9
> 463e97.log
> Spawned remote server: 848
> Waiting for server log...
[14:14:51.610] > 
[14:14:51.626] > Waiting for server log...
[14:14:51.689] > Waiting for server log...
[14:14:51.719] > Waiting for server log...
[14:14:51.783] > Waiting for server log...
[14:14:51.812] > Waiting for server log...
[14:14:51.826] > 
[14:14:51.889] > Waiting for server log...
[14:14:51.996] >  
> *
> * Visual Studio Code Server
> *
> * By using the software, you agree to
> * the Visual Studio Code Server License Terms (https://aka.ms/vscode-server-lice
> nse) and
> * the Microsoft Privacy Statement (https://privacy.microsoft.com/en-US/privacyst
> atement).
> *
> 
> 2cbb956f7ef6: start
> SSH_AUTH_SOCK====
> DISPLAY====
> webUiAccessToken====
> listeningOn==43017==
> osReleaseId==debian==
> arch==x86_64==
> vscodeArch==x64==
> bitness==64==
> tmpDir==/tmp==
> platform==linux==
> unpackResult====
> didLocalDownload==0==
> downloadTime====
> installTime====
> extInstallTime====
> serverStartTime==399==
> connectionToken==1a111aaa-11a1-11aa-11aa-a111a111aa1a==
> 2cbb956f7ef6: end
[14:14:51.997] Received install output: 
SSH_AUTH_SOCK====
DISPLAY====
webUiAccessToken====
listeningOn==43017==
osReleaseId==debian==
arch==x86_64==
vscodeArch==x64==
bitness==64==
tmpDir==/tmp==
platform==linux==
unpackResult====
didLocalDownload==0==
downloadTime====
installTime====
extInstallTime====
serverStartTime==399==
connectionToken==1a111aaa-11a1-11aa-11aa-a111a111aa1a==

[14:14:51.997] Remote server is listening on 43017
[14:14:51.997] Parsed server configuration: {"serverConfiguration":{"remoteListeningOn":{"port":43017},"osReleaseId":"debian","arch":"x86_64","webUiAccessToken":"","sshAuthSock":"","display":"","tmpDir":"/tmp","platform":"linux","connectionToken":"1a111aaa-11a1-11aa-11aa-a111a111aa1a"},"serverStartTime":399,"installUnpackCode":""}
[14:14:51.998] Starting forwarding server. localPort 64321 -> socksPort 64312 -> remotePort 43017
[14:14:51.999] Forwarding server listening on 64321
[14:14:51.999] Waiting for ssh tunnel to be ready
[14:14:52.000] [Forwarding server 64321] Got connection 0
[14:14:52.000] Tunneled 43017 to local port 64321
[14:14:52.000] Resolved "ssh-remote+account-persist.pulsarkube.devspace" to "127.0.0.1:64321"
[14:14:52.003] ------

[14:14:52.012] > 
[14:14:52.013] [Forwarding server 64321] Got connection 1
[14:14:56.009] Failed to write `remote.SSH.remotePlatform`: CodeExpectedError: Unable to write to User Settings because remote.SSH.remotePlatform is not a registered configuration.
[14:15:27.020] ------

[14:15:27.020] SSH Resolver called for "ssh-remote+account-persist.pulsarkube.devspace", attempt 3, (Reconnection)
[14:15:27.022] SSH Resolver called for host: account-persist.pulsarkube.devspace
[14:15:27.022] Setting up SSH remote "account-persist.pulsarkube.devspace"
[14:15:27.023] Using commit id "6445d93c81ebe42c4cbd7a60712e0b17d9463e97" and quality "stable" for server
[14:15:27.024] Install and start server if needed
[14:15:29.227] Running script with connection command: "C:\WINDOWS\System32\OpenSSH\ssh.exe" -T -D 64406 "account-persist.pulsarkube.devspace" bash
[14:15:29.229] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[14:15:29.445] > ]0;C:\WINDOWS\System32\cmd.exe
[14:15:29.445] Got some output, clearing connection timeout
[14:15:29.537] > 8f0cbc15575a: running
[14:15:30.037] > Connection to localhost closed by remote host.
[14:15:30.037] > Connection to localhost closed by remote host.
[14:15:30.037] > Connection to localhost closed by remote host.
[14:15:31.320] "install" terminal command done
[14:15:31.323] Install terminal quit with output: Connection to localhost closed by remote host.
[14:15:31.626] "install" terminal command done
[14:15:31.626] Install terminal quit with output: Connection to localhost closed by remote host.
[14:15:31.937] "install" terminal command done
[14:15:31.938] Install terminal quit with output: Connection to localhost closed by remote host.
[14:15:31.938] Received install output: Connection to localhost closed by remote host.
[14:15:31.938] Failed to parse remote port from server output
[14:15:31.939] Resolver error: Error: 
    at m.Create (c:\Users\rblanchet\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:584145)
    at t.handleInstallOutput (c:\Users\rblanchet\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:582705)
    at t.tryInstall (c:\Users\rblanchet\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:681881)
    at async c:\Users\rblanchet\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:644110
    at async t.withShowDetailsEvent (c:\Users\rblanchet\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:647428)
    at async t.resolve (c:\Users\rblanchet\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:645160)
    at async c:\Users\rblanchet\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:720916
[14:15:31.942] ------
xgalaxy commented 11 months ago

Okay. On a whim I tried the VS Code sample you listed in your documentation that links to here: https://github.com/loft-sh/devspace-vscode-example/tree/main

And THIS works. So I'm not sure whats wrong with my configuration? The only things that look substantially different are:

xgalaxy commented 11 months ago

Okay. The key appears to be using helm deployment like as provided in the example. If I use my own deployment it doesn't work. So perhaps the component chart is opening up a port or an ingress or something that makes VSCode SSH work that doesn't normally happen?

That doesn't explain why my config would work on MacOs but not Windows though unless I change it to be like the example. Ideally the same config would work for both situations.

cakriwut commented 11 months ago

Hi @xgalaxy ,

I suspect the problem is caused by \r\n character in your script. Its little annoying when you are working with Windows. In order to test this , change terminal.command simply calling /bin/bash . If this work, then you need to handle special character from Windows before executing.

    terminal:
      command:  /bin/bash
xgalaxy commented 11 months ago

It's not the terminal section at all because I've had that section completely commented out when I've been trying to figure this out. The only two things that seem to make this 'magic' work on Windows is:

  1. having it be a helm deployment
  2. making sure command has this: command: ["sh", "-c", "tail -f /dev/null"]

If neither of the above are true then it simply does not work on Windows.

Also my gitattributes are setup for LF on linux files so I don't think \r\n characters are sneaking in somewhere.