0

I'm looking for a way to run Heroku CLI commands within a java application hosted on Heroku.

I'd like to be able to run commands like heroku pg:backup heroku pg:restore etc

Is there a way to do that ?


EDIT : I added the Heroku CLI to my app, now I'm looking for a way to invoke heroku commands from my java code.

Maybe you could use something like this :

ProcessBuilder pb = new ProcessBuilder("/path/to/herokuCLI", "myCommand");

Problem is I don't know how to find the right path.

If you look at the file structure of your app on Heroku you can only find your .war + some "configuration files" which is quite normal as you only push a war to Heroku : Procfile system.properties target

Besides I don't think that's the right way to do that.
I'd like to avoid doing backup/restore operations in pure java code.
Maybe you can't rely on Heroku cmd to do the job for you after all.

1

1 Answer 1

2

You'll need to add the Heroku CLI buildpack to your application. You can do so with: heroku buildpacks:add heroku-community/cli

Push a new build after you've done so and you'll now be able to run CLI commands from inside your application dynos. You can see some additional information about this in the documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.