Amazon recently announced a new deployment service called CodeDeploy. OpsWorks is another application management product which provides excellent configuration management via Chef, however it lacks the advanced deployment functionality of CodeDeploy. It therefore makes sense to integrate these two products, delegating the configuration management to OpsWorks and the deployment functionality to CodeDeploy.
This is part 1 of integrating OpsWorks and CodeDeploy.
This section provides an introduction to OpsWorks and CodeDeploy, and the basic configuration required to get started.
Why not just use OpsWorks?
OpsWorks is a great product, but it lacks several key deployment features such as the ability to run rolling deployments and cancel an in-flight deployment.
Why not just use CodeDeploy?
While CodeDeploy does support the execution of configuration scripts in lifecycle events, these could easily become difficult to maintain if your configuration is complex. Also, the configuration might not belong to any specific application, and if you’re running multiple applications per instance it might make sense to configure certain shared services on a per-server basis rather than per-application. OpsWorks is an excellent solution to these issues as it supports Chef and per-instance setup and configuration lifecycle events.
To get started you’ll need to set up an OpsWorks stack with a custom cookbook repository. The stack also must be created in a region where CodeDeploy is supported, such as North Virginia. If you’re using a VPC don’t forget to configure your VPC to allow external connectivity.
My stack configuration is as follows, as you can see I’ll be using Ubuntu 14.04, but the steps should be similar on Amazon linux.
Also, create a layer for your application servers. For example I’ve created a PHP App Server layer. Don’t forget to enable “Public IP addresses” under the networking options.
In this example I’m also going to deploy from S3, rather than GitHub. Therefore I’ll assume you have an S3 bucket created to host the zip deployment packages.
Creating a CodeDeploy Service Role
You’ll need to create a service role for CodeDeploy before proceeding, although if you’ve already followed the “Sample Deployment” wizard then you will probably have created one at the following step:
If you need to create one manually then you can follow these steps to first create a role with the following policy:
Then set the trust relationships:
Creating CodeDeploy application
Next go to the CodeDeploy console and create a new application using the “Custom Deployment” option.
In the application options you have to define which EC2 instance tags will be included in the deployment. Set the
opsworks:layer:php-app to the name of your stack and layer respectively.
Select a Deployment Config (eg.
CodeDeployDefault.OneAtATime), and set the Service Role ARN to the service
role you created earlier.