Getting Started with Cloud Foundry – Application Deployment Pipelines with Concourse – Part 1

In the first two blogs post of Getting Started with Cloud Foundry, we have setup a local development environment for Cloud Foundry with PCF Dev and shown how easy it is to deploy a sample app. Now we’re going to look at taking our sample app through a basic deployment pipeline, first deploying it to ‘test’ and then to ‘production’.

To build the deployment pipeline, we are going to use a tool called Concourse. Concourse is built by Pivotal to create and run deployment pipelines, and as it’s built by Pivotal it has excellent support for Cloud Foundry. You can read more about Concourse at concourse.ci.

  1. The quickest way to get started with Concourse is to spin it up with Vagrant. If you don’t have Vagrant installed, go grab it from here and install it before proceeding. That will require a restart.
  2. Before starting Concourse with Vagrant locally, depending on how much memory you have in your machine it, you might want to stop PCF Dev if you still have it running. Run “cf dev stop”
  3. Once you have Vagrant installed, run “vagrant init concourse/lite” then “vagrant up” to get it started. As this will download a Vagrant box of about 700Mb it will take a few moments depending on your internet speed.
  4. Once completed, Concourse will then be running at http://192.168.100.4:8080/

    Capture01

  5. Click on the relevant link to download the CLI used for Concourse, which is called ‘fly’. The Concourse web UI is only for viewing pipelines, all the config is done via fly.
  6. Finally, once you have download fly, as it comes as a binary with no install, lets add it to the PATH environment variable so we can use it from any directory. Do that from Control Panel > System and Security > System > Advanced system settings > Advanced > Environment variables.

Ok, so we have Concourse and fly installed, lets go and setup our first, basic pipeline. For this we will follow the ‘Hello, world!’ tutorial from Concourse.ci. For my own learning I’m duplicating their steps in my own words.

  1. Before using fly for managing pipelines, you need to configure fly to point at a Consource instance. In fly this Concourse instance is called a target and you can give it an alias to make it easy to use going forward. Run the following command to set the concourse instance we have running in Vagrant as our target and give it an alias of ‘lite’; ‘fly -t lite login -c http://192.168.100.4:8080’

    Capture02

  2. Now we have set up an alias to target our Concourse instance, we can use the YAML file below to create a pipeline. Save the below as hello.yaml. This is a simple file which defines a pipeline that has a job with a plan which comprises of one task, and uses a Docker container to echo the words “Hello, world!”. The image_resource and source configuration use Concourse’s container register to grab the required Docker image, but you can point this at any registry.
    jobs:
    - name: hello-world
      plan:
      - task: say-hello
        config:
          platform: linux
          image_resource:
            type: docker-image
            source: {repository: ubuntu}
          run:
            path: echo
            args: ["Hello, world!"]
  3. Once you have that saved, run the following to create your pipeline ‘fly -t lite set-pipeline -p hello-world -c hello.yml’. You now have your first pipeline in Concourse, all be it with one job so just one square turns up in the GUI. Arguably this isn’t even a pipeline, its just one ‘thing’ on its own.

    Capture03

  4. The top bar is blue because any new pipeline by default is paused. You can unpause it by running ‘fly -t lite unpause-pipeline -p hello-world’
  5. Because we don’t have a resource to trigger the job, it won’t run until we manually trigger it. Click on the hello-world box and click the ‘+’ icon in the top right corner. The job will run and you will see it download the docker image and then echo ‘Hello, world!’.

    Capture04

  6. If you run it again by clicking the ‘+’ button, it won’t download the image again and so the task will just echo ‘Hello, world!’
  7. Now lets create a pipeline with a resource which triggers the job. Create a file called navi-pipeline.yml with the following contents. This creates a ‘time’ resource (resources can be things like Git, but in this instance its just a timer) and then creates a job which triggers when the resource name ‘every-1m’ is true. The job basically does the same as our hello world pipeline, except this time it says “Hey! Listen!”.
    resources:
    - name: every-1m
      type: time
      source: {interval: 1m}
    
    jobs:
    - name: navi
      plan:
      - get: every-1m
        trigger: true
      - task: annoy
        config:
          platform: linux
          image_resource:
            type: docker-image
            source: {repository: ubuntu}
          run:
            path: echo
            args: ["Hey! Listen!"]
  8. Update the Hello world pipeline with the above YAML by running the command ‘fly -t lite set-pipeline -p hello-world navi-pipeline.yml’
  9. Take a look at the GUI and you’ll see the hello world job has been replaced by the navi job with a resource. Every 1 minute the ‘every-1m’ resource will be true and therefore the navi job will trigger.

    Capture05

  10. If you click on the navi job you’ll see all the times it has trigger and the output from the latest run.

    Capture06

Now we have Concourse up and running, and have the fly cli powering some simple pipelines, the next step is to setup the pipeline to run our deployment. That’ll be for another part 2 of this blog post.

Advertisements
Getting Started with Cloud Foundry – Application Deployment Pipelines with Concourse – Part 1

One thought on “Getting Started with Cloud Foundry – Application Deployment Pipelines with Concourse – Part 1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s