Skip to content

Better: add asdf support#8925

Open
ylecuyer wants to merge 1 commit intojruby:masterfrom
ylecuyer:asdf-yle
Open

Better: add asdf support#8925
ylecuyer wants to merge 1 commit intojruby:masterfrom
ylecuyer:asdf-yle

Conversation

@ylecuyer
Copy link
Contributor

Hello,

Little PR to add asdf support. Asdf has its java command in /home/ylecuyer/.asdf/shims/java but the real jdk is in /home/ylecuyer/.asdf/installs/java/openjdk-17/bin/java so doing java_command/../../ to get the jdk doesn't work

Instead it uses asdf which java which points to the correct path

See repro with this Dockerfile

FROM debian:12

RUN apt-get update && apt-get install -y wget git curl build-essential libssl-dev libreadline-dev zlib1g-dev vim

RUN mkdir -p ~/.bin
RUN wget https://github.com/asdf-vm/asdf/releases/download/v0.18.0/asdf-v0.18.0-linux-amd64.tar.gz \
    && tar -xzf asdf-v0.18.0-linux-amd64.tar.gz -C ~/.bin \
    && rm asdf-v0.18.0-linux-amd64.tar.gz

# Set environment variables for asdf
ENV PATH="/root/.bin/:/root/.asdf/shims/:${PATH}"

# Install asdf java plugin
RUN asdf plugin add java https://github.com/halcyon/asdf-java.git

# Install java 21
RUN asdf install java openjdk-21

# Install asdf ruby plugin
RUN asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git

ENV ASDF_JAVA_VERSION=openjdk-21

COPY asdf.patch /root/asdf.patch

# PATCH
# ENV RUBY_APPLY_PATCHES=/root/asdf.patch

# Install jruby 10.0.0.1
RUN ASDF_RUBY_BUILD_VERSION=master asdf install ruby jruby-10.0.1.0

RUN ASDF_RUBY_VERSION=jruby-10.0.1.0 jruby -v

Without the patch:

 > [ 9/10] RUN ASDF_RUBY_BUILD_VERSION=master asdf install ruby jruby-10.0.1.0:                                                                                                                                                                                                           
0.327 Downloading ruby-build...                                                                                                                                                                                                                                                           
1.590 ==> Downloading jruby-dist-10.0.1.0-bin.tar.gz...                                                                                                                                                                                                                                   
2.680 -> curl -q -fL -o jruby-10.0.1.0.tar.gz https://dqw8nmjcqpjn7.cloudfront.net/22174ed408aa19340fc3c609b67f5a83374539ecc50053153d60f6e1f81faa9d                                                                                                                                       
2.689   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                                                                                                                                                                                     
2.689                                  Dload  Upload   Total   Spent    Left  Speed
100 32.2M  100 32.2M    0     0  77.9M      0 --:--:-- --:--:-- --:--:-- 77.8M
3.611 ==> Installing jruby-10.0.1.0...
3.707 -> ./ruby gem install jruby-launcher --no-document
7.446 
7.446 BUILD FAILED (Debian GNU/Linux 12 on x86_64 using ruby-build 20250724)
7.448 
7.449 You can inspect the build directory at /tmp/ruby-build.20250724122319.73.WxkErp
7.450 See the full build log at /tmp/ruby-build.20250724122319.73.log
7.484 error installing version: failed to run install callback: exit status 1
------
Dockerfile:30
--------------------
  28 |     
  29 |     # Install jruby 10.0.0.1
  30 | >>> RUN ASDF_RUBY_BUILD_VERSION=master asdf install ruby jruby-10.0.1.0
  31 |     
  32 |     RUN ASDF_RUBY_VERSION=jruby-10.0.1.0 jruby -v
--------------------
ERROR: failed to build: failed to solve: process "/bin/sh -c ASDF_RUBY_BUILD_VERSION=master asdf install ruby jruby-10.0.1.0" did not complete successfully: exit code: 1

With the patch:

 => [ 9/10] RUN ASDF_RUBY_BUILD_VERSION=master asdf install ruby jruby-10.0.1.0                                                                                                                                                                                                      9.8s
 => [10/10] RUN ASDF_RUBY_VERSION=jruby-10.0.1.0 jruby -v

@headius
Copy link
Member

headius commented Aug 13, 2025

Great idea! I'll review and merge shortly.

@chadlwilson
Copy link
Contributor

I've been using jruby with asdf (and now mise aka rtx) for a number of years.

The "normal" way to make most JVM ecosystem kind of stuff work with the canonical asdf java plugin was to use one of the set-java-home extra hooks, avoiding changes to projects to be specifically aware. Mise does this properly by default out-of-the-box, and a lot faster than asdf.

Just my two cents.

@headius
Copy link
Member

headius commented Aug 14, 2025

@ylecuyer Maybe take a look into using set-java-home or let us know why that isn't sufficient?

@ylecuyer
Copy link
Contributor Author

As far as I understand the problem with set-java-home is that it relies on a bash PROMPT_COMMAND or other shells pre command hooks. And there is none for sh which is the default shell in a Dockerfile

Even when wrapping the RUN into a /bin/bash -c I couldn't get it to work because the shell is non interactive. Adding -i wasn't successful either and adds warning to the build logs.

@chadlwilson
Copy link
Contributor

Having done it before, if you're trying to use asdf inside docker, you're at the edge of what is 'normal' use, especially of asdf given its shim-based design.

Personally im not sure that such a use case should motivate changing JRuby itself. There are too many different tools, shells and approaches to version management, and I don't believe this type of automation is asdf's primary goal.

Your docker file could as easily call JAVA_HOME=$(asdf which java) or use asdf exec etc, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants