Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Incorrect JAVA_HOME for custom Corretto runtime on AL 2023 x86_64 #738

Closed
naiyerasif opened this issue Sep 5, 2024 · 7 comments
Closed

Comments

@naiyerasif
Copy link

Describe the bug
When I provision a CodeBuild project with Amazon Linux 2023 x86_64 standard:5.0, and set the runtime as corretto22 in the install phase, the exported JAVA_HOME, JRE_HOME, and JDK_HOME variables don't point to the correct installed location of Corretto 22, causing failure when I try to run mvn package in the next phases.

To Reproduce
Steps to reproduce the behavior:

  1. Create a CodeBuild project with Amazon Linux 2023 x86_64 standard:5.0 image. (I'm using this to build a Java application with Maven with source and target set to 22 in pom.xml)
  2. Specify corretto22 as the runtime version
    version: 0.2
    phases:
      install:
        runtime-versions:
          java: corretto22
      build:
        commands:
          - mvn package
  3. Trigger a job. It fails during build phase. Maven complains that JAVA_HOME is not set correctly.

Expected behavior
The commands in build phase should pass and Maven should not complain about JAVA_HOME

Logs
NA

Platform (please complete the following information):

  • OS: Amazon Linux 2023 x86_64 standard:5.0

Additional context
The issue seems to stem from here.

# https://github.com/aws/aws-codebuild-docker-images/blob/1bd6ad2e247b957c8597fc31e172e3d2df185a19/al2/x86_64/standard/5.0/runtimes.yml#L66
default:
  commands:
    - echo "Installing custom Corretto(OpenJDK) version $VERSION ..."
    - yum -y install java-$VERSION-amazon-corretto-devel.x86_64
    - export JAVA_HOME="/usr/lib/jvm/java-$VERSION-amazon-corretto"
    - export JRE_HOME="/usr/lib/jvm/java-$VERSION-amazon-corretto"
    - export JDK_HOME="/usr/lib/jvm/java-$VERSION-amazon-corretto"
    - |-
      for tool_path in "$JAVA_HOME"/bin/*;
        do tool=`basename "$tool_path"`;
          if [ $tool != 'java-rmi.cgi' ];
            then
              rm -f /usr/bin/$tool /var/lib/alternatives/$tool \
                && update-alternatives --install /usr/bin/$tool $tool $tool_path 20000;
          fi;
      done

In the above runtime configuration, JAVA_HOME, JRE_HOME, and JDK_HOME are all pointing to "/usr/lib/jvm/java-$VERSION-amazon-corretto" whereas Corretto 22 installs at "/usr/lib/jvm/java-$VERSION-amazon-corretto.x86_64".

Current workaround
Manually overriding the environment variables to point to correct location of Corretto 22 fixes the issue and things start working.

version: 0.2
  phases:
    install:
      runtime-versions:
        java: corretto22
      commands:
        - JAVA_HOME="/usr/lib/jvm/java-$VERSION-amazon-corretto.x86_64"
        - JRE_HOME=${JAVA_HOME}
        - JDK_HOME=${JAVA_HOME}
    build:
      commands:
        - mvn package
@naiyerasif
Copy link
Author

If the workaround is an acceptable fix, I'm willing to create a PR for this change.

@darin-holloway
Copy link

This happened today for me on a
amazonlinux2-aarch64-standard:3.0 running a supported runtime (corretto17)

I'm going to file a support case as well to raise visibility. At least for me it appeared that JAVA_8_HOME and JAVA_11_HOME were defined correctly with the trailing .$arch but there was no definition of JAVA_17_HOME or JAVA_21_HOME to handle the supported runtimes, to say nothing of the original poster's case of custom runtimes.

@darin-holloway
Copy link

This got more interesting, it didn't match on

phases:
    install:
      runtime-versions:
        java: corretto17
``` in my buildspec but fell through to "Installing custom Corretto(OpenJDK) version 17" is that blank line at the top of the runtimes.yml screwing up the match behavior?  https://github.com/aws/aws-codebuild-docker-images/blob/1bd6ad2e247b957c8597fc31e172e3d2df185a19/al2/aarch64/standard/3.0/runtimes.yml#L6 and then cascading down to the failure in this issue

@leoherran-aws
Copy link
Member

I was not able to reproduce the reported issue for the amazonlinux2-aarch64-standard:3.0 image. Using the following buildspec with the image yielded the following output:

version: 0.2

phases:
  install:
    runtime-versions:
      java: corretto17
      
  build:
    commands:
      - echo $JAVA_HOME
      - echo $JRE_HOME
      - echo $JDK_HOME
[Container] Running command echo "Installing corretto(OpenJDK) version 17 ..."
Installing corretto(OpenJDK) version 17 ...

[Container] Running command export JAVA_HOME="$JAVA_17_HOME"

[Container] Running command export JRE_HOME="$JRE_17_HOME"

[Container] Running command export JDK_HOME="$JDK_17_HOME"

[Container] Running command for tool_path in "$JAVA_HOME"/bin/*;
 do tool=`basename "$tool_path"`;
  if [ $tool != 'java-rmi.cgi' ];
  then
   rm -f /usr/bin/$tool /var/lib/alternatives/$tool \
    && update-alternatives --install /usr/bin/$tool $tool $tool_path 20000;
  fi;
done

[Container] Moving to directory /codebuild/output/src257657082/src
[Container] Registering with agent
[Container] Phases found in YAML: 2
 INSTALL: 0 commands
 BUILD: 3 commands
[Container] Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
[Container] Phase context status code:  Message: 
[Container] Entering phase INSTALL
[Container] Phase complete: INSTALL State: SUCCEEDED
[Container] Phase context status code:  Message: 
[Container] Entering phase PRE_BUILD
[Container] Phase complete: PRE_BUILD State: SUCCEEDED
[Container] Phase context status code:  Message: 
[Container] Entering phase BUILD
[Container] Running command echo $JAVA_HOME
/usr/lib/jvm/java-17-amazon-corretto.aarch64

[Container] Running command echo $JRE_HOME
/usr/lib/jvm/java-17-amazon-corretto.aarch64/jre

[Container] Running command echo $JDK_HOME
/usr/lib/jvm/java-17-amazon-corretto.aarch64

@leoherran-aws
Copy link
Member

For the other (main) issue, I was able to reproduce that the corretto22 install path differs from other versions when installed as a custom runtime version. We are working on a fix and will update here when it is released.

@darin-holloway
Copy link

I just retested and couldn't reproduce the issue as well, thank you for the confirmation though and good luck on the other fix.

@leoherran-aws
Copy link
Member

This was fixed in edad5c3 and is released in the latest image versions.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants