Is it possible to deploy a raw Java web app to Heroku? - heroku

Very inexperienced user here...please be patient!
I inherited maintenance of Heroku app from someone no longer with the company. Having to re-deploy an app update is probably a once-a-year event, and here we are.
The instructions I have include building a standalone jar file containing my app and then deploying it to Heroku. Specifically the procedure for this is to use the Heroku CLI with the following command:
heroku deploy:jar webapp.jar -a my-app
Easy enough. Except he had his own instance of the Heroku CLI, and when I went to download my own copy, it appears that the deploy command no longer exists! Is this the case? Is this a deprecated command? Do I need to go through the process of figuring out how to set up a git repository to deploy this? (We are in fact using git to manage the source for this app, but it's behind our company firewall, so I'm not sure how practical/difficult it will be to set this up for Heroku). I just want to make sure I'm not missing something simple before investing a significant amount of time re-inventing the deployment process. Thanks.

The most popular mechanism is indeed to push the code from git to Heroku, providing the necessary files (i.e. profcile) to deploy the runtime.
An alternative is to create a Docker image and push it to the Heroku Registry (which in your case would require more reworking).
Refer to Deploy with Git, the firewall should not be a problem as Heroku will not access your code, but you will need to perform the push (git push heroku master)

I have to answer my own question because I was able to find the solution.
It turns out there is a plugin available for the heroku CLI that provides the deploy command. Running heroku plugins:install java will install the plugin that provides the deploy command in the heroku CLI.
See https://devcenter.heroku.com/articles/deploying-executable-jar-files for more information.

Related

Heroku - access errors - how to select app

I am trying to get heroku setup locally on my new laptop to be able to access an existing heroku account that has two existing rails apps on it. I was able to install heroku cli locally and I was able to login to heroku. If I run "heroku apps" it lists my two apps. But two things I need help with:
1) I can't remember how to tell heroku which app the git repo in the current folder on my laptop should work with on heroku server. in other words, how do i "select" which app i want to current work with after logging into heroku.
2) when I tried running the "heroku config" command to list existing config vars after logging it it gave me some kind of error message. need some suggestions on what might be causing that too.
Sorry to not include screen shots of errors but on a different company right now. hopefully you can at least help me answer the first question.
Thanks,
Edward
ps. I found this Q&A, does the answer here apply to my question (1)?
How to link a folder with an existing Heroku app
The cause turned out to be that I needed to add the heroku app location as a remote repo using the heroku cli from within my local git repo I had created. I used the following command:
heroku git:remote -a thawing-inlet-61413
where "thawing-inlet-61413" is the name of the app. You can get this by running:
heroku apps
and it will list them.
reference: https://devcenter.heroku.com/articles/git#creating-a-heroku-remote

How to run InfluxDB on Heroku?

Is it possible, and if so, how? I'd like to be able to reach it from my existing Heroku infrastructure.
Will I need a Procfile? From what I understand it's just a standalone binary written in Go! so it shouldn't be that hard to deploy it, I'm just curious how to deploy it because I don't think I understand the ins and outs of Heroku deployment.
Heroku Dynos should not be used to deploy a database application like InfluxDB.
Dynos are ephemeral servers. Data does not persist between dyno restarts and cannot be shared with other dynos. Practically speaking, any database application deployed on a dyno is essentially useless. This is why databases on Heroku (e.g. Postgres) are all Add-ons. InfluxDB should be set up on a different platform (like, AWS EC2 or a VPS) since a Heroku Add-on is not available.
That said, it is possible to deploy InfluxDB to a Heroku dyno.
To get started, it is important to understand the concept of a 'slug'. Slugs are containers (similar to a Docker images) which hold everything needed to run a program on Heroku's infrastructure. To deploy InfluxDB, an InfluxDB slug needs to be created.* There are two ways to create a slug for Go libraries:
Create a slug directly from a Go executable as described here.**
Build the slug from source using the Heroku Go buildpack (explained below).
To build the slug from source using a buildpack, first clone the InfluxDB Github repo. Then add a Procfile at the root of the repo, which tells Heroku the command to run when the dyno starts up.
echo 'web: ./influxd' > Procfile
The Go buildpack requires all dependencies be included in the directory. Use the godep dependency tool to vendor all dependencies into the directory.
go get github.com/tools/godep
godep save
Next, commit the changes made above to the git repo.
git add -A .
git commit -m dependencies
Finally, create a new app and tell it to compile with the Go buildpack.
heroku create -b https://github.com/kr/heroku-buildpack-go.git
git push heroku master
heroku open // Open the newly created InfluxDB instance in the browser.
Heroku will show an error page. An error will be displayed because Heroku's 'web' process type requires an app to listen for incoming requests on the port described by the $PORT environment variable, otherwise it will kill the dyno. InfluxDB's API and admin panel run on ports 8086 and 8083, respectively.
Unfortunately, InfluxDB does not allow those ports to be set from environment variables, only through the config file (/etc/config.toml). A small bash script executed before InfluxDB starts up could set the correct port in the config file before InfluxDB starts up.
Another problem, Heroku only exposes one port per dyno so the API and the admin panel cannot be exposed to the internet at the same time. A smart reverse proxy could work around that issue using Heroku's X-Forwarded-Port request header.
Bottom line, do not use Heroku dynos to run InfluxDB.
* This means the benefits of a standalone Go executable are lost when deploying to Heroku, since it needs to be recompiled for Heroku's stack.
** Creating a slug directly from the InfluxDB executable does not work because there is no built-in way to listen to the right port given by Heroku in the $PORT environment variable.
I like to think anything is possible on a Heroku node when using a custom buildpack, but there are some considerations when hosting with Heroku:
ops, e.g. backup, monitoring (does it entail installing extra services, opening extra ports, etc - Heroku might get in the way here)
performance, considering dyno size
and if you need a larger dyno, cost becomes an issue. You'll get more bang for your buck when you go the IaaS route.
other "features" of a dyno, e.g. disk ephemerality
I highly recommend hosted InfluxDB or spinning up your own on a VPS, all of which you can point your existing Heroku-based apps to. It will then help to get those instances as close together as possible (i.e. same region, or co-located if possible), presuming a need for low latency between DB and app stack.

Deploying a Github App on Heroku

I have been trying to deploy from a GitHub repository to Heroku. For pushing my changes to GitHub I am using Mac UI Client for GitHub.
Now in the heroku app setup, I changed at https://dashboard.heroku.com/apps/myapp/settings . Here I made changes in option GitHub Rep (Link your app to a GitHub repository to see commit diffs in the activity log.). I added as my github-user/repository-name
Now when i use myappname.heroky.com I am redirected to a default page which says :
Heroku | Welcome to your new app! Refer to the documentation if you
need help deploying.
In the documentation it is all commands which is going over me since i use Github UI tool.
Any idea if this can be deployed w/o using the commands?
I am asking this particular thing, since last time I used AppHarbor and it simply pulled my github rep w/o any hiccups.
Adding your GitHub repo to the Heroku app settings will not set up automatic deployments. It just allows Heroku to provide commit information in the app logs.
To achieve what you are looking for, you need to set up continuous deployment (or "CD"). The easiest way to do this is with a continuous integration (or "CI") solution.
One common CI server is Jenkins, though that will require you to set it up manually. Nowadays, there are several automated CI/CD services you can take advantage of, including Travis, CircleCI, Codeship, Snap. All of them have options to automatically deploy to Heroku after building your app (which can be trigger by a push to GitHub).

How can i create a clone of an existing app on heroku from another heroku app as separate app?

I have a main app on heroku and another app A on git in location github:a.
I want to create, when it is necessary, copies of A as A1,A2,A3...AN as separate apps on heroku from my main app automatically with different parameters.
How can i do that?
Edit: This process should be done by my main app automatically.
Updating this answer due to Heroku command DEPRECATION:
heroku fork has been deprecated as a core command as of 12/01/2017.
You will need to install the heroku-fork plugin to continue using this command.
heroku plugins:install heroku-fork
Here is a link to the Github plugin repo.
Use heroku fork to copy an existing application, including add-ons, config vars, and Heroku Postgres data.
See this KB page: Forking Applications.
Heroku toolbelt now provides a fork method to clone an existing application, see my answer here :
how to clone a project on heroku
There is a new feature on Heroku called Review Apps. One can create copies of the app manually or set up automatic copies from new PRs on Github.
Read more at: https://devcenter.heroku.com/articles/github-integration-review-apps
Simply create new applications and push your code to them. If you need to copy data, checkout the pgbackups transfers.
For management purposes, check out this dev center article.
To do this programatically, you'll need to look at the Heroku gem, and then figure out a way of getting something to git push to the appropriate remote. I would be surprised if this was possible to be honest.

How do I setup the Heroku CLI app?

It's a pretty simple problem. I need to get my heroku CLI app working with an app I have. I already have the git repo checked out (from github though, not sure if that matters).
A google search suggests this page is the place to go to get help, but the page doesn't tell me anything useful:
http://devcenter.heroku.com/articles/heroku-command
If you've already checked out the code all you need to need is setup a git remote pointing at heroku.
Locate your apps Gtit url - easiest place is from the 'My Apps' on Heroku in the 'Git Repo' panel, it will look something like git#heroku.com:stark-beach-5145.git
Back in your local git repo do (replacing with your app URL):
git remote add heroku git#heroku.com:stark-beach-5145.git
Now you will be able to perform git push heroku etc.
However, if you just want to use heroku commands as long as you explicitly pass in the application name you don't actually need to perform steps 1 and 2 above. eg
heroku ps --app <appname>
would show you the running processes for your application etc. Here appname is the name of the app as listed on the 'My Apps' page.

Resources