devpod
devpod copied to clipboard
Environment Variable replaced at Runtime
What happened?
I am setting up different variables to find binaries like
"CARGO_HOME" : "/home/gitpod/.cargo",
"GOPATH" : "/home/gitpod/go-packages",
"GOROOT" : "/home/gitpod/go",
},
"remoteUser": "gitpod",
"remoteEnv": {
"PATH": "${containerEnv:PATH}:/home/gitpod/.cargo/bin:/home/gitpod/go/bin:/home/gitpod/go-packages/bin"
And unfortunately the /home/gitpod part is replaced by /workspace so all my binaries are not in the PATH anymore.
What did you expect to happen instead?
This works fine with codespace,
How can we reproduce the bug? (as minimally and precisely as possible)
You can reproduce by opening this repo in devpod and searching for go, tinygo, wit or other executable installed with Cargo: https://github.com/vados-cosmonic/wasmcon2024-couchbase-workshop/
Hey @ldoguin, thanks for reporting the issue, we'll take a look!
I'll drop in with my observations, as I think I'm seeing something similar. I've started debugging this more closely:
My test .devcontainer.json:
{
"name": "debugging devpod's PATH problem",
"image": "ghcr.io/yacoob/interactive:base",
"containerEnv": {
"PATH": "/containerEnv/marker:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"MARKER": "container"
},
"remoteEnv": {
"PATH": "/remoteEnv/marker:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"MARKER": "remote"
},
"securityOpt": ["label=disable"],
"remoteUser": "yacoob",
"containerUser": "yacoob"
}
Test:
❯ podman exec reverent_kirch printenv PATH
/containerEnv/marker:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
❯ podman exec reverent_kirch printenv MARKER
container
❯ devpod ssh env-debug --command 'printenv PATH'
/home/yacoob/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
❯ devpod ssh env-debug --command 'printenv MARKER'
remote
❯ devpod ssh env-debug --command 'cat /etc/envfile.json'
{"env":{"PATH":"/remoteEnv/marker:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","MARKER":"remote"}}
This strongly suggests that:
containerEnvsets variables properly for the container (aspodman execshows both variables undisturbed)remoteEnvsets both variables via/etc/envfile.json, butPATHgets sanitized down to some standard value.
This is not totally unexpected, as traditional ssh also sanitizes PATH to its own default. Here, it's breaking things, as the values for containerEnv and remoteEnv can be set by either user or a feature they've included.
@pascalbreuninger any idea where that sanitization for PATH is happening?
Further evidence:
❯ devpod ssh --set-env MARKER=/bla --set-env PATH=/workspaces/foo.venv/bin:/usr/bin --command 'printenv PATH' .
/home/yacoob/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
❯ devpod ssh --set-env MARKER=/bla --set-env PATH=/workspaces/foo.venv/bin:/usr/bin --command 'printenv MARKER' .
/bla
Looks like devpod ssh - or the agent on the container's end - actually sanitizes PATH.
One more thing: a (crude) workaround for me was to symlink the binaries I was missing into ~/.local/bin. As I'm making a Python devcontainer, I ended up having this:
"postCreateCommand": "(curl -LsSf https://astral.sh/uv/install.sh | sh) && uv sync && echo 'source ${containerWorkspaceFilder}/.venv/bin/activate' >> ~/.zshrc.local && ln -sf ${containerWorkspaceFolde
r}/.venv/bin/python3 ~/.local/bin/python3",
Not ideal, but does the trick in the meantime.
Correct fix (IMO) is to change devpod to honour PATH set via containerEnv and remoteEnv - as this seems to be the way for devcontainer features to hook into the container.
Also notice this, the PATH is not injected?
"Config": {
"Hostname": "5d105445672d",
"Domainname": "",
"User": "root",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/cargo/bin:/usr/local/go/bin:/go/bin:/home/vscode/go/bin:/home/vscode/cargo/bin:${containerEnv:PATH}",
"DEVPOD=true",
"REMOTE_CONTAINERS=true",
"DEVPOD_WORKSPACE_ID=bats-protocol-framework",
"DEVPOD_WORKSPACE_UID=default-ba-606cf",
"CARGO_HOME=/home/vscode/cargo",
"GOPATH=/home/vscode/go",
"VCPKG_ROOT=/usr/local/vcpkg",
"VCPKG_DOWNLOADS=/usr/local/vcpkg-downloads",
"RUSTUP_HOME=/usr/local/rustup",
"GOROOT=/usr/local/go"
],
"Cmd": [
"-c",
"echo Container started\ntrap \"exit 0\" 15\n\nexec \"$@\"\nwhile sleep 1 & wait $!; do :; done",
"-"
],
This issue is stale because it has been open for 60 days with no activity.
no stale
This issue is stale because it has been open for 60 days with no activity.
no stale
This issue is stale because it has been open for 60 days with no activity.
no stale