Get Started with CloudCaptain & Revel

 

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

Prerequisites

Before you begin, ensure you have an x64 machine and 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 Go
  4. downloaded and installed the latest version of Revel
  5. downloaded and installed the latest version of VirtualBox

Creating the Revel application

In this tutorial we are going to create and deploy a simple Revel application.

Start by navigating to your GOPATH and create our app:

> revel new github.com/myuser/getstarted-revel

Now let's make sure we are compiling for Linux x64. If you are on Linux already, you can safely skip this step.

Windows users should invoke:

> set GOOS=linux

And Mac OSX users should invoke:

> export GOOS=linux

Finally compile the app and package it into a tar.gz:

> revel package github.com/myuser/getstarted-revel prod
~
~ revel! https://revel.github.io
~
Your archive is ready: getstarted-revel.tar.gz

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:

> boxfuse run -image=getstarted-revel:1.0

Creating getstarted-revel ...
Mapping getstartedrevel-dev-myuser.boxfuse.io to 127.0.0.1 ...
Created App getstarted-revel (single-instance / none)
Fusing Image for getstarted-revel.tar.gz (Revel) ...
Image fused in 00:00.667s (9326 K) -> myuser/getstarted-revel:1.0
Launching Instance of myuser/getstarted-revel:1.0 on VirtualBox ...
Forwarding http port localhost:9000 -> vb-530fc84d:9000
Instance launched in 00:07.553s -> vb-530fc84d
Waiting for Payload to start on vb-530fc84d:9000 (expecting HTTP 200 at / within 300s) ...
Payload started in 00:00.008s -> https://127.0.0.1:9000

In just a few seconds CloudCaptain found your application, detected its type, generated an image for it and launched an instance of that image on VirtualBox.

CloudCaptain also found definition for an http server at port 9000 in the app.conf generated by Revel for your application and used that to automatically healthcheck your instance.

Now open your browser and navigate to this address to see your new application up and running within the VirtualBox VM:

You can also see your newly created image:

> boxfuse ls

Images available locally:
+-----------------------------+-------------------------+-------+---------+--------------+--------+---------------------+
| Image                       |         Payload         | Debug | Runtime |    Ports     |  Size  |    Generated at     |
+-----------------------------+-------------------------+-------+---------+--------------+--------+---------------------+
| myuser/getstarted-revel:1.0 | getstarted-revel.tar.gz | false | Revel   | http -> 9000 | 9326 K | 2016-08-09 14:25:59 |
+-----------------------------+-------------------------+-------+---------+--------------+--------+---------------------+
Total: 1

As well as the instance that is running:

> boxfuse ps

Running Instances on VirtualBox in the dev environment :
+-------------+-----------------------------+---------------------+-----------------------+---------------------+
|  Instance   |            Image            |        Type         |          URL          |     Launched at     |
+-------------+-----------------------------+---------------------+-----------------------+---------------------+
| vb-530fc84d | myuser/getstarted-revel:1.0 | 4 CPU / 1024 MB RAM | https://127.0.0.1:9000 | 2016-08-09 14:26:01 |
+-------------+-----------------------------+---------------------+-----------------------+---------------------+
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:

> boxfuse run getstarted-revel:1.0 -env=prod

Pushing myuser/getstarted-revel:1.0 ...
Verifying myuser/getstarted-revel:1.0 ...
Waiting for AWS to create an AMI for myuser/getstarted-revel:1.0 in eu-central-1 (this may take up to 50 seconds) ...
AMI created in 00:19.958s in eu-central-1 -> ami-93e81efc
Creating Elastic IP ...
Mapping getstartedrevel-myuser.boxfuse.io to 52.59.65.17 ...
Creating security group boxsg-myuser-prod-getstarted-revel-1.0 ...
Launching t2.micro instance of myuser/getstarted-revel:1.0 (ami-93e81efc) in prod (eu-central-1) ...
Instance launched in 00:18.382s -> i-58cb4ce5
Creating Cloud Watch Alarm for Instance auto-recovery -> i-58cb4ce5-auto-recovery-alarm
Waiting for AWS to boot Instance i-58cb4ce5 and Payload to start at https://54.93.175.48:9000/ ...
Payload started in 00:31.024s -> https://54.93.175.48:9000/
Remapping Elastic IP 52.59.65.17 to i-58cb4ce5 ...
Waiting 15s for AWS to complete Elastic IP Zero Downtime transition ...
Deployment completed successfully. myuser/getstarted-revel:1.0 is up and running at https://getstartedrevel-myuser.boxfuse.io:9000/

Notice that we have now specified an image, as we want to reuse our 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 Go application in action on AWS:

Bonus: update your application using blue/green deployments

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

Start by modifying <GOPATH>/src/github.com/myuser/getstarted-revel/app/views/App/Index.html with a simple change:

...
<h1>It works!</h1>
<h1>Updated by CloudCaptain with zero downtime!</h1>
...

Then rebuild the tar.gz:

> revel package github.com/myuser/getstarted-revel prod

Finally, deploy the new version of your application to AWS:

> boxfuse run -env=prod -image=getstarted-revel:2.0

Fusing Image for getstarted-revel.tar.gz (Revel) ...
Image fused in 00:00.679s (9326 K) -> myuser/getstarted-revel:2.0
Pushing myuser/getstarted-revel:2.0 ...
Verifying myuser/getstarted-revel:2.0 ...
Waiting for AWS to create an AMI for myuser/getstarted-revel:2.0 in eu-central-1 (this may take up to 50 seconds) ...
AMI created in 00:35.237s in eu-central-1 -> ami-77d52318
Creating security group boxsg-myuser-prod-getstarted-revel-2.0 ...
Launching t2.micro instance of myuser/getstarted-revel:2.0 (ami-77d52318) in prod (eu-central-1) ...
Instance launched in 00:21.719s -> i-77cc4bca
Creating Cloud Watch Alarm for Instance auto-recovery -> i-77cc4bca-auto-recovery-alarm
Waiting for AWS to boot Instance i-77cc4bca and Payload to start at https://54.93.63.29:9000/ ...
Payload started in 00:31.024s -> https://54.93.63.29:9000/
Remapping Elastic IP 52.59.65.17 to i-77cc4bca ...
Waiting 15s for AWS to complete Elastic IP Zero Downtime transition ...
Destroying Cloud Watch Alarm i-58cb4ce5-auto-recovery-alarm ...
Terminating instance i-58cb4ce5 ...
Destroying Security Group sg-c256d6aa (boxsg-myuser-prod-getstarted-revel-1.0) ...
Deployment completed successfully. myuser/getstarted-revel:2.0 is up and running at https://getstartedrevel-myuser.boxfuse.io:9000/

And there it is:

Summary

In this brief guide we have seen how to:

  • create a Revel 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 Revel application and deploy it with ease and pleasure.

CloudCaptain Revel Documentation