code-server icon indicating copy to clipboard operation
code-server copied to clipboard

PlatformIO IDE extension does not work on code-server v3.0.1 from Docker Hub

Open r0zzy5 opened this issue 5 years ago • 26 comments

I am trying to install the PlatformIO IDE extension on a code-server v3.0.1 instance hosted in a docker container. I am running Docker Desktop on Windows 10 Pro and accessing code-server using Chrome 80. The extension seems to install fine using the extension manager in code-server, but when I try to open the PlatformIO Home tab, Chrome reports that 127.0.0.1:8010 did not send any data and therefore the PlatformIO Home page is not shown:

PlatformIO error

I am using the following Dockerfile:

FROM codercom/code-server:3.0.1

USER root

RUN apt-get update && apt-get install -y python3 python3-distutils \
	&& rm -rf /var/lib/apt/lists/*

USER coder

EXPOSE 8010

ENTRYPOINT ["dumb-init", "fixuid", "-q", "/usr/local/bin/code-server", "--host", "0.0.0.0", "--auth", "none", "."]

And the following docker-compose.yml:

version: '3.3'
services:
    code-server-platformio:
        image: r0zzy5/code-server-platformio
        ports:
            - '8080:8080'
            - '8010:8010'
        volumes:
            - './src:/home/coder/project'

r0zzy5 avatar Mar 23 '20 19:03 r0zzy5

I've had a quick look at this.

platformio starts a server listening on 127.0.0.1:8010. This is because it usually only needs to be accessible on the same machine when running on the desktop. The catch is that this can't be exposed by Docker, as Docker only maps through to non-loopback addresses.

platformio home supports a --host argument to get it to listen on another interface, so it can be started with --host=0.0.0.0 so that it can be exposed by Docker.

Not sure what the right fix is though. Should platformio know that it's running in a server environment, or should there be some special logic in code-server to handle it?

It'd be nice to get it working out of the box without any custom Dockerfiles involved.

x-cubed avatar Apr 04 '20 10:04 x-cubed

@x-cubed, I agree it would be best if this could "just work" without any custom Dockerfiles.

However for the time being, where would I configure my platformio home to launch using the --host argument?

r0zzy5 avatar Apr 07 '20 07:04 r0zzy5

We could fix this with the addition of our #1453 feature.

Thoughts @code-asher ?

kylecarbs avatar Apr 07 '20 15:04 kylecarbs

Yeah, seems like we could just access it at <domain>/proxy/8010. I didn't see an option for changing the URL it tries to open though so I'm not sure how we'd make that work. Maybe it's possible to detect a webview opening on 127.0.0.1:port and change it to the proxy domain instead.

code-asher avatar Apr 07 '20 17:04 code-asher

Just got this to run on my system will leave this for anyone it may help...

In the PIO terminal on code-server use the command 'pio home --host x.x.x.x --port 8010' where x.x.x.x is the IP of the docker then bridge the docker port to the host like @r0zzy5 showed. You should then have access to the PIO webgui through http://y.y.y.y:8010 where y.y.y.y is the docker host IP

justurn avatar May 27 '20 09:05 justurn

Any update on this?

plckr avatar Mar 18 '21 21:03 plckr

@ricreis394 do the solutions above not work for you? If not, we can take a look into this again.

jsjoeio avatar Mar 19 '21 16:03 jsjoeio

@jsjoeio when I click to open PlatformIO Home Page, the UI tries to load a frame which is pointer to 127.0.0.1:, which obviously cannot load.

The commands used in command line are as follows: pio home --host <internal_docker_ip> --port 8010 pio home --host localhost --port 8010

These 2 above loads something, but not completely, using the subsubdomain port like: 8010.code.example.com

plckr avatar Mar 19 '21 16:03 plckr

Ah okay! Hmm..I am not familiar with PlatformIO.

Would it be possible for you to provide reproduction steps using the latest version of code-server? If you need an example, look at our bug report template.

With that, I'd be happy to take a closer look for you.

jsjoeio avatar Mar 19 '21 17:03 jsjoeio

OS/Web Information

  • Web Browser: Google Chrome Version 89.0.4389.90 (Official Build) (64-bit)
  • Local OS: Windows 10
  • Remote OS: linuxserver (maybe alpine?)
  • Remote Architecture: x86-64
  • code-server --version: 3.9.1 e0203f2a36c9b7036fefa50eec6cf8fa36c5c015

Steps to Reproduce

  1. Have subsubdomain reverse proxy configuration for code-server, like <port>.code-server.example.com
  2. Install PlatformIO extension
  3. Go to PlatformIO sidebar section, click PIO Home -> Open

Expected

It should appear the PIO Home webpage

Actual

Appears 127.0.0.1 refused to connect.

Screenshot

platformio

Notes

when I click to open PlatformIO Home Page, the UI tries to load a frame which is pointer to 127.0.0.1:, which obviously cannot load.

The commands used in command line are as follows: pio home --host <internal_docker_ip> --port 8010 pio home --host localhost --port 8010

These 2 above loads something, but not completely, using the subsubdomain port like: 8010.code.example.com

This issue can be reproduced in VS Code: No

plckr avatar Mar 19 '21 23:03 plckr

Awesome! Thanks so much for the detailed repro steps @ricreis394 - we'll take a look at this in the next milestone/sprint!

EDIT: meant to tag you @ricreis394😅

jsjoeio avatar Mar 22 '21 17:03 jsjoeio

+1 to this issue.

The bug mentions a reverse proxy, but I don't think is necessary to repro. I can repro this behind my Traefik reverse proxy or at <server_local_ip>:port. I did not test whether localhost works because my server is headless.

I have a Dockerfile here that installs PlatformIO automatically and reproduces the issue.

tbhova avatar Mar 23 '21 01:03 tbhova

I've been struggling with the same issue for a while as well. What worked for me is quite a blunt method, but I've done a global replace for all occurrences of '127.0.0.1' in the platformio-core directory (/config/.platformio) with '0.0.0.0'. This together with the exposed 8010 port as in @tbhova's Dockerfile and fixing this port to that value in the platformio-ide settings (Platformio-ide: Pio Home Server Http Port) solved it for me.

Well, I wouldn't like say solved as it's a nuisance that there's no easy interface for setting the ip address to be used for communicating with the pio-core as part of the platformio extension...

RoboMagus avatar Mar 25 '21 10:03 RoboMagus

There is such a setting option in platformio.platformio-ide-2.3.2/package.json image

I tried it in docker and it worked

yqboy avatar Apr 23 '21 16:04 yqboy

That's awesome to hear - thanks for sharing @yqboy!

@RoboMagus let us know if you get a chance to try using that setting option and see if it fixes your issue

jsjoeio avatar Apr 23 '21 17:04 jsjoeio

That setting @yqboy mentions is actually a fix of mine that got merged ;) I'm working on getting it working behind a reverse proxy as well though...

RoboMagus avatar Apr 23 '21 19:04 RoboMagus

Oh HA! Totally missed it. Nice :D

Okay well keep us posted.

jsjoeio avatar Apr 23 '21 20:04 jsjoeio

Please explain me, What should i do to config code server with working platformIO. Now i use caddy, and don't know how to configure

utya avatar Jun 08 '21 07:06 utya

I currently use a Dockerfile as below to ensure the prerequisites are met for installing the PlatformIO plugin.

FROM ghcr.io/linuxserver/code-server

USER root

RUN apt-get update && \
    apt-get install -y --no-install-recommends python3 python3-distutils python3-dev python3-pip curl make && \
    apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Then ensure that the PlatformIO settings in VScode are set correctly. I.e. set the IP to 0.0.0.0 instead of 127.0.0.1, and make the port static. I have it set to 8010. Then make sure this port is exported when starting the docker container (docker run [...] -p 8010:8010 [...]).

Do note though that only one instance can be opened and linked to PIO at any given time, as only one port can be set to static and each new session requires it's own port.

RoboMagus avatar Jun 08 '21 09:06 RoboMagus

@RoboMagus make like this docker run -d
--name=code-server
-e PUID=1000
-e PGID=1000
-e TZ=Europe/London
-e PASSWORD=pass #optional
-e HASHED_PASSWORD= #optional
-e SUDO_PASSWORD=password #optional
-e SUDO_PASSWORD_HASH= #optional
-e PROXY_DOMAIN=domain #optional
-p 8443:8443
-p 8010:8010
-e DOCKER_MODS=linuxserver/mods:code-server-python3
-v /home/utya:/config
--restart unless-stopped
ghcr.io/linuxserver/code-server

change to 0.0.0.0, and doesn't work

utya avatar Jun 08 '21 12:06 utya

I'm was experiencing the same issues with effectively the same setup as @utya, except with a compose file. I also tried installing code-server without docker and had similar issues - with enough tinkering I was eventually able to access PIO directly at $LOCAL_IP:8010, but code-server refused to show anything in the extension window.

Just to be clear, my exact symptoms are:

  • Error message "127.0.0.1 refused to connect" when host was set to 127.0.0.1.
  • Black (blank?) frame when set to either $LOCAL_IP or 0.0.0.0
  • Occasionally seeing "Loading..." for a few seconds before the black frame - couldn't pin down what was changing to make that happen.
  • Setting the port to static or dynamic didn't seem to make a difference.
  • I had https enabled and working, and the strict SSL option was set to false.

rdotts avatar Jun 25 '21 05:06 rdotts

any progress? here I have this message at start, don't know if it is related to this issue: Error: Traceback (most recent call last): File "/root/.platformio/.cache/tmp/get-platformio-1.0.3.py", line 69, in main() File "/root/.platformio/.cache/tmp/get-platformio-1.0.3.py", line 61, in main bootstrap() File "/root/.platformio/.cache/tmp/get-platformio-1.0.3.py", line 47, in bootstrap pioinstaller.main.main() File "/root/.platformio/.cache/tmp/.piocore-installer-ksc1gu9y/tmp65x7o7wh/pioinstaller.zip/pioinstaller/main.py", line 131, in main File "/root/.platformio/.cache/tmp/.piocore-installer-ksc1gu9y/tmp65x7o7wh/pioinstaller.zip/click/core.py", line 1137, in call File "/root/.platformio/.cache/tmp/.piocore-installer-ksc1gu9y/tmp65x7o7wh/...

Error: Traceback (most recent call last): File "/root/.platformio/.cache/tmp/get-platformio-1.0.3.py", line 69, in main() File "/root/.platformio/.cache/tmp/get-platformio-1.0.3.py", line 61, in main bootstrap() File "/root/.platformio/.cache/tmp/get-platformio-1.0.3.py", line 47, in bootstrap pioinstaller.main.main() File "/root/.platformio/.cache/tmp/.piocore-installer-ksc1gu9y/tmp65x7o7wh/pioinstaller.zip/pioinstaller/main.py", line 131, in main File "/root/.platformio/.cache/tmp/.piocore-installer-ksc1gu9y/tmp65x7o7wh/pioinstaller.zip/click/core.py", line 1137, in call File "/root/.platformio/.cache/tmp/.piocore-installer-ksc1gu9y/tmp65x7o7wh/...

camelator avatar Oct 13 '21 10:10 camelator

any progress? here I have this message at start, don't know if it is related to this issue:

I am not familiar with this extension or how it works, but if you can write out full repro steps (assume I know nothing...), then I can take a look faster

jsjoeio avatar Oct 28 '21 18:10 jsjoeio

hi, I have found a solution, but I don't use Docker but Ubuntu directly but should be applicable to a Docker container. Since Platformio sits in an iframe it doesn't work properly if it doesn't refer to 127.0.0.1 I used a caddy server as a proxy and in the visx the pio home server starts at 0.0.0.0 but in the iframe it is taken from the package json and referring to https but always +50 ie the Pio server starts on port 8010 but in the iframe there is https: // IP: 8060 / session / so you can refer to 8010 via the caddy file and there is no mixed content. However, I took a static entry for the session key because I use several PCs. With a dynamic one, "Not found" was always displayed

hi, ich habe eine Lösung gefunden allerdings nutze ich keinen Docker sondern direkt Ubuntu sollte aber auf einen Docker Container anwendbar sein. Da Platformio in einen Iframe sitzt funktioniert es nicht richtig wenn es nicht auf 127.0.0.1 verweist ich habe einen Caddyserver als Proxy genutzt und in der visx startet der pio Home Server auf 0.0.0.0 aber im Iframe wird er eintrag aus der Package json genommen und auf https verwiesen jedoch immer +50 d.h. der Pio Server startet auf Port 8010 aber im Iframe steht dann https://IP:8060/session/ so kann man dann über die Caddyfile von 8060 auf 8010 verweisen und es ist kein gemischter Inhalt. Allerdings habe ich beim Sessionkey einen Statischen Eintrag genommen da ich mehrere PC's verwende bei einem Dynamischen kam immer "Not found"

Bildschirmfoto platformio-ide alpha.zip

chrishdx avatar Nov 20 '21 16:11 chrishdx

My dockerfile posted above has stopped working.

If I connect a terminal to the code-server container and run

cd /usr/lib/code-server
code-server --install-extension platformio.platformio-ide --force

I get the error logs:

Installing extensions...
Extension 'platformio.platformio-ide' not found.
Make sure you use the full extension ID, including the publisher, e.g.: ms-dotnettools.csharp
Failed Installing Extensions: platformio.platformio-ide

It looks like these code-server docs explain why MS' extension marketplace isn't used and suggest Open VSX.

PlatformIO has this tracking issue to add itself to Open VSX.

I'm going to continue following these issues, but I'm likely going to switch to a VSCode VM.

tbhova avatar Apr 10 '22 18:04 tbhova

Has anyone been able to get PlatformIO running in docker in code-server?

melwinek avatar May 24 '23 06:05 melwinek

Closing this out since from what I can tell, this is an extension issue? Instead of using 127.0.0.1 I think they need to use asExternalUri or something like that. But if there is something we need to change in code-server let me know and we can reopen.

It reproduces in Codespaces as well, so it does seem to be an issue with the extension and/or VS Code core.

code-asher avatar Jul 11 '24 23:07 code-asher