babashka / pods

Pods support for JVM and babashka
Eclipse Public License 1.0
122 stars 12 forks source link

Pod doesn't load when setting XDG_CACHE_HOME or XDG_DATA_HOME in Ubuntu #63

Closed hueyy closed 1 year ago

hueyy commented 1 year ago

The issue

Running the following in the repl does not install the retrogradeorbit/bootleg pod:

user=> (require '[babashka.pods :as pods])
nil

user=> (pods/load-pod 'retrogradeorbit/bootleg "0.1.9")
Downloading pod retrogradeorbit/bootleg (0.1.9)
Successfully installed pod retrogradeorbit/bootleg (0.1.9)
java.io.IOException: Cannot run program "/home/user/.local/share/.babashka/pods/repository/retrogradeorbit/bootleg/0.1.9/linux/x86_64/bootleg": error=2, No such file or directory [at <repl>:2:1]

Other pods appear to install fine, e.g.:

user=> (pods/load-pod 'org.babashka/fswatcher "0.0.3")
Downloading pod org.babashka/fswatcher (0.0.3)
Successfully installed pod org.babashka/fswatcher (0.0.3)
#:pod{:id "pod.babashka.fswatcher"}
borkdude commented 1 year ago

@retrogradeorbit I suspect thid has to do with dynamic linking. Would you consider making the bootleg pod a static binary on linux?

@hueyy Can you execute ldd /home/user/.local/share/.babashka/pods/repository/retrogradeorbit/bootleg/0.1.9/linux/x86_64/bootleg and paste the output here?

hueyy commented 1 year ago

I ran ls /home/user/.local/share/.babashka/pods/repository/retrogradeorbit/bootleg/0.1.9

The only file there is manifest.edn (subfolders are missing) so it looks like the bootleg binary isn't being downloaded and saved there for some reason.

borkdude commented 1 year ago

Can you try this with BABASHKA_PODS_DIR=/tmp?

borkdude commented 1 year ago

I suspect there might be a permission error while writing the pod or so, this is why it might be good to try the above environment variable

hueyy commented 1 year ago

Yep, I can confirm setting BABASHKA_PODS_DIR=/tmp worked:

$ BABASHKA_PODS_DIR=/tmp bb repl

Babashka v1.0.169 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (System/getenv "BABASHKA_PODS_DIR")
"/tmp"
user=> (require '[babashka.pods :as pods])
nil
user=> (pods/load-pod 'retrogradeorbit/bootleg "0.1.9")
Downloading pod retrogradeorbit/bootleg (0.1.9)
Successfully installed pod retrogradeorbit/bootleg (0.1.9)
#:pod{:id "pod.retrogradeorbit.bootleg.glob"}
user=> 

I thought it might be a permissions permission too, but I checked the permissions of /home/user/.local/share/.babashka/pods/repository/retrogradeorbit/bootleg/0.1.9 and all parent directories -- my user owns it and has rw permissions for all files and x permissions for all folders.

borkdude commented 1 year ago

Is it possible to replicate your problem using a Dockerfile so I have something to work with?

On Sun, 8 Jan 2023 at 15:32, Huey @.***> wrote:

Yep, I can confirm setting BABASHKA_PODS_DIR=/tmp worked:

$ BABASHKA_PODS_DIR=/tmp bb repl

Babashka v1.0.169 REPL. Use :repl/quit or :repl/exit to quit the REPL. Clojure rocks, Bash reaches.

user=> (System/getenv "BABASHKA_PODS_DIR")"/tmp" user=> (require '[babashka.pods :as pods])niluser=> (pods/load-pod 'retrogradeorbit/bootleg "0.1.9") Downloading pod retrogradeorbit/bootleg (0.1.9) Successfully installed pod retrogradeorbit/bootleg (0.1.9)#:pod{:id "pod.retrogradeorbit.bootleg.glob"} user=>

I thought it might be a permissions permission too, but I checked the permissions of /home/user/.local/share/.babashka/pods/repository/retrogradeorbit/bootleg/0.1.9 and all parent directories -- my user owns it and has rw permissions for all files and x permissions for all folders.

— Reply to this email directly, view it on GitHub https://github.com/babashka/pods/issues/63, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACFSBRFICAZHCCM76F5LDTWRLFZPANCNFSM6AAAAAATULEM3U . You are receiving this because you commented.Message ID: @.***>

-- https://www.michielborkent.nl https://www.eetvoorjeleven.nu

borkdude commented 1 year ago

I suspect it may be an issue with XDG_CACHE etc settings: perhaps babashka pods write to one directory but tries to read from another directory.

Is it possible that the binary was written to a different directory?

You might be able to debug this with the pods library locally https://github.com/babashka/pods by inserting some print statements.

hueyy commented 1 year ago

Unfortunately, I haven't been able to reproduce this via a Dockerfile, very odd. But I can confirm setting $BABASHKA_PODS_DIR to /home/user/.local/share/.babashka/pods/repository works (and the pod is successfully installed in that directory) and that (System/getenv "XDG_DATA_HOME") returns /home/user/.local/share. Very curious.

borkdude commented 1 year ago

@hueyy You're not the first to experience this problem, so I'd like to get to the bottom of this...

In the Dockerfile, is it possible to set the XDG_* environment variables similar to your own environment?

hueyy commented 1 year ago

Aha! That worked, as in that worked in reproducing the issue:

The Dockerfile:

FROM ubuntu:22.04

RUN apt-get update && apt-get install -y curl && \
    curl -sLO https://raw.githubusercontent.com/babashka/babashka/master/install && \
    chmod +x install && \
    ./install

RUN useradd -ms /bin/bash user
USER user
WORKDIR /home/user

ENV XDG_DATA_HOME=/home/user/.local/share
ENV XDG_CACHE_HOME=/home/user/.cache

RUN echo "(require '[babashka.pods :as pods])(pods/load-pod 'retrogradeorbit/bootleg \"0.1.9\")" | tee test.bb

ENTRYPOINT ["bb", "test.bb"]

I ran the following:

docker build -t test .
docker run test

Which produced the following output:

Downloading pod retrogradeorbit/bootleg (0.1.9)
Successfully installed pod retrogradeorbit/bootleg (0.1.9)
----- Error --------------------------------------------------------------------
Type:     java.io.IOException
Message:  Cannot run program "/home/user/.local/share/.babashka/pods/repository/retrogradeorbit/bootleg/0.1.9/linux/x86_64/bootleg": error=2, No such file or directory
Location: /home/user/test.bb:1:36

----- Context ------------------------------------------------------------------
1: (require '[babashka.pods :as pods])(pods/load-pod 'retrogradeorbit/bootleg "0.1.9")
                                      ^--- Cannot run program "/home/user/.local/share/.babashka/pods/repository/retrogradeorbit/bootleg/0.1.9/linux/x86_64/bootleg": error=2, No such file or directory

----- Stack trace --------------------------------------------------------------
babashka.pods.impl/run-pod           - <built-in>
babashka.pods.impl/load-pod          - <built-in>
babashka.pods.sci/load-pod/fn--27042 - <built-in>
babashka.pods.sci/load-pod           - <built-in>
clojure.core/apply                   - <built-in>
babashka.impl.pods/load-pod          - <built-in>
user                                 - /home/user/test.bb:1:36
borkdude commented 1 year ago

Excellent! I will have a look soon!

borkdude commented 1 year ago

@hueyy The problem should be solved with the master build of babashka which you can install with:

bash <(curl https://raw.githubusercontent.com/babashka/babashka/master/install) --dev-build --dir /tmp

once the current master build finishes.