PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/ReadMe.md

https://bitbucket.org/antaresgruppen/fagm-te-2013-05-heroku
Markdown | 199 lines | 142 code | 57 blank | 0 comment | 0 complexity | 8edd2503ad2cd1bf212b251341dabcfd MD5 | raw file
  1. # Prerequisites
  2. Basic Java knowledge, including an installed version of the JVM and [Maven 3][mvn].
  3. A credit card is needed for bonus excercise with mongoDb.
  4. Your own domain-name is for bonus excercise where you connect one (+ login to your DNS hosting).
  5. **DOS:** you need administrator access while doing this workshop.
  6. Ambitious attendees have read [The twelve-factor app][12fact].
  7. Most interesting: [Dev/prod parity][devprod]
  8. [Vagrant][vagrant]
  9. [Debugging JVM Programs on Heroku][debug]
  10. Tip: If you did try Heroku earlier, use same user now.
  11. You want to avoid having several users for heroku (or git) on the same computer, lest you want to go through the hassle of managing ssh-keys. See [ref that saved me][2ssh] with comment by Tom Carchrae.
  12. # In to the cloud
  13. ## Register and install
  14. "Sign up" on [Heroku][heroku].
  15. Click confirm link in the email you received.
  16. After submitting a password you will be taken to "Getting started".
  17. Install the "Heroku Toolbelt" (link on "Getting started").
  18. Try `heroku help` (command line) to see if all is well.
  19. The Heroku Toolbelt gives access to the [Heroku command-line client][herokucli], [Foreman][procfile], and the Git revision control system.
  20. *15 minute mark*
  21. ## Local checkout and build
  22. :::term
  23. git clone https://bitbucket.org/antaresgruppen/fagm-te-2013-05-heroku.git
  24. cd path-to-project
  25. mvn package
  26. export PORT=5000
  27. (DOS: set PORT=5000)
  28. java -cp target/classes:"target/dependency/*" HelloWorld
  29. (DOS: java -cp target/classes;"target/dependency/*" HelloWorld)
  30. (double quotes needed to prevent expansion of `*`)
  31. See that it works locally (*http://localhost:5000/*).
  32. Stop application with SIGTERM (ctrl+c).
  33. ## Pushing to Heroku
  34. **DOS:** you must add git/bin to PATH (for ssh key generation).
  35. Choose to add ssh key, be wary of dropped network or other problems. If bad shit happens before first push, you may be served well to start with a clean slate (check out new version and continue below).
  36. :::term
  37. heroku login
  38. heroku create
  39. git push heroku master
  40. heroku open
  41. The above is first time only (when creating).
  42. Later, commit changes before pushing to Heroku:
  43. :::term
  44. heroku login
  45. git commit -m 'message here'
  46. git push heroku master
  47. heroku open
  48. If you need to see logs: `heroku logs`, or `heroku logs -t`
  49. *30 minute mark*
  50. # What happened?
  51. Heroku will:
  52. 1. recognize the application as Java by the existence of pom.xml
  53. 2. build it using Maven as build tool
  54. 3. set the environment variable *PORT*, identifying the HTTP port to which the web process should bind (and some other variables).
  55. 4. run the application with the command given in *procfile*
  56. The application's *HelloWorld* class contains a *main* method that configures and starts up an embedded Jetty server. The welcome file is a static html file.
  57. What is the url to acess the servlet itself?
  58. Note that Heroku runs your application on the [OpenJDK](http://openjdk.java.net/) version 6 or 7 (8 available in beta).
  59. ## Logging and debugging
  60. There is a slight problem with CV-servlet, try url *http://<your server>/cv/bad* and check log from server.
  61. Look at the code written.
  62. How are errors logged?
  63. How should you log debug / info?
  64. Hint: request routing is found in *HelloWorld.main(...)*.
  65. # À la carte
  66. Choose from below
  67. ## Custom Domain
  68. Read and follow [about custom domains on Heroku][cname].
  69. Then use your DNS Service administrative interface to add a CNAME record that point the chosen name to your heroku application.
  70. ## Postgres Addon
  71. Read and follow [Heroku Postgres][heroku-postgres] to setup database.
  72. The code to use database is written in *Postgres.java*, except you need to pass uri to constructor.
  73. Hint: read through "Establish primary db".
  74. Hint: read also "Connecting in Java".
  75. ## MongoHQ Addon
  76. Before you can use MongoHQ addon, you need to "[verify][verify]" your account (enter credit card). According to [billing][billing], only addons heroku-postgresql:dev and pgbackups:plus are excempted.
  77. Verified? go on - read and follow [Heroku MongoHQ][mongohq] to setup database.
  78. The code to use database is written in *MongoDB.java*, except you need to pass uri to constructor.
  79. Hint: check table of contents, only 2 sections relevant from setup page.
  80. # Optional extras
  81. For when you completed the above
  82. ## Run a worker process
  83. The [Java workbook][javamore] has an excercise that shows how you can run a worker process. Remember to stop it before free dyno-hours tick away.
  84. ## Run a [One-off dyno][oneoffdyno]
  85. For example, use it to set up database.
  86. `heroku java -cp target/classes:"target/dependency/*" Postgres`. Or any other class with a *main(...)*.
  87. ## Local access to Postgres or MongoHQ?
  88. Snoop the connection url and see if you can get to cloud database from your own PC.
  89. ## OAuth 2 [Google][gooauth]
  90. Sharing done through external service.
  91. # Resources
  92. This [workshop][fagm] is evolved from from the [Java demo application](https://github.com/heroku/devcenter-java) on GitHub.
  93. ## Heroku and Java
  94. [Introduction to Heroku for Java Developers][javaintro]
  95. [Java][javaheroku] on Heroku
  96. Heroku [Java devcenter][javadev]
  97. Getting [Started with Java on Heroku][javastart]
  98. Learn [more about Heroku for Java][javamore]
  99. ## Heroku
  100. [Heroku dashboard][dash]
  101. [Heroku addons][addons]
  102. [Applying the Unix Process Model to Web Apps][unixproc]
  103. [The twelve-factor app][12fact]
  104. ## More sample code
  105. PostgreSql [Hello World][hellopostgres], MongoDb [from Java][javamongo] and MongoDb [Hello World][hellomongo].
  106. [Handlebars.js][handlebars]
  107. -------------------------------------------------
  108. [heroku]: http://www.heroku.com "Heroku site"
  109. [dash]: https://dashboard.heroku.com/apps "Heroku dashboard"
  110. [herokucli]: http://devcenter.heroku.com/categories/command-line "Heroku command-line client"
  111. [billing]: https://devcenter.heroku.com/categories/billing "Heroku: billing"
  112. [verify]: https://devcenter.heroku.com/articles/account-verification "Heroku: verify account"
  113. [oneoffdyno]: https://devcenter.heroku.com/articles/one-off-dynos "Heroku: One-off dyno"
  114. [procfile]: https://devcenter.heroku.com/articles/procfile "Heroku: procfile"
  115. [javaintro]: https://devcenter.heroku.com/articles/intro-for-java-developers "Java intro"
  116. [javaheroku]: http://java.heroku.com "Java on Heroku"
  117. [javadev]: https://devcenter.heroku.com/categories/java "Java on Heroku devcenter"
  118. [javastart]: https://devcenter.heroku.com/articles/java "Getting Started with Java on Heroku"
  119. [javamore]: https://devcenter.heroku.com/articles/java-learn-more "Learn more about Heroku for Java"
  120. [mongohq]: https://devcenter.heroku.com/articles/mongohq "MongoHQ addon"
  121. [hellomongo]: http://www.mkyong.com/mongodb/java-mongodb-hello-world-example/ "MongoDb Hello World"
  122. [javamongo]: http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-java-driver/ "Getting started with MongoDB Java"
  123. [postgresql]: https://addons.heroku.com/heroku-postgresql "postgresql addon"
  124. [heroku-postgres]: https://devcenter.heroku.com/articles/heroku-postgresql "Heroku Postgres doc"
  125. [hellopostgres]: https://github.com/heroku/devcenter-java-database "postgresql Hello World"
  126. [neo4j]: https://devcenter.heroku.com/articles/neo4j "neo4j addon"
  127. [cname]: https://devcenter.heroku.com/articles/custom-domains "About custom domains"
  128. [gooauth]: https://developers.google.com/accounts/docs/OAuth2 "Google OAuth 2"
  129. [addons]: https://addons.heroku.com/ "Heroku addons"
  130. [unixproc]: http://adam.heroku.com/past/2011/5/9/applying_the_unix_process_model_to_web_apps/ "Blog post on unix process model"
  131. [12fact]: http://www.12factor.net/ "The twelve-factor app"
  132. [devprod]: http://www.12factor.net/dev-prod-parity "Dev/prod parity"
  133. [vagrant]: http://www.vagrantup.com/ "vagrant site"
  134. [debug]: http://mikeslinn.blogspot.no/2012/09/debugging-jvm-programs-on-heroku.html "Debugging JVM Programs on Heroku"
  135. [handlebars]: http://handlebarsjs.com/ "handlebars js"
  136. [mustache]: http://mustache.github.com/ "mustache js"
  137. [fagm]: https://bitbucket.org/antaresgruppen/fagm-te-2013-05-heroku "Hands-on instructions"
  138. [mvn]: http://maven.apache.org/download.html "Maven download"
  139. [ssh]: http://stackoverflow.com/questions/11440683/heroku-key-not-accepted "ssh key not accepted"
  140. [herssh]: https://devcenter.heroku.com/articles/keys "Heroku ssh keys"
  141. [2ssh]: http://stackoverflow.com/questions/8786564/cannot-push-to-heroku-because-key-fingerprint "Post that saved my assh"
  142. []: ""