Home > Articles

  • Print
  • + Share This
This chapter is from the book

Deploying and Running in the Cloud

Now that we’ve used Go to build a microservice while following the way of the cloud, we can put that effort to good use and deploy our work to the cloud. The first thing we’re going to need is a cloud. While there are a number of options available to us, in this book we favor Cloud Foundry’s PCF Dev and Pivotal Web Services (PWS) as deployment targets because they’re both extremely easy to get started with and PWS has a free trial that does not require a credit card to get started.

Creating a PWS Account

Head over to http://run.pivotal.io/ to create an account with Pivotal Web Services. Pivotal Web Services is platform powered by Cloud Foundry that lets you deploy your applications in their cloud and take advantage of a number of free and paid services in their marketplace.

Once you’ve created an account and logged in, you will see the dashboard for your organization. An organization is a logical unit of security and deployment. You can invite other people to join your organization so you can collaborate on cloud projects, or you can keep all that cloudy goodness to yourself.

On the home page or dashboard for your organization, you will see a box giving you some helpful information, including links pointing you to the Cloud Foundry CLI. This is a command-line interface that you can use to push and configure your applications in any cloud foundry (not just PWS).

Download and install the CF CLI and make sure it works by running a few test commands such as cf apps or cf spaces to verify that you’re connected and working. Remember that you have 60 days to play in the PWS sandbox without ever having to supply a credit card, so make sure you take full advantage of it.

For information on what you can do with the CF CLI, check out the documentation here http://docs.run.pivotal.io/devguide/cf-cli/.

Setting up PCF Dev

If you’re more adventurous, or you simply like to tinker, then PCF Dev is the tool for you. Essentially, PCF Dev is a stripped-down version of Cloud Foundry that provides application developers all of the infrastructure necessary to deploy an application into a CF deployment, but without all of the production-level stuff that would normally prevent you from running a cloud on your laptop.

PCF Dev utilizes a virtual machine infrastructure (you can choose between VMware or VirtualBox) and a tool called vagrant to spin up a single, self-contained virtual machine that will play host to PCF Dev and your applications.

You can use PCF Dev to test how well your application behaves in the cloud without having to push to PWS. We’ve found it invaluable for testing things like service bindings and doing testing that falls somewhere between automated integration testing and full acceptance testing.

At the time this book is being written, PCF Dev is still in its early stages and, as a result, the instructions for installing and configuring the various releases are likely to change.

To get set up with PCF Dev, go to https://docs.pivotal.io/pcf-dev/.

The beauty of PCF Dev is that once you have the pre-requisites installed, you can simply issue the start command and everything you need will be brought up for you on your local virtualization infrastructure. For example, on OS X, you start your foundation with the ./start-osx script.

Using the exact same Cloud Foundry CLI that you used to communicate with your PWS cloud, you can retarget that CLI to your new MicroPCF installation:

$ cf api api.local.pcfdev.io --skip-ssl-validation
Setting api endpoint to api.local.pcfdev.io...

API endpoint:   https://api.local.pcfdev.io (API version: 2.44.0)
Not logged in. Use 'cf login' to log in.

Make sure you login as the instructions indicate (the default username and password are admin and admin), and you can then issue standard Cloud Foundry CLI commands to communicate with your newly started local, private CF deployment:

$ cf apps
Getting apps in org local.pcfdev.io-org / space kev as admin...

Pushing to Cloud Foundry

Now that you’ve got the CF CLI installed and you can choose whether your CLI is targeting the PWS cloud or your local PCF Dev installation, you can push your application and run it in the cloud.

While you can manually supply all of the various options that you need to push your application to the cloud, it’s easier (and more compatible with the CD pipeline work we’ll be doing later in the book) to create a manifest file, like the one in Listing 5.7.

Listing 5.7 manifest.yml

- path: .
  memory: 512MB
  instances: 1
  name: your-app-name
  disk_quota: 1024M
  command: your-app-binary-name
  buildpack: https://github.com/cloudfoundry/go-buildpack.git

With this manifest file in the main directory of your application, you can simply type the following command and your application will be deployed in the cloud.

$ cf push

As we’ll also illustrate later in the book, you can even configure your Wercker pipeline to automatically deploy your application to the Cloud Foundry of your choice at the end of a successful build for continuous delivery.

  • + Share This
  • 🔖 Save To Your Account