Following up our MongoDB Munich Thank You Post today we would like to show you how to deploy an application on CloudControl and use MongoSoup as the data storage. As an example we use a little web application that displays movies from The Movie Database. The source code is available on GitHub. So first of all:
What is MongoSoup?
MongoSoup is the first German-based MongoDB cloud hosting solution. Supported by our team of experts you can have a running MongoDB database in virtually no time.
What do you need?
First of all you need a CloudControl account. Therefore, go to console.cloudcontrolled.com and create an account and verify your email address. Then switch to your console.
If you haven’t already installed Git on your computer, get it from the official site or your package repository. For Windows it’s recommended to use the official installer and Git bash.
Afterwards you need to install cctrl the CloudControl command line client. For Linux and Mac OS X you can get it like this:
# if you don't have pip yet, first install pip $ sudo easy_install pip # then install cctrl $ sudo pip install cctrl
If you have problems on linux, you can also download it here and install it by running:
$ sudo python setup.py install
Windows user should download the installer. The file is named cctrl-x.x-setup.exe.
For more details see the CloudControl Getting Started Guide .
How to create a CloudControl application?
Afterwards create a new CloudControl Application, either online or by running the following comand with only the language you want:
$ cctrlapp APP_NAME create [java, php, python, ruby]
If your project uses Gradle, like we do here, you need to specify the buildpack like this:
$ cctrlapp APP_NAME create custom --buildpack https://github.com/comsysto/heroku-buildpack-gradle.git
If the buildpack is not suitable for you, you can fork and modify it like you need it.
How to add MongoSoup?
To add MongoSoup as Add-On to your application run:
$ cctrlapp APP_NAME/DEP_NAME addon.add mongosoup.sandbox
This will give you a free sandbox plan to play around with.
Now you can go to the web interface, select your application and your deployment. If you now go to the Add-Ons, you can click on the Credentials Button and see the link you will have to include in your application.
In our case it’s changing the spring-context.xml to use the Credentials class that is provided by CloudControl.
How to start the application?
Finally, CloudControl needs a Procfile in the main directory to start the application. In our case the content of the file is:
As we are using the gradle application plugin, the start file calls the outcoming script of running ‘gradle stage’ which depends on the ‘installApp’ task.
If your are not using gradle, it will be something like:
web: java -cp target/classes:target/dependency/* com.cloudcontrolled.java.jetty.example.App
You may also need to change the Java version to 1.7. In order to do so, create a system.properties file in the main directory with following content:
To get the right port for your application use:
as 8080 is not always the right port.
To test your application locally you can use foreman and execute ‘foreman start’ on your command line.
How to deploy your application?
As CloudControl is working with Git, commit your application either to your own git repository or the git repository provided by CloudControl. Be aware that by default the master brunch is taken for the default deployment. If you want to use another brunch, the name must be identical with your deployment name.
Now you can push your application to CloudControl by running:
$ cctrlapp APP_NAME push
Afterwards you deploy your application by running:
$ cctrlapp APP_NAME deploy
This can take some minutes. You can see the current status when you log in online to your CloudControl account.
Now your application is online hosted under http://APP_NAME.cloudcontrolled.com.
What may help if you have problems or need more information?
The CloudControl documentation is here: https://www.cloudcontrol.com/dev-center/Platform%20Documentation
For a Java Hello World example look at: https://www.cloudcontrol.com/dev-center/Guides/Java/HelloWorld
You can use SSH to connect directly as described here: https://www.cloudcontrol.com/dev-center/Platform%20Documentation#secure-shell-ssh
What is the demo based on?
The demo is based on the Spring Framework, MongoDB, Apache Wicket and Jetty. You can see the demo live deployed on CloudControl.
How can this demo be extended?
Starting with this little demo you can extend it as you wish to. If you are using The Movie Database, please create your own account here and use your own API key.