Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: code-server (run with docker) will always overwrite PATH variable #5621

Closed
4 tasks done
huweiATgithub opened this issue Oct 5, 2022 · 23 comments · Fixed by #5688
Closed
4 tasks done

[Bug]: code-server (run with docker) will always overwrite PATH variable #5621

huweiATgithub opened this issue Oct 5, 2022 · 23 comments · Fixed by #5688
Labels
bug Something isn't working triage This issue needs to be triaged by a maintainer
Milestone

Comments

@huweiATgithub
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

OS/Web Information

  • Remote OS: Ubunu
  • Remote Architecture: amd64
  • code-server --version: both v4.7.0 and v4.0.1 are tried

Steps to Reproduce

  1. In a machine with docker installed, run
    mkdir -p ~/.config
    docker run -it --name code-server -p 127.0.0.1:8080:8080 \
    -v "$HOME/.config:/home/coder/.config" \
    -v "$PWD:/home/coder/project" \
    -u "$(id -u):$(id -g)" \
    -e "DOCKER_USER=$USER"  -e "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/some/path" \
    codercom/code-server:latest
  2. Login to the browser, launch terminal in vscode and print the PATH echo $PATH
  3. Always get:

Expected

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/some/path with some extra paths appended by code-server.

Actual

/usr/lib/code-server/lib/vscode/bin/remote-cli:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

Logs

No response

Screenshot/Video

No response

Does this issue happen in VS Code or GitHub Codespaces?

  • I cannot reproduce this in VS Code.
  • I cannot reproduce this in GitHub Codespaces.

Are you accessing code-server over HTTPS?

  • I am using HTTPS.

Notes

Though I checked I am using HTTPS, but I actually running locally without HTTPS.
I checked it because it is a must and I think HTTPS has nothing to do with the issue.

@huweiATgithub huweiATgithub added bug Something isn't working triage This issue needs to be triaged by a maintainer labels Oct 5, 2022
@benz0li
Copy link
Contributor

benz0li commented Oct 5, 2022

Prepending /usr/lib/code-server/lib/vscode/bin/remote-cli to PATH is not a bug but by design.

Cross references:

@huweiATgithub
Copy link
Contributor Author

Prepending /usr/lib/code-server/lib/vscode/bin/remote-cli to PATH is not a bug but by design.

Prepending is not the issue. My issue is that PATH has been overwritten instead of prepending.

@jsjoeio
Copy link
Contributor

jsjoeio commented Oct 5, 2022

@code-asher do you mind taking a look at this one?

@benz0li
Copy link
Contributor

benz0li commented Oct 5, 2022

@huweiATgithub What PATH is set in /etc/profile?

@huweiATgithub
Copy link
Contributor Author

@huweiATgithub What PATH is set in /etc/profile?

I am running from the docker:

docker run -it --name code-server -p 127.0.0.1:8080:8080 \
-v "$HOME/.config:/home/coder/.config" \
-u "$(id -u):$(id -g)" \
-e "DOCKER_USER=$USER"  -e "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/some/path" \
codercom/code-server

therefore, it should not matter what is my path in /etc/profile. I am passing the PATH through docker run -e option.

@huweiATgithub
Copy link
Contributor Author

Let alone that I deploy code-server with docker. I have also tried that on multiple machines. So I suppose that is not an issue related to the host machines.

You may quickly execute the above docker command to see if that can be reproduced.

@huweiATgithub
Copy link
Contributor Author

BTW, if you tried to docker exec into the container. The PATH variable is fine. only terminal launch by code-server had the issue.

I guess before the code-server launch, it has a wrapper that modifies the PATH variable to insure code-server's launching env. The wrapper is not respecting the PATH from its env.

@benz0li
Copy link
Contributor

benz0li commented Oct 5, 2022

You may quickly execute the above docker command to see if that can be reproduced.

I can reproduce your issue.

@benz0li
Copy link
Contributor

benz0li commented Oct 5, 2022

BTW, if you tried to docker exec into the container. The PATH variable is fine. only terminal launch by code-server had the issue.

I can confirm that.

I guess before the code-server launch, it has a wrapper that modifies the PATH variable to insure code-server's launching env. The wrapper is not respecting the PATH from its env.

I am setting PATH in the Dockerfile and that works fine. Check my reference deployment at https://demo.jupyter.b-data.ch.

@code-asher
Copy link
Member

I remember looking into this briefly before (#4699) but I have no idea where it happens. 😞

@huweiATgithub
Copy link
Contributor Author

I am setting PATH in the Dockerfile and that works fine. Check my reference deployment at https://demo.jupyter.b-data.ch/.

b-data looks very fancy! integrating jupyterlab with vscode is really cool and productive.
I am not familiar with it. It seems I cannot customize in the demo- mode.
I created one Dockerfile,

FROM codercom/code-server
ENV PATH="/some/path:${PATH}"

then build it and run it with Docker using a command similar to the one posted above.

Still get path:
image

@huweiATgithub
Copy link
Contributor Author

I remember looking into this briefly before (#4699) but I have no idea where it happens. disappointed

How did I not find out the previous issue 😲 I searched that...

@code-asher
Copy link
Member

code-asher commented Oct 5, 2022

Oh wait I think I might know what it is! I think VS Code spawns a login shell to get PATH. So basically they run something like bash -lc "printenv PATH" and then set PATH to that. Edit: actually it seems they source the entire environment not just PATH as seen here then merge it with the current environment.

There are some terminal settings like Inherit Env that we might want to play around with to see if we can stop it from doing that.

@code-asher
Copy link
Member

Can confirm that disabling Terminal › Integrated: Inherit Env prevents the override.

@huweiATgithub
Copy link
Contributor Author

Can confirm that disabling Terminal › Integrated: Inherit Env prevents the override.

can it preserve the modified PATH? Inherit Env sounds like getting env from the env that it runs in.

@benz0li
Copy link
Contributor

benz0li commented Oct 5, 2022

I am not familiar with it. It seems I cannot customize in the demo- mode.

No. But see https://github.com/b-data/jupyterlab-python-docker-stack#run-container


Adapted to your example:

docker run -it --name jupyter-code-server \
  -u root \
  -p 8888:8888 \
  -v $PWD:/home/$USER \
  -e NB_USER=$USER \
  -e NB_UID=$(id -u) \
  -e NB_GID=$(id -g) \
  -e CHOWN_HOME=1 \
  -e CHOWN_HOME_OPTS=-R \
  -e PATH=/opt/TinyTeX/bin/linux:/opt/quarto/bin:/opt/code-server/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/some/path \
  registry.gitlab.b-data.ch/jupyterlab/python/scipy

ℹ️ Run the command in an empty directory so that the container populates it.
👉 -e CHOWN_HOME=1 and -e CHOWN_HOME_OPTS=-R is only required at first run.

@code-asher
Copy link
Member

can it preserve the modified PATH? Inherit Env sounds like getting env from the env that it runs in.

Yeah it looks ilke the "inherit env" name is misleading. It seems to mean that it spawns a login shell to get the environment rather than using the current environment (which sounds backwards from "inherit" to me 🤷 but I guess that is the name they went with).

So to summarize:

  • With inherit env: gets environment by spawning a login shell and overrides current environment
  • Without inherit env: uses the current environment

@huweiATgithub
Copy link
Contributor Author

Oh wait I think I might know what it is! I think VS Code spawns a login shell to get PATH. So basically they run something like bash -lc "printenv PATH" and then set PATH to that. Edit: actually it seems they source the entire environment not just PATH as seen here then merge it with the current environment.

There are some terminal settings like Inherit Env that we might want to play around with to see if we can stop it from doing that.

I checked the .bashrc and .profile. There is nothing particular done there.
The PATH is being modified in /usr/bin/code-server I think.

@huweiATgithub
Copy link
Contributor Author

With inherit env: gets environment by spawning a login shell and overrides current environment

For a login shell, I think the path set in the Dockerfile or pass from the docker run command should be respected.
See:
image

So I think either vscode modifies the PATH or code-server modifies it.
It is more likely that the code-server modifies it as the local instance of vscode runs without this issue.

@code-asher
Copy link
Member

code-asher commented Oct 5, 2022

I tried the same thing with debian:11 (this is what code-server is based on) and reproduced:

coder@my-dev2:~/docker$ docker run --rm -e "PATH=/usr/bin:/bin:/some-path" -it debian:11 bash
root@25b75f4f2da6:/# printenv PATH
/usr/bin:/bin:/some-path
root@25b75f4f2da6:/# bash -lc 'printenv PATH'
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

In /etc/profile there is this:

if [ "$(id -u)" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi

So this could be the cause of the problem.

@huweiATgithub
Copy link
Contributor Author

What about adding a release for ubuntu:focal? It also benefits those users who use ubuntu:focal more.

@code-asher
Copy link
Member

That seems chill. Maybe we can do the Docker tags like this:

latest         # debian:11 with latest code-server
bullseye       # debian:11 with latest code-server
focal          # ubuntu:focal with latest code-server
4.7.0          # debian:11 with code-server 4.7.0
4.7.0-bullseye # debian:11 with code-server 4.7.0
4.7.0-focal    # ubuntu:focal with code-server 4.7.0

I patterned that after the Python image but maybe in code-server's case it makes more sense to do it by OS.

latest       # debian:11 with latest code-server
debian       # debian:11 with latest code-server
ubuntu       # ubuntu:focal with latest code-server
4.7.0        # debian:11 with code-server 4.7.0
4.7.0-debian # debian:11 with code-server 4.7.0
4.7.0-ubuntu # ubuntu:focal with code-server 4.7.0

We could also do both.

@huweiATgithub
Copy link
Contributor Author

Looks good. These are fine if documented I think.

@jsjoeio jsjoeio added this to the On Deck milestone Oct 6, 2022
@jsjoeio jsjoeio removed this from the On Deck milestone Oct 24, 2022
@jsjoeio jsjoeio modified the milestones: October 2022, 4.8.0 Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage This issue needs to be triaged by a maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants