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

Update .gitpod.yml to use Java 21 by default #373

Merged
merged 8 commits into from
Dec 27, 2024

Conversation

SohamJuneja
Copy link
Contributor

@SohamJuneja SohamJuneja commented Dec 25, 2024

Fixes #367

Testing done

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@SohamJuneja SohamJuneja requested a review from a team as a code owner December 25, 2024 20:29
@krisstern krisstern mentioned this pull request Dec 26, 2024
6 tasks
Copy link
Member

@krisstern krisstern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, has any testing been done with this setup?

@krisstern krisstern changed the title Update .gitpod.yml to use java 21 by default Update .gitpod.yml to use Java 21 by default Dec 26, 2024
@SohamJuneja
Copy link
Contributor Author

SohamJuneja commented Dec 26, 2024

I applied desired changes but now getting a new error:
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.15.1:install-node-and-npm (install node and npm) on project design-library: Could not install Node: Could not find the downloaded Node.js binary in /workspace/design-library-plugin/node/tmp/node-v20.18.1-linux-x64/bin/node -> [Help 1]

I dont think that this error is just because of updation in gitpod.yml file but still trying to find what am I missing here.

After this error , when I use java -version it gives me the correct version :
openjdk version "21.0.4" 2024-07-16 LTS
which means that Java21 was installed successfully.

@krisstern
Copy link
Member

One quick fix is to revert change to add back curl -s "https://get.sdkman.io" | bash since my question was intended as a check but not necessary a request for change so you may want to keep it if it works that way.

If reverting does not work then maybe (I am not 100% sure unless we have tried) we should try to config the dependencies we will need using a custom Dockerfile called .gitpod.Dockerfile? From the look of things we will need at least both Java (https://www.gitpod.io/docs/introduction/languages/java) and JavaScript (https://www.gitpod.io/docs/introduction/languages/javascript).

@SohamJuneja
Copy link
Contributor Author

Yes, even after reverting the change and adding the curl back, I’m still encountering the same error. The error seems to persist regardless of the changes, and I am unable to pinpoint the exact cause. I have checked that Java 21 was successfully installed, as confirmed by the java -version output. I still suspect that the issue might not be entirely related to the recent changes in the gitpod.yml file, but I'm continuing to investigate

@krisstern
Copy link
Member

As mentioned in #374 (comment) @timja prefers to use Dockerfile for the Gitpod configuration. Would you be willing to adapt this PR with that change in mind?

@krisstern
Copy link
Member

Regarding your bug, you may want to add the required dependencies via both Java (https://www.gitpod.io/docs/introduction/languages/java) and JavaScript (https://www.gitpod.io/docs/introduction/languages/javascript using a Dockerfile instead.

@krisstern
Copy link
Member

In case you are not aware of already the Node.js referred to in

[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.15.1:install-node-and-npm (install node and npm) on project design-library: Could not install Node: Could not find the downloaded Node.js binary in /workspace/design-library-plugin/node/tmp/node-v20.18.1-linux-x64/bin/node -> [Help 1]

is not a Java dependency but a JavaScript dependency.

.gitpod.yml Outdated
- init: mvn install -P quick-build
- init: |
curl -s "https://get.sdkman.io" | bash
echo "sdkman_auto_answer=true" > $HOME/.sdkman/etc/config
Copy link
Member

@krisstern krisstern Dec 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, is this line L4:

      echo "sdkman_auto_answer=true" > $HOME/.sdkman/etc/config

really necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that line is necessary because without it, it prompts you to confirm whether you want to use Java 21 as the default version. By setting sdkman_auto_answer=true, it automatically answers "yes" to this prompt, making the setup seamless without requiring manual input.

@SohamJuneja
Copy link
Contributor Author

In case you are not aware of already the Node.js referred to in

[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.15.1:install-node-and-npm (install node and npm) on project design-library: Could not install Node: Could not find the downloaded Node.js binary in /workspace/design-library-plugin/node/tmp/node-v20.18.1-linux-x64/bin/node -> [Help 1]

is not a Java dependency but a JavaScript dependency.

Yes , I'm aware of that

@SohamJuneja
Copy link
Contributor Author

As mentioned in #374 (comment) @timja prefers to use Dockerfile for the Gitpod configuration. Would you be willing to adapt this PR with that change in mind?

Yes, I’ve started adapting the PR to use a Dockerfile for the Gitpod configuration, as mentioned in #374.

Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow https://www.gitpod.io/guides/custom-java-distribution-on-gitpod

The dockerfile approach looks to be the best

@SohamJuneja
Copy link
Contributor Author

Added a dockerfile , still the same error is coming:
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.15.1:install-node-and-npm (install node and npm) on project design-library: Could not extract the Node archive: Could not extract archive: '/workspace/m2-repository/com/github/eirslett/node/20.18.1/node-20.18.1-linux-x64.tar.gz'
Trying to resolve this now ( both node.js and java versions are installed correctly ) , installed 20.18.1 as it was referenced in this error multiple times.

@krisstern
Copy link
Member

May I ask how are you testing your new Gitpod environment? Could you provide some details about the steps you have taken?

@SohamJuneja
Copy link
Contributor Author

I’ve been testing the new Gitpod environment by configuring the Dockerfile to install the required versions of Java and Node.js, and adjusting the gitpod.yml file to use it. During the process, I ran into some issues that required trial and error, so I created a separate branch in my fork to test all the changes before merging them. I hope this isn’t considered a bad practice, but it helped ensure everything works as expected.

@krisstern
Copy link
Member

I’ve been testing the new Gitpod environment by configuring the Dockerfile to install the required versions of Java and Node.js, and adjusting the gitpod.yml file to use it. During the process, I ran into some issues that required trial and error, so I created a separate branch in my fork to test all the changes before merging them. I hope this isn’t considered a bad practice, but it helped ensure everything works as expected.

But how do you run the tests on Gitpod locally?

@SohamJuneja
Copy link
Contributor Author

To test the changes, I made modifications to the files locally and then pushed the changes to my branch. After that, I opened the branch directly in Gitpod, which automatically triggered the build process. During the build, all dependencies were installed at the start, and that’s when I encountered the error in the terminal.

@krisstern
Copy link
Member

I see, let me see if I can reproduce your issues

@krisstern
Copy link
Member

I have tweaked your code a bit in https://github.com/krisstern/design-library-plugin/tree/java21bydefault and have run everything again but I did not encounter any failures or errors. In fact, the following is what I see:

gp tasks attach 5fc6e2e1-1fbf-4a0d-bc8d-7dccf606b092
gitpod /workspace/design-library-plugin (java21bydefault) $ gp tasks attach 5fc6e2e1-1fbf-4a0d-bc8d-7dccf606b092
 HISTFILE=/workspace/.gitpod/cmd-1 history -r; {
gp ports await 8080 && gp url 8080 && gp preview $(gp url 8080)/jenkins/
}
gitpod /workspace/design-library-plugin (java21bydefault) $  HISTFILE=/workspace/.gitpod/cmd-1 history -r; {
> gp ports await 8080 && gp url 8080 && gp preview $(gp url 8080)/jenkins/
> }
Awaiting port 8080... ok
https://8080-krisstern-designlibrary-msaey2xybvr.ws-us117.gitpod.io
gitpod /workspace/design-library-plugin (java21bydefault) $ java --version
Picked up JAVA_TOOL_OPTIONS: -XX:+UseContainerSupport -XX:ActiveProcessorCount=1
openjdk 21.0.4 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode, sharing)
gitpod /workspace/design-library-plugin (java21bydefault) $ node --version
v20.18.1

The below is what I see in my browser:
Screenshot 2024-12-27 at 3 22 00 AM

@krisstern
Copy link
Member

The only major difference is that the .gitpod/Dockerfile I have is as follows:

FROM gitpod/workspace-full

ARG MAVEN_VERSION=3.9.9
ARG NODE_VERSION=20.18.1

# Install Java 21.0.4-tem and Node.js v20.18.1
RUN brew install gh && \
    bash -c ". /home/gitpod/.sdkman/bin/sdkman-init.sh && sdk install maven ${MAVEN_VERSION} && sdk default maven ${MAVEN_VERSION} && \
    sdk install java 21.0.4-tem && \
    sdk default java 21.0.4-tem" && \
    bash -c "source $HOME/.nvm/nvm.sh && nvm install ${NODE_VERSION} \
    && nvm use ${NODE_VERSION} && nvm alias default ${NODE_VERSION}"

# Ensure nvm uses the default version on every new terminal session
RUN echo "nvm use default &>/dev/null" >> ~/.bashrc.d/51-nvm-fix

@krisstern
Copy link
Member

But I will have to admit I may not need to have "mvn" installed... so you may want to clean that up a bit

@krisstern
Copy link
Member

And you may also want to set the Java JDK version as an ARG variable as well.

@SohamJuneja
Copy link
Contributor Author

@krisstern Thanks for the updates. I suspected there might be a configuration issue in my VS Code in gitpod, so I switched to IntelliJ IDEA, and it worked. Now, both your updates and my approach are running without errors. Could you let me know which one you think we should proceed with for the final code?

@krisstern
Copy link
Member

Yeah, for VSCode you will need to configure something additional like the devcontainer.json file to make things work, and I was using IntelliJ myself.

Copy link
Member

@krisstern krisstern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the .gitpod/Dockerfile file, can we use ARG for both the Java JDK version and the Node.js version?

@SohamJuneja
Copy link
Contributor Author

SohamJuneja commented Dec 27, 2024

Sure , updating the Dockerfile with the latest node version ( earlier it was 20.18.1 )

@@ -0,0 +1,19 @@
FROM gitpod/workspace-full:latest

USER gitpod
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering what is this for and do we really need this? I tried without this config and everything worked as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are used to specify a base image but ig Gitpod already uses these settings by default, so they can be removed without issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can run as root (user) by default, since we are using Gitpod this would not be too risky

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes , right . I am removing both of these lines and will check again on gitpod just for surity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I meant for the USER gitpod line only

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they have some formatting issue on GitHub, so if I comment on a line plesae only pay attention to the last line. This is a known issue with GitHub.

@krisstern krisstern requested review from timja and krisstern December 27, 2024 08:39
@@ -1,7 +1,3 @@
FROM gitpod/workspace-full:latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this line back

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes , even I ran without this and faced some error to load with default image only , adding it back .

@SohamJuneja
Copy link
Contributor Author

I've tested the changes, and everything is working fine now. Please let me know if any further modifications are needed

Copy link
Member

@krisstern krisstern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SohamJuneja Just tested your branch on Gitpod and it worked. Thanks for all the hard work put into this PR!

@SohamJuneja
Copy link
Contributor Author

Thanks a lot for your guidance too! @krisstern @timja

Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@timja timja merged commit fcccabb into jenkinsci:master Dec 27, 2024
17 checks passed
@SohamJuneja SohamJuneja deleted the java21bydefault branch December 28, 2024 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automate Java 21 Installation in gitpod.yml
3 participants