heroku / cli

Heroku CLI
https://devcenter.heroku.com/articles/heroku-cli
ISC License
854 stars 224 forks source link

Bug: Installation of java plugin fails #2034

Closed lorddoig closed 6 months ago

lorddoig commented 2 years ago

Note: Detailed traces in the linked gists as they were too large to post here.

Since the v7.62.0 CLI release heroku plugins:install java is consistently failing. Initially it required a newer version of python, but when that's provided this error occurs on Debian 9 and Debian 10. Upgrading build-essential or testing with Ubuntu 20.04 gives this error. Using python2 vs python3 appears to make no difference. The second error also appears to cause the CLI to hang on various commands and never complete (process only exits when sent kill signal).

This is having quite serious consequences for my organisation (and presumably others) as all our java deployment pipelines are broken and methods to pin the CLI tool to a particular version are convoluted/unsupported. A support ticket has also been raised in which it was suggested to use the command heroku plugins:install @heroku-cli/plugin-java but this exhibits the same problems.

Tested with the following docker images:

Steps to reproduce

Where $IMAGE is taken from the above list:

  1. docker run -it $IMAGE /bin/bash
  2. [ -z "$JAVA_HOME" ] && sudo apt-get update && sudo apt-get install -y openjdk-11-jdk
  3. curl https://cli-assets.heroku.com/install.sh | sh
  4. heroku plugins:install java
  5. IF install complains of outdated python version
    1. sudo apt-get update && sudo apt-get install -y python3 or manually install a suitable python by another method
    2. GOTO 4
  6. IF installer can't find g++
    1. sudo apt-get update && sudo apt-get install -y build-essential
    2. GOTO 4
edmorley commented 2 years ago

@heroku/front-end Please could you take a look at this? It seems the latest (semver minor) CLI release has broken some existing CLI plugins.

tevanoff commented 2 years ago

@lorddoig I'm sorry for the trouble here. I was able to replicate this using your very helpful steps, thanks for that! After digging a bit, it does look like this is due to an update to the oclif framework that was pulled in to this latest release.

oclif has a feature that let's you use a friendly name to install a plugin. In the case of the Heroku CLI, when you run heroku plugins:install java, that java name will resolve to the real npm package named @heroku-cli/plugin-java.

The change in question slightly tweaked how that resolution check is done. Instead of using https to look for the package on npm, it now shells out to the npm command. But in the case of your docker image, the npm command likely does not exist, and instead of failing, things move forward as if that package does not exist. This results in the wrong package named java being installed. This is not a valid oclif plugin, so it breaks things.

We can see this name resolution failure in the debug output you included: https://gist.github.com/lorddoig/aee13264a3a2a9ef68d6f31b38cfadb8#file-err1-txt-L285-L286

We'll figure out the best way to remedy this over here. In the meantime, you should be able to use the full package name to install (heroku plugins:install @heroku-cli/plugin-java).

I know you mentioned above that heroku plugins:install @heroku-cli/plugin-java did not work for you, but I'm wondering if you tried that in a clean container, or in a container where heroku plugins:install java was already run? In the latter case, my testing has shown that things are left in a broken state and retrying the install using the full package name won't work. But in a container where the short name version of the install has not been run, the full name version seems to work fine, at least with a couple of the images I tried out from your list above. Please let us know if that's definitely not the case for you.

Thanks for letting us know about this, and thanks again for the helpful debugging info! 😄

lorddoig commented 2 years ago

@tevanoff Thanks for the prompt response, and for the technical detail in your reply! 😃

You're quite correct: it does work when you specify the plugin as @heroku-cli/plugin-java, just as your colleague suggested in the support ticket 🤦‍♂️ I must have run it on a dirty container like you said. So this resolves our issue, thank you very much!

Just one question: is there any reason we should not specify the plugin in this way in our CI jobs for the foreseeable future? Or should we revert back to heroku plugins:install java when (if?) this gets fixed? I understand it might be a bit of an edge case to be running this on a machine that doesn't have npm installed.

Thanks again!

tevanoff commented 2 years ago

@lorddoig Oh good, I'm glad that's working for you! And you probably already noticed this, but you shouldn't need to update python or build-essential either as both of those were required for the java package that was being erroneously installed. Sorry for the runaround! We'll see what we can do to fix this or at least make the failure more clear. It is a bit of an edge case but still one that we want to support.

As for your question, I'll leave this open and we'll update it if you want to switch back to the short name version at some point, but sticking with the full name should be fine as that's not likely to change.

Thanks again!

sbosio commented 6 months ago

I will close this issue because it looks as if it was solved. But I want to leave here for reference that moving forward, the only supported way to deploy Java applications in Heroku platform is by means of the new Heroku JVM Application Deployer that's an independent tool which doesn't requires Heroku CLI to run.