I've been experimenting with various ways of narrowing the gap between development and production, particularly for the lone developer or very small team. Here's an overview of how to get up and running with a maven Dropwizard project in Github and Heroku. I'm assuming a basic familiarity with git and maven.
I am indebted to Gary Rowe's blog entry for getting me started on this. He goes into deeper detail on several points than I do here.
Create a local Dropwizard project in maven
You can create the maven project itself quite easily from the command line:
Choose the default option. Let's say you call your project
git add .
git commit -m "my new project"
You've now created a new (empty) project in your local git reposity. All standard stuff.
Now you can write the code itself. I would suggest using Dropwizard's own tutorial. This will create a good old "hello world" example.
Create a github project
Now this step is optional. You could of course just push your changes to Heroku directly, but I like to keep my shared repository more general purpose - hence Github.
Once you're happy with the project and committed all the changes, you can push the changes to Github. There you can create your project (let's say it's called
myproject there too), and sync your local git and github. Github actually provides instructions on how to do this after you've created the project:
git remote add origin https://github.com/yourusername/myproject.git
git push -u origin master
From now own you can push locally committed git changes to github as follows:
git push origin master
Create a heroku project
Now you can push your changes to Heroku. Let's assume you have a Heroku account and have installed the Heroku toolbelt.
Inside your project you need to add a Procfile. Heroku uses this to determine how to run your application once it has been built. For a Dropwizard project this is quite simple:
web: java $JAVA_OPTS -Ddw.http.port=$PORT -Ddw.http.adminPort=$PORT -jar myproject/target/myproject-1.0-SNAPSHOT.jar server myproject/config.yaml
Now, once you've committed this you can push this project up to Heroku.
This will create a new app in Heroku. It will create it with a randomly generated name which you'll probably want to change. You can change this easily enough in the Settings section of the app on the Heroku website. Once you've done this you need to perform an extra step to update your local git remote configuration to reflect the new name. Let's say you changed it to
git remote rm heroku
heroku git:remote -a myproject
Now, finally, you can deploy:
git push heroku master
You should see the build taking place, and finally something like:
-----> Discovering process types
Procfile declares types -> web
-----> Compiled slug size: 57.7MB
-----> Launching... done, v9
http://myproject.herokuapp.com deployed to Heroku
df0d0b4..06a12b7 master -> master
If you now type
a browser will open pointing at your app. Each time you push to Heroku, you'll update the app running there.
Hopefully this is enough to get you started. I haven't covered some tidbits like creating your Heroku keys and other set up shenanigans, nor tuning your app Heroku settings. I refer the reader to the Heroku Java tutorial and Gary's aforementioned article for further details.
If you have any suggestions or corrections please let me know in the comments!