Using Cloud Foundry with GitLab and Jenkins

In my last two blog posts, I walked users through some things they can accomplish with Jenkins, Gitlab, and Skytap Cloud. Those things included:

  1. Creating a new configuration with GitLab for source control (Get the Most out of the Gitlab Template in Skytap Cloud)
  2. Adding Jenkins to this configuration and tying them together to do continuous integration builds (Using Jenkins and Gitlab Together in Skytap Cloud)

Now I’ll walk you through how to do something cool with this configuration and add in Cloud Foundry, which will give you a nice continuous integration workflow. You’ll be able to develop the application; check it (push) into source control; and have the application automatically built and deployed for testing into Cloud Foundry. And if anything goes wrong along the way, Jenkins will fail the build and let you know.

But just before we get started: If you didn’t keep your configuration, or haven’t gone through the steps in my two previous blog posts, you will want to complete those first. Then, go ahead and add the Cloud Foundry VM into the configuration using these steps:

  1. Open your configuration
  2. Click Add VMs
  3. In the filter box, type ‘Cloud Foundry’ and click the magnifying glass
  4. Select the Cloud Foundry – Dev Stack Template
  5. In the lower right-hand corner, check the ‘Choose VMs to Add’ box, clear ‘Dev Workstation’ (you don’t need the dev workstation, just the Cloud Foundry VM)
  6. Click Add (If you happened to add the dev workstation, no big deal. Just delete it since you won’t be using it.)
  7. Start the Cloud Foundry VM

Now you’ve added Cloud Foundry to the mix. One thing to know about Cloud Foundry is that it doesn’t like IP changes, so to make life easier, let’s do some quick IP changes in your configuration.

If you’ve been following along the whole time, your GitLab VM should have the 10.0.0.1 IP address. Go ahead and shut that VM down. (If you happened to have started the Cloud Foundry VM, shut that one down as well.) Once both VMs are stopped, go in to the settings of the GitLab VM and change its IP address from 10.0.0.1 to 10.0.0.5. Once you’ve saved that, you can change Cloud Foundry’s IP address to 10.0.0.1 (which should make it very happy). Once that is done, go ahead and fire both VMs back up again.

Now that Cloud Foundry is ready, it’s time to get Jenkins up to speed with Cloud Foundry. To do this, you need to install the Cloud Foundry client on the Jenkins VM. You can connect to Jenkins using SmartClient.

  1. Login as the root user
  2. Run the following to install Cloud Foundry Client and dnsmasq

Note: You might be wondering why we included dnsmasq. This is because Cloud Foundry assumes that you’ll reference it via a wildcarded DNS name. The Skytap built-in DNS sever doesn’t support this, so you need to “shim” it with dnsmasq on both the Jenkins and Development clients. If you are going to deploy parts of this in your own internal network, you will need to build a wildcarded DNS entry as well on your own DNS server.

Now it’s time to head back over to your Development VM since everything else will need to be done either via a web browser on Jenkins or the terminal on the Development client. So use SmartClient to connect to the Development VM.

    1. Login as the skytap user
    2. Open Terminal (Applications > Accessories > Terminal)
    3. Run the following to install the Cloud Foundry client and dnsmasq just as you did on the Jenkins server. You’ll also push your express application to Cloud Foundry first, then once you have Jenkins configured it will just do updates:

Note: If vmc push fails during Starting Application, don’t worry. It will generate an ‘Error 306: Error retrieving file logs/startup.log.’ You can fix it and let Jenkins push the application to Cloud Foundry for you.

    1. Open Firefox (Applications > Internet > Firefox Web Browser)
    2. In the address bar, enter http://host-2 (Jenkins)
    3. Select the express_sample job
    4. Select Configure
    5. In the Build section, click Add build step
    6. Select Execute shell
    7. In the Command box add the following:
  1. Click Save

Now everything should be ready. All that’s left is to fix the application and let Jenkins deploy it to Cloud Foundry.

Open up the terminal again and you can fix the application. You need to change the express version in package.json and how the port is assigned in app.js.

Note: This will change from forcing a particular version of Express in Node.js to whichever one is available. The Git push command pushes the changes back to GitLab. That push will trigger Jenkins to deploy your changes to Cloud Foundry.

Let’s confirm that everything worked properly. Head back over to Firefox and enter http://host-2 in the address bar and watch everything happen in Jenkins. Once the build is done, enter http://express.vcap.me in the address bar and check out your application in Cloud Foundry (pushed there by Jenkins). Now feel free to make some changes to the application, push the changes back into GitLab, and watch them show up in Cloud Foundry.

As always, if you have any questions, don’t hesitate to get in touch with Skytap Support or your Skytap representative. Also, you may want to keep this configuration around for a while as my next blog post will be building upon this one.

Until next time,

Matt

Join our email list for news, product updates, and more.