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

Java executable not found depending on container #678

Closed
2 of 5 tasks
abbasyadollahi opened this issue Aug 29, 2024 · 11 comments
Closed
2 of 5 tasks

Java executable not found depending on container #678

abbasyadollahi opened this issue Aug 29, 2024 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@abbasyadollahi
Copy link

Description:
I have a simplified action which sets up Java inside of a container. Depending on the container used, I get an error because it fails to run the the installed Java executable, even though it seems to exist. The Java version doesn't seem to matter.

Task version:
v4

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Repro steps:
Here's a barebones example of the steps in the GitHub action, where test-docker fails and test-ubuntu works.

...
jobs:
  test-docker:
    runs-on: ubuntu-latest
    container: docker:cli
    steps:
      - name: Set up JDK
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 11
      - name: Execute Java
        run: |
          which java
          type java
          echo $JAVA_HOME
          echo $PATH
          java --help

  test-ubuntu:
    runs-on: ubuntu-latest
    container: ubuntu:latest
    steps:
      - name: Install docker and docker-compose
        run: |
          apt -y update 
          apt -y install sudo curl
          curl -fsSL https://get.docker.com -o get-docker.sh
          sudo sh ./get-docker.sh
          apt-get install docker-compose-plugin
      - name: Set up JDK
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 11
      - name: Execute Java
        run: |
          which java
          type java
          echo $JAVA_HOME
          echo $PATH
          java --help

Expected behavior:
I expect both jobs to successfully install the java executable (which they seem to do) and be able to execute it.

Actual behavior:
The test-docker job seems to install the java library properly, but doesn't seem to be able to execute it. On the other hand, the test-ubuntu job installs the java library properly and is able to run the java executable as expected. In both cases, the java lib seems to exists on disk, but the job using the docker:cli image as its container can't find the java executable. Below is an excerpt of the output of the Execute Java step of each job.

test-docker

/__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64/bin/java
java is /__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64/bin/java
/__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64
/__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/__w/_temp/24f7e9c6-9173-452f-b7b0-833ce68b877a.sh: line 5: /__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64/bin/java: not found

test-ubuntu

/__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64/bin/java
java is /__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64/bin/java
/__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64
/__t/Java_Temurin-Hotspot_jdk/11.0.24-8/x64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Usage: java [options] <mainclass> [args...]
           (to execute a class)
...
@abbasyadollahi abbasyadollahi added bug Something isn't working needs triage labels Aug 29, 2024
@aparnajyothi-y
Copy link
Contributor

Hello @abbasyadollahi, Thank you for creating this issue and we will look into it :)

@srcimon
Copy link

srcimon commented Sep 8, 2024

Having kind of the same issue here with my project. Mockito cannot find the java executable. I worked around it via pinning the ubuntu version to 24.04. With ubuntu-latest I get:

Caused by: java.lang.reflect.InvocationTargetException
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
	at org.mockito.internal.configuration.plugins.DefaultMockitoPlugins.create(DefaultMockitoPlugins.java:103)
	... 10 more
Caused by: org.mockito.exceptions.base.MockitoInitializationException: 
Could not initialize inline Byte Buddy mock maker.

It appears as if your JDK does not supply a working agent attachment mechanism.
Java               : 21
JVM vendor name    : Eclipse Adoptium
JVM vendor version : 21.0.4+7-LTS
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 21.0.4+7-LTS
JVM info           : mixed mode, sharing
OS name            : Windows NT
OS version         : 6.5.0-1025-azure

Please let me know if I confuse something here.

@suyashgaonkar
Copy link

Hi @abbasyadollahi , This issue can be resolved by adding an extra step in the job. Following are the steps that you need to add to make the job work. -
name:Install Java
run: |
apk update && \
apk upgrade
apk add openjdk11=11.0.24_p8-r0

To make the job run successfully, we need to install java in the container using the docker's apline package manager to make to get java executable detected.
Please refer to the attached snip.

Screenshot 2024-09-11 at 2 57 36 PM

@srcimon
Copy link

srcimon commented Oct 1, 2024

@abbasyadollahi my issue disappeared magically when using ubuntu-latest now. Maybe it's worth a try.

@suyashgaonkar
Copy link

Hi @abbasyadollahi , We are awaiting for your response on the issue. Please let us know if we can close this issue if there are no further queries.

@abbasyadollahi
Copy link
Author

abbasyadollahi commented Oct 3, 2024

@srcimon
I believe our issues are slightly different, your build seems to at least recognize that there's a Java executable, whereas mine doesn't (even though the output clearly shows the java executable existing). I tried once again with ubuntu-latest, but getting the same issue.

@suyashgaonkar
I see, it's good to know I can manually install Java in the container, though this issue is about the setup-java action. From my understanding, it shouldn't matter whether I'm running the job in the ubuntu:latest container or the docker:cli container, the setup-java action should be able to install the Java executable correctly for both.

@suyashgaonkar
Copy link

Hi @abbasyadollahi , the setup-java is responsible in dealing with functionalities and configurations related to Github Action runners and not the containers. The reason being java commands working fine on ubuntu:latest container and not in docker:cli is ubuntu:latest container has jdk installed by default, the case is not same with the docker:cli hence we would explicitly need to install jdk while working with docker containers.
You can refer the following url :- https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md

@abbasyadollahi
Copy link
Author

@suyashgaonkar
One small thing to note is that the ubuntu:latest container does not have JDK installed, the link you sent is for the ubuntu-latest runner, which all the steps in my example use so they all have JDK 8, 11, 17, 21 installed.
I see, maybe I'm misunderstanding what the setup-java action does in that case, because I was under the assumption that it installs the selected JDK + tools on which ever host/container it's running on? Instead you're saying the action requires the host to already have the JDK + tools installed, and it simply deals with system configurations like setting JAVA_HOME or PATH?
This definitely sounds odd since I just ran a job with the setup-java action to install JDK 16 (which is not installed on the ubuntu-latest runner nor the ubuntu:latest container) and it was able to install the libraries. Here's the step output below showing that it installs the library.

Installed distributions
  Trying to resolve the latest version from remote
  Resolved latest version as [16](https://github.com/abbasyadollahi/test/actions/runs/11264615355/job/31324936772#step:5:17).0.2+7
  Trying to download...
  Downloading Java 16.0.2+7 (Temurin-Hotspot) from https://github.com/adoptium/temurin16-binaries/releases/download/jdk-16.0.2%2B7/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz ...
  Extracting Java archive...
  /usr/bin/tar xz --warning=no-unknown-keyword --overwrite -C /__w/_temp/0bc4f421-27e3-442d-beb6-1f89de5fb2e1 -f /__w/_temp/b80d4b23-059d-4833-a3e3-fcb369c64c[20](https://github.com/abbasyadollahi/test/actions/runs/11264615355/job/31324936772#step:5:21)
  Java 16.0.2+7 was downloaded
  Setting Java 16.0.2+7 as the default
  Creating toolchains.xml for JDK version 16 from temurin
  Writing to /github/home/.m2/toolchains.xml
  
  Java configuration:
    Distribution: temurin
    Version: 16.0.2+7
    Path: /__t/Java_Temurin-Hotspot_jdk/16.0.2-7/x64

Seems there's something specifically wrong with the docker:cli container. After investigating a bit more, I think it might have something to do with alpine based images (docker:cli builds off the latest alpine image), since the setup-java action works with other ubuntu based images but not alpine based images. Seems it could be related to #374.

@github-staff github-staff deleted a comment from telfaw Oct 22, 2024
@github-staff github-staff deleted a comment from syedmaaz9905 Oct 24, 2024
@suyashgaonkar
Copy link

suyashgaonkar commented Oct 30, 2024

Hi @abbasyadollahi, The docker:cli is alpine linux based image which is built around MUSL whereas ubuntu:latest is GLIBC based image and works with setup-java seamlessly. docker:cli being a MUSL based image requires to go through a extra step i.e is to install a MUSL based open-jdk manually with the help of Alpine Package Keeper (apk). Let us know if you still need any assistance or we can close this issue ?

@abbasyadollahi
Copy link
Author

Ok I see, so if I understood correctly, you're saying setup-java doesn't support installing a JDK on MUSL based systems (like alpine)? If that's the case, then we can go ahead and close this ticket, though it would definitely be a nice to have, or at least an indication of this pitfall in the action's README.

@suyashgaonkar
Copy link

Hi @abbasyadollahi, Thank you for your feedback. You understood correctly.

We appreciate your understanding and agree that this feature would be beneficial to have. Additionally, please note that setup-java actions are available for environments that GitHub Actions hosted runners support.

We will go ahead and close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants