JuliaLang / devcontainer-features

Julia Development Container Feature
16 stars 4 forks source link

postCreate script failing with trivial path environment variable changes to devcontainer.json #18

Open ahjulstad opened 4 months ago

ahjulstad commented 4 months ago

When specifying PATH environment variable in the devcontainer.json, for example like this:

"remoteEnv": {
        "PATH": "${containerEnv:PATH}"
    }

the postcreate.jl script fails.

Running the postCreateCommand from Feature 'ghcr.io/julialang/devcontainer-features/julia:1'...

[19325 ms] Start: Run in container: /bin/sh -c /usr/local/julia-devcontainer-features/postcreate.jl
[20064 ms] postCreateCommand failed with exit code 127. Skipping any further user-provided commands.
Done. Press any key to close the terminal.

MWE here:

https://github.com/ahjulstad/julia-devcontainer-feature-errror-minimimworkingexample/commit/df768106758afa1752d1994ed69884f7cb49008e

julia> versioninfo()
Julia Version 1.10.2
Commit bd47eca2c8a (2024-03-01 10:14 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 12 × Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
Threads: 1 default, 0 interactive, 1 GC (on 12 virtual cores)

After startup I can run Julia or the postcreate.jl script just fine, but the language server does not start.

The resulting path if I delete the remoteEnv statement becomes: /vscode/vscode-server/bin/linux-x64/e170252f762678dec6ca2cc69aba1570769a5d39/bin/remote-cli:/home/vscode/.juliaup/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/vscode/.local/bin

If I keep the remoteEnv statement /home/vscode/.juliaup/bin:/vscode/vscode-server/bin/linux-x64/e170252f762678dec6ca2cc69aba1570769a5d39/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/vscode/.local/bin

Same elements, but slightly different sequence.

(The purpose of the original path setting was to make the Julia-installed python available at the command prompt, with the goal of sharing python environments across devcontainers. And if you ask, why use devcontainers at all; I am on Windows.)

Perhaps this is caused by some core devcontainer feature, I don't know...

eitsupi commented 4 months ago

I believe this is due to the fact that the PATH updated by juliaup has been overwritten once again and julia is no longer on the PATH. You might try using something like the following "PATH": "${containerEnv:PATH}:/home/vscode/.juliaup/bin:/home/vscode/.julia/conda/3/x86_64/bin"

ahjulstad commented 4 months ago

Indeed, that works. The resulting path, though, has all the same elements.

/vscode/vscode-server/bin/linux-x64/e170252f762678dec6ca2cc69aba1570769a5d39/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/vscode/.juliaup/bin:/home/vscode/.local/bin

Why this path is not present when the container tries to run the postcreate script in my first attempt, I have no idea.

Strange behaviour. Thanks for your help, though.

eitsupi commented 4 months ago

Perhaps the following is happening:

  1. juliaup updates .bashrc etc. for adding the julia bin path to the PATH env var.
  2. The PATH env var is updated by the remoteEnv setting and the life cycle scripts are executed.
  3. When bash etc. starts, it reads the .bashrc so you can be sure that the path to the julia bin added by juliaup is in the PATH env var.

The workaround is probably to set something like the following in the Feature settings, but I am not sure if this will work.

    "containerEnv": {
        "PATH": "~/.juliaup/bin:${PATH}"
    }

There are several Features that update the PATH env var like this, but I do not know how to specify the home directory. https://github.com/devcontainers/features/blob/6f4e59866169405c7b7a8ff65e3f2ac3ced6a26e/src/rust/devcontainer-feature.json#L62

eitsupi commented 4 months ago

Perhaps it would be worth changing the installation location of Juliaup to a location like /usr/local/juliaup. https://github.com/JuliaLang/juliaup?tab=readme-ov-file#command-line-arguments

Then we can set like

    "containerEnv": {
        "PATH": "/usr/local/juliaup/bin:${PATH}"
    }

@davidanthoff Thoughts?