Get Started with CloudCaptain & JHipster

 

This tutorial will get you started with CloudCaptain and JHipster. It should take you about 5-10 minutes to complete.

Prerequisites

Before you begin, ensure you have successfully:

  1. created a CloudCaptain Account (simply log in with your GitHub account, it's free)
  2. downloaded and installed the latest CloudCaptain Client
  3. downloaded and installed the latest version of JHipster (including Git, Node.js, Yeoman, Bower, Gulp and JHipster itself)
  4. downloaded and installed the latest version of VirtualBox
  5. downloaded and installed the latest JDK with JAVA_HOME set up correctly

Creating the JHipster application

Start by creating a new directory:

> mkdir getstarted-jhipster

And navigate to it:

> cd getstarted-jhipster

Now create the application:

getstarted-jhipster> yo jhipster

And select all defaults except for the database where you should pick PostgreSQL instead and for the internationalization where you can say no.

Once that's done, set the project version to 1.0 in pom.xml:

...
<version>0.0.1-SNAPSHOT</version>
<version>1.0</version>
...

Your application is now fully set up. Go ahead and build it:

getstarted-jhipster> mvnw -Pprod -DskipTests package

Great. Your Spring Boot application is now available under target/jhipster-1.0.war.

Fusing a CloudCaptain image and running it locally on VirtualBox

Now it's time to fuse your application into a CloudCaptain image and launch an instance of it on VirtualBox:

getstarted-jhipster> boxfuse run

Creating jhipster ...
Mapping jhipster-dev-myuser.boxfuse.io to 127.0.0.1 ...
Created App jhipster (single-instance / postgresql)
Fusing Image for jhipster-1.0.war (JHipster) ...
Image fused in 00:05.036s (96301 K) -> myuser/jhipster:1.0
Creating CloudCaptain Dev VM for myuser/jhipster ...
Starting CloudCaptain Dev VM for myuser/jhipster ...
Exposing Dev VM PostgreSQL database port on localhost:5432
Waiting for database instance to start ...
Launching Instance of myuser/jhipster:1.0 on VirtualBox ...
Forwarding http port localhost:8080 -> vb-2dc97023:8080
Instance launched in 00:04.490s -> vb-2dc97023
Waiting for Payload to start on vb-2dc97023:8080 (expecting HTTP 200 at / within 300s) ...
Payload started in 00:10.041s -> https://127.0.0.1:8080

CloudCaptain has automatically detected the PostgreSQL dependency and used the 8080 port to check whether the instance came up correctly.

Open a browser at this address to see your new application up and running within the VirtualBox VM by simply executing:

getstarted-jhipster> boxfuse open

You can also see your newly created image:

getstarted-jhipster> boxfuse ls

Images available locally:
+---------------------+------------------+-------+--------------------------+--------------+---------+---------------------+
| Image               |     Payload      | Debug |         Runtime          |    Ports     |  Size   |    Generated at     |
+---------------------+------------------+-------+--------------------------+--------------+---------+---------------------+
| myuser/jhipster:1.0 | jhipster-1.0.war | false | Java 8.102.14 (JHipster) | http -> 8080 | 96301 K | 2016-08-17 23:30:21 |
+---------------------+------------------+-------+--------------------------+--------------+---------+---------------------+
Total: 1

As well as the instance that is running:

getstarted-jhipster> boxfuse ps

Running Instances on VirtualBox in the dev environment :
+-------------+---------------------+---------------------+-----------------------+---------------------+
|  Instance   |        Image        |        Type         |          URL          |     Launched at     |
+-------------+---------------------+---------------------+-----------------------+---------------------+
| vb-2dc97023 | myuser/jhipster:1.0 | 4 CPU / 1024 MB RAM | https://127.0.0.1:8080 | 2016-08-17 23:30:47 |
+-------------+---------------------+---------------------+-----------------------+---------------------+
Total: 1

Deploying your application to AWS

Now let's deploy the image to AWS. As CloudCaptain works with your AWS account, it first needs the necessary permissions to do so. So if you haven't already done it, go to the CloudCaptain Console and connect your AWS account now.

Every new CloudCaptain account comes with 3 environments: dev, test and prod. dev is your local VirtualBox environment and test and prod are on AWS.

So let's deploy our application to the prod environment on AWS:

getstarted-jhipster> boxfuse run -env=prod

Pushing myuser/jhipster:1.0 ... Verifying myuser/jhipster:1.0 ... Creating security group boxsg-db-myuser-prod-jhipster ... Creating RDS PostgreSQL database (db.t2.micro / 5 GB / single-az) => boxdb-myuser-prod-jhipster (this one-time action may take up to 10 minutes to complete) ... Waiting for AWS to create an AMI for myuser/jhipster:1.0 in eu-central-1 (this may take up to 50 seconds) ... AMI created in 00:35.564s in eu-central-1 -> ami-35fa0b5a Waiting for AWS to make RDS DB boxdb-myuser-prod-jhipster available ... DB boxdb-myuser-prod-jhipster [creating] DB boxdb-myuser-prod-jhipster [backing-up] DB boxdb-myuser-prod-jhipster [available] Creating security group boxsg-myuser-prod-jhipster ... Creating Elastic IP ... Mapping jhipster-myuser.boxfuse.io to 52.29.78.197 ... Creating security group boxsg-myuser-prod-jhipster-1.0 ... Launching t2.micro instance of myuser/jhipster:1.0 (ami-35fa0b5a) in prod (eu-central-1) ... Instance launched in 00:20.687s -> i-95d15028 Creating Cloud Watch Alarm for Instance auto-recovery -> i-95d15028-auto-recovery-alarm Waiting for AWS to boot Instance i-95d15028 and Payload to start at https://54.93.63.207:8080/ ... Payload started in 01:29.685s -> https://54.93.63.207:8080/ Remapping Elastic IP 52.29.78.197 to i-95d15028 ... Waiting 15s for AWS to complete Elastic IP Zero Downtime transition ... Deployment completed successfully. myuser/jhipster:1.0 is up and running at https://jhipster-myuser.boxfuse.io:8080/

Notice that CloudCaptain has reused your image unchanged instead fusing a new one.

With that one command CloudCaptain has automatically pushed your image to the CloudCaptain Vault as well as provisioned, configured and secured all necessary AWS resources. There is no manual work necessary on your behalf.

All you need to do is simply navigate to your new domain to see your JHipster application in action on AWS:

Bonus: update your application with zero downtime

Now let's take things one step further and deploy an update of your application with zero downtime using blue/green deployments.

Start by modifying src/main/webapp/app/home/home.html and change the message:

...
<h1>Welcome, Java Hipster!</h1>
<h1>Updated by CloudCaptain with zero downtime!</h1>
...

then bump the version in pom.xml:

...
<version>1.0</version>
<version>2.0</version>
...

and rebuild the war:

getstarted-jhipster> mvnw -Pprod -DskipTests package

Finally deploy the new version of your application to AWS:

getstarted-jhipster> boxfuse run -env=prod

Fusing Image for jhipster-2.0.war (JHipster) ...
Image fused in 00:05.059s (96302 K) -> myuser/jhipster:2.0
Pushing myuser/jhipster:2.0 ...
Verifying myuser/jhipster:2.0 ...
Waiting for AWS to create an AMI for myuser/jhipster:2.0 in eu-central-1 (this may take up to 50 seconds) ...
AMI created in 00:38.463s in eu-central-1 -> ami-22fa0b4d
Waiting for AWS to make RDS DB boxdb-myuser-prod-jhipster available ...
Creating security group boxsg-myuser-prod-jhipster-2.0 ...
Launching t2.micro instance of myuser/jhipster:2.0 (ami-22fa0b4d) in prod (eu-central-1) ...
Instance launched in 00:24.858s -> i-cdd15070
Creating Cloud Watch Alarm for Instance auto-recovery -> i-cdd15070-auto-recovery-alarm
Waiting for AWS to boot Instance i-cdd15070 and Payload to start at https://52.59.241.106:8080/ ...
Payload started in 01:16.406s -> https://52.59.241.106:8080/
Remapping Elastic IP 52.29.78.197 to i-cdd15070 ...
Waiting 15s for AWS to complete Elastic IP Zero Downtime transition ...
Destroying Cloud Watch Alarm i-95d15028-auto-recovery-alarm ...
Terminating instance i-95d15028 ...
Destroying Security Group sg-0ed95166 (boxsg-myuser-prod-jhipster-1.0) ...
Deployment completed successfully. myuser/jhipster:2.0 is up and running at https://jhipster-myuser.boxfuse.io:8080/

And there it is:

Summary

In this brief guide we have seen how to:

  • create a JHipster application
  • fuse it into a CloudCaptain image
  • deploy the image locally on VirtualBox
  • deploy the image unchanged to AWS
  • update the application with zero downtime

Now it's your turn. Take your favorite JHipster application and deploy it with ease and pleasure.

And don't forget, CloudCaptain also comes with a Maven and a Gradle plugin to seamlessly integrate with your CI/CD workflow.

CloudCaptain JHipster Documentation