This tutorial explains how to create a continuous deployment pipeline to Google Container Engine using Codeship. You will learn how to deploy a containerized application when new code is merged into the master branch and all integration tests have passed.

Continuous deployment is the practice of automating the delivery of software to production after passing a series of tests. Although not for everyone, it should be the goal of any software development and DevOps team not restricted by regulatory constraints.

This pipeline runs each step in series. The build-image step instructs Codeship to build the hello-express Docker image on the CI server. After Codeship builds the Docker image, the push-image-with-sha step will push the image to Google Container Registry using the name gcr.io/YOUR_PROJECT_ID/hello-express, adding a tag using the first eight characters of the commit SHA for every commit to the repository.

The third and fourth step will run only if the branch is tagged as master. The tag-as-master step will add the master tag to the image pushed to Google Container Registry. This indicates the image in Google Container Registry that is currently deployed.

The following step, gke-initial-deployment, builds the Container Engine cluster and deploys the gcr.io/YOUR_PROJECT_ID/hello-express Docker image.

You will run this pipeline locally using the Codeship Jet CLI. Since there is no git commit or branch to reference, use the ci-commit-id and tag flags with the Codeship Jet CLI to pass in test strings at runtime, (for example, 1234ABCD and master). The build on the Codeship CI server populates ci-commit-id with the git commit SHA, and tag with the branch or tag name.

Finally, the --push flag instructs the Codeship Jet CLI to run the push steps in the codeship-steps.yml file.

jet steps --ci-commit-id 1234ABCD --tag master --push

This command creates your initial deployment and exposes the application. Once completed, navigate to the Discovery page in the Google Cloud Platform Console to verify the status is ok. Click the endpoint to open the application in the browser. You should see Hello Express!.

Step 4: Create a Codeship project

Now that you have set up the container cluster and deployed the application, you can create the Codeship project. This project will connect to your source control management service. Codeship integrates with the following services:

After you save these changes, stage all of these files for a commit. Commit the changes to the master branch, and push to your remote repository. After the push is complete, return to the Codeship project dashboard and watch for a green build.

Step 7: Deploy an update to your application (optional)

You can now modify the code in the server.js file to return something different. Change 'Hello Express!' to something like 'Hello World!'. Once you have changed the application, commit the change and push to your remote repository.

After the Codeship process is completed, navigate to the application endpoint to verify your changes have taken effect.

Cleaning Up

After completing the tutorial, follow these steps to remove the resources from your Google Cloud Platform account to prevent any charges:

Delete the service — this will deallocate the Cloud Load Balancer created for your Service:

kubectl delete service hello-express

Wait for the load balancer provisioned for the hello-web service to be deleted. The load balancer is deleted asynchronously in the background when you run kubectl delete. Wait until the load balancer is deleted by watching the output of the following command:

gcloud compute forwarding-rules list

Delete the container cluster. This will delete the resources that make up the container cluster, such as the compute instances, disks and network resources.

Subscribe via Email

Over 60,000 people from companies like Netflix, Apple, Spotify and O'Reilly are reading our articles. Subscribe to receive a weekly newsletter with articles around Continuous Integration, Docker, and software development best practices.

We promise that we won't spam you. You can unsubscribe any time.

Join the Discussion

Leave us some comments on what you think about this topic or if you like to add something.