Deploy your first Continuous Deployment Pipeline

- By Manisha Sahasrabudhe on September 21, 2016

As you know, we released our new implementation of continuous deployment pipelines last month. While our basic documentation is up to date, we believe that learning the new pipelines is best done with quick tutorials that demonstrate the power of CD and how easy it is to get started.

We have created a sample project and sample configuration to deploy the project to a test environment, create a release with semantic versioning, and deploy the project to production. The entire end to end scenario should take less than 30 mins to try out and while you won't learn every little trick, it will definitely make you comfortable with the configuration and how to set things up.

An integration for the Container Service where your cluster is located. This example uses Amazon ECS. You can add an Amazon ECS integration by following instructions here

Set up CI for the sample application

Before you get started with setting up your deployments, let's set up CI for your sample application.

Add the Docker Hub account integration you created to your Subscription containing the forked samplepipelinesdemo. To do this, go to your Subscription's Settings tab and click onIntegrations in the sidebar menu. Click on Add integration, name your integration, and then in the dropdown, choose your integration.

Next, make the following changes to the shippable.yml at the root of your forked samplepipelinesdemo:

replace shipdeploy with the Docker Hub integration you created. Please use the integration name from your Subscription Settings here.

replace shippablesamples in the IMAGE_NAME with your Docker Hub org name where you want to push the image.

Enable your forked sample application for CI. Click on Enable project in the left sidebar menu, find the samplePipelinesDemo and click on Enable.

You can trigger a build for samplepipelinesdemo in one of two ways:

Go to the Shippable UI and click on Build for the project on the Subscription page

Make a small change to the project. In the /static/css/app.cat.css file, change the color value in the following code

.shippableText{
color: #fff;
text-align: center;
font-size: 8em;
}

This should trigger a build on Shippable. Wait for your green build!

After the build is complete, check your Docker Hub org to ensure that the image was pushed successfully. Write down the tag of the image pushed (should be master.build_number if everything went well).

Create a cluster

Cluster creation is not covered in this sample, since it assumes an ECS cluster is already available. Create a cluster on your container service with at least one machine. There are no other constraints. Note down your cluster name and region.

Edit pipeline configuration ymls

Open up samplePipelinesTest/shippable.resources.yml and make the following edits:

Seed your pipeline in Shippable

Go to the SPOG pill menu of your Pipelines tab and voila! You should see your pipeline there:

Deploy to Test

Right click on the dv-man job in the SPOG view and click on Run. This will run the manifest job which creates a new service manifest. The deploy job is set up to run after manifest finishes, so it will be automatically triggered.

Check out your deployed demo on ECS

You can now go to your AWS management console and navigate to the deployed application by following the steps below:

Go to your ECS cluster by navigating to EC2 Container Service and clicking on the cluster name

Click on the Service Name starting with dv. This will take you to the Tasks page

Click on the Task to navigate to the containers page.

Expand the container to view the IP address of your deployed application

Click on the IP address will open up a new browser tab and show you the running application.

Connect CI and Pipelines

Now that you have your pipeline up and running, you should connect it to your CI. On completing this step, every code change to your sample application will trigger a deployment to the Test cluster we set up in the previous steps.

To do this:

Create an API token for your account. To do this, go to your Account Settings by clicking on the gear icon in the top navbar. Then click on API tokens in the left sidebar menu and create a token. Copy the token since you won't be able to see it again.

Next, we will create an account integration of type 'Event Trigger'

Go to Integrations in the left sidebar menu and then click on Add Integration

Select Event Trigger from the dropdown for Master Integration and complete the settings as shown below. Please make sure you update the Authorization textbox in the formatapiToken <token-value>.

Add the integration to your Subscription containing the forked samplePipelinesDemo. To do this, go to your Subscription's Settings tab and click on Integrations in the sidebar menu. Click on Add integration, name your integration, and then in the dropdown, choose the integration you created in the previous step.

Next, make the following changes to the shippable.yml at the root of your forked sample application:

Uncomment the notifications section

replace triggerPipelinesDemo with the name of the Event Trigger integration you created. Please use the integration name from your Subscription Settings here.

Try pushing a color change to your sample demo by going to the /static/css/app.cat.css file and changing color of .shippableText, and see your pipeline light up! Check your running application to see the new color.

Adding a release step

Now that you have CI hooked up, you have a workflow from source control to a test environment. Next, we will hook up a release job that will be triggered manually when you are satisfied with your tests.

This release job tags your service with a version number starting with a seed version specified in your resources yml.

Add the following to your samplePipelinesTest/shippable.resources.yml:

This creates a release job for your sample project. It takes the version resource we just created as an input. We are also adding a trigger resource that allows us to manually trigger the pipeline. This is defined in shippable.triggers.yml. This job is sequenced after the deployment job in your pipeline, and every time a release is created, it currently bumps up the minor version.

Commit your changes. You'll see the release job added at the end:

Adding a production deployment

Each time a release is created, we will hook it up to deploy to production. You will need an existing cluster on your Container Service to set this up. To configure this:

Replace demo-manisha-ecs with the Container Service integration name from your subscription.

Replace demo-shippable-ecs-prod with your prod cluster name.

Replace us-east-1 with the region where your cluster is located

This is similar to the job that deploys to test environment, but it is configured with the prod cluster and is sequenced after the releae job in your pipeline. The job as configured will not be triggered automatically when release is updated. You can turn switch: on to run it automatically each time a new release is created, or you can add a trigger resource like we did for the release job so you can trigger it with a commit.

Create a release and trigger deployment!

To create a new release, go to your shippable.triggers.yml and increment the counter by 1. This will trigger the release job and create a release with version 1.1.0.

Next, go to your Shippable UI SPOG view, right click on the production deployment job dv-prod-ecs and click on Run. This should deploy your application to your production cluster.