Running code server on gcp cloud shell gives error when previewing

688 Views Asked by At

I'm trying to run code-server on gcp cloud shell. I downloaded the following version

https://github.com/cdr/code-server/releases/download/v3.9.2/code-server-3.9.2-linux-amd64.tar.gz, which I think is the correct one, extracted the contents and ran

code-server --auth none

This gave the following output

[2021-04-06T00:53:21.728Z] info  code-server 3.9.2 109d2ce3247869eaeab67aa7e5423503ec9eb859
[2021-04-06T00:53:21.730Z] info  Using user-data-dir ~/.local/share/code-server
[2021-04-06T00:53:21.751Z] info  Using config file ~/.config/code-server/config.yaml
[2021-04-06T00:53:21.751Z] info  HTTP server listening on http://127.0.0.1:8080
[2021-04-06T00:53:21.751Z] info    - Authentication is disabled
[2021-04-06T00:53:21.751Z] info    - Not serving HTTPS

Now when I try Web Preview -> preview on port 8080 nothing happens I just get a blank screen and on the code console I see the following error

2021-04-06T00:50:04.470Z] error vscode Handshake timed out {"token":"e9b80ff7-10f9-4089-8497-b98688129452"}

I'm not sure what I need to do here ?

2

There are 2 best solutions below

0
On
  1. In cloud shell editor, create a file with .sh extension, and install the code-server by using these steps:

    export VERSION=`curl -s https://api.github.com/repos/cdr/code-server/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")'`
    
    wget https://github.com/cdr/code-server/releases/download/v3.10.2/code-server-3.10.2-linux-amd64.tar.gz
    
    tar -xvzf code-server-3.10.2-linux-amd64.tar.gz
    
    cd code-server-3.10.2-linux-amd64
    
  2. To run the vscode.sh file using terminal: ./vscode.sh

    If a warning “permission denied” comes, type chmod +x vscode.sh and then again proceed with running the file.

  3. To navigate to the folder: cd code-server-3.10.2-linux-amd64/

  4. To navigate to the bin: cd bin/

  5. To start the server : ./code-server --auth none --port 8080

Now you can see the VSCode IDE in your browser either by using web preview->preview on port 8080 option or the HTTP server link in your terminal.

3
On

My gut is saying that one must study this article (Expose code-server) in great detail. I think you will find that Code server is listening on IP address 127.0.0.1 at port 8080. Your thinking then is to access this server using Web Preview on port 8080 .... however ... pay attention to the IP addresses of your virtual machine. The IP address 127.0.0.1 is known as the loopback address. It is ONLY accessible to applications running on the SAME machine. My belief is that when you run Web Preview, you are trying to access the IP address of your Cloud Shell machine which is NOT 127.0.0.1.

If you read the above article, the story goes on to show how to use SSH forwarding to provide a front-end to whatever this application may be.