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

automate building war files for pull requests #546

Closed
4 tasks done
jjgao opened this issue Dec 1, 2015 · 10 comments
Closed
4 tasks done

automate building war files for pull requests #546

jjgao opened this issue Dec 1, 2015 · 10 comments
Assignees

Comments

@jjgao
Copy link
Member

jjgao commented Dec 1, 2015

  • build a new war file for every pull request.
  • set up a public test database
  • deploy the new war file, named pr-1234.war?
  • ideally delete the war file after a PR is closed.

Deploy to OpenShift:
https://blog.openshift.com/how-to-build-and-deploy-openshift-java-projects-using-travis-ci/

Deploy to Heroku:
https://blog.travis-ci.com/2013-07-09-introducing-continuous-deployment-to-heroku/

You can also deploy Java Applications with the Heroku Maven Plugin:
https://devcenter.heroku.com/articles/deploying-java-applications-with-the-heroku-maven-plugin

@jjgao jjgao changed the title automate automate building war files for pull requests Dec 1, 2015
@inodb
Copy link
Member

inodb commented Dec 11, 2015

Getting close following this

https://devcenter.heroku.com/articles/java-webapp-runner

see https://github.com/inodb/cbioportal/tree/heroku

But when I run the following:

java -Djava.naming.factory.initial=org.apache.naming.java.javaURLContextFactory \
        -jar portal/target/dependency/webapp-runner.jar --port 9099 portal/target/portal

I get this error, any clue?

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityMapper' defined in class path resource [applicationContext-business.xml]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext-business.xml]: Cannot resolve reference to bean 'businessDataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'businessDataSource' defined in class path resource [applicationContext-business.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [java:comp/env/jdbc/xenograft] is not bound in this Context. Unable to find [java:comp].

@inodb
Copy link
Member

inodb commented Dec 14, 2015

Managed to fix this issue with a lot of help from Heroku's @jkutner. The code is on my heroku branch: https://github.com/inodb/cbioportal/tree/heroku. See an example here of a deployed PR:
screen shot 2015-12-14 at 4 59 14 pm
I have to clean up the heroku branch so it is a bit more clear which files are related to heroku, but other than that it works like a charm.

There are some costs involved that are worth discussing:

  • Public mysql db is hosted on Amazon. I'm not actually sure how much it would be if we would run the database 24/7. But I'm guessing 20-30$ per month. This cost could go down if we would make a smaller test database. There are alternatives such as using Heroku's db or Google's db service but I'm guessing that the price differences are negligible. I've send out an email to Amazon to inquire about non profit options.
  • Heroku can automatically create a review app for each PR. One "dyno" per heroku app is free, but having automatic builds for each PR could drive up the cost. An alternative is that the person opening the PR can click on the "deploy to heroku" button on the README and afterwards share the link to the heroku app that runs the PR manually. This would be free since each dyno would be linked to another person's account with the trade off that everyone will have to click two buttons and wait a bit when submitting a PR.

@jkutner
Copy link

jkutner commented Dec 14, 2015

Heroku has a free MySQL add-on, but it's limited to 10 connections, and 5MB of data. I'm not sure what your db requirements are, though.

The review apps actually create a new app. You can have one free dyno per app and each app can have it's own free DB. The only limitation is that an unverified account (i.e. one without a credit card attached) can only have 5 apps at a time. But since these apps are created on-demand from PRs, you just have to throttle how many things you are working on at once :)

I hope that helps. Let me know if you have any more questions.

@inodb
Copy link
Member

inodb commented Dec 14, 2015

Thanks for the comments, @jkutner. The mysql db at the moment is ~10GB. We might be able to shrink it down a bit in the future but not soon.

I didn't realize that each PR would spin up as a separate app. That's great!

@jjgao
Copy link
Member Author

jjgao commented Dec 15, 2015

Thanks, @inodb @jkutner! Cannot wait to test it. 👍

@inodb I think you should write a post about it :)

inodb added a commit to inodb/cbioportal that referenced this issue Dec 15, 2015
- Add webapp-runner.jar as dependency (used by heroku to run war)
- Add deploy to heroku button to README
- Remove unnecessary target directories after building war to decrease heroku's
  slug size (basically size repo + war)
- Add dbconnector spring property to allow using jndi or dbcp at runtime.
  Heroku's webapp-runner.jar does not seem to work with our setup of jndi.
- Add heroku specific property files (use amazon public db)
- There was a problem with PORTAL_HOME both being required at run time and build
  time. At Heroku the build directory is different from the run directory and
  currently there is no dynamic way to get the name of this dir. Scripts in
  profile.d are run on heroku before the war is started. This allows one to set
  the PORTAL_HOME variable there. The PORTAL_HOME variable at build time is set
  through a buildpack on github inodb/cbioportal-buildpack. This is why the
  extra buildpack is required.
- There is a heroku profile in pom.xml that copies all heroku specific files to
  the root dir of the portal when building the war. Only app.json has to be in
  the root dir for the deploy to heroku button to work.
inodb added a commit to inodb/cbioportal that referenced this issue Dec 15, 2015
- Add webapp-runner.jar as dependency (used by heroku to run war)
- Add deploy to heroku button to README
- Remove unnecessary target directories after building war to decrease heroku's
  slug size (basically size repo + war)
- Add dbconnector spring property to allow using jndi or dbcp at runtime.
  Heroku's webapp-runner.jar does not seem to work with our setup of jndi.
- There is a heroku profile in pom.xml that copies all heroku specific files to
  the root dir of the portal when building the war. Only app.json has to be in
  the root dir for the deploy to heroku button to work. Copy EXAMPLE property
  file to src/main/resources/portal.properties. Set custom properties on
  command line with maven in app.json (i.e. use amazon public db).
- There was a problem with PORTAL_HOME both being required at run time and build
  time. At Heroku the build directory is different from the run directory and
  currently there is no dynamic way to get the name of this dir. Scripts in
  profile.d are run on heroku before the war is started. This allows one to set
  the PORTAL_HOME variable there. The PORTAL_HOME variable at build time is set
  through a buildpack on github inodb/cbioportal-buildpack. This is why the
  extra buildpack is required.
@inodb inodb assigned n1zea144 and unassigned inodb Dec 16, 2015
n1zea144 added a commit that referenced this issue Dec 16, 2015
Fix #546 Allow deployment on Heroku
@inodb
Copy link
Member

inodb commented Dec 16, 2015

@jkutner One more question. It seems to work really well so far. Only problem with automatically creating apps for each PR is that when we click the checkbox there is a message that there is no app.json. It seems that each PR should have an app.json before selecting that option. Is it possible in some way to check that box without having to update all PRs? It's fine if most of them fail for now
screen shot 2015-12-16 at 1 53 30 pm

@jkutner
Copy link

jkutner commented Dec 16, 2015

@inodb do you have an app.json in your root dir? I don't see it on the default branch. That may be the problem.

There are some peculiar caveats with Heroku Button from a branch, and those may affect review apps in some way too. I think if you remove this from the app.json it may help:

"repository":"https://github.com/cbioportal/cbioportal",

@inodb
Copy link
Member

inodb commented Dec 16, 2015

Thanks @jkutner. I've tried removing the "repository" line from app.json but to no avail. I found a workaround though. If I change the default branch in the github settings, click the checkbox on heroku and then switch the default branch back to what it was, it works perfectly fine.

@jkutner
Copy link

jkutner commented Dec 16, 2015

@inodb ah, so it seems the validation when clicking the checkbox is just a safe guard, and may not actually have any effect on the behavior. I will check with the folks who own that feature to confirm.

@inodb inodb closed this as completed in a496cf9 Dec 16, 2015
@inodb inodb removed the in progress label Dec 16, 2015
@jkutner
Copy link

jkutner commented Dec 16, 2015

\o/ nice!

the button worked for me. it looks like its pushing the memory limits a bit, though. i'll see what i can do about that.

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

No branches or pull requests

4 participants