This is part 2 of integrating OpsWorks and CodeDeploy.
This section covers creating the OpsWorks Chef recipes to deploy your application via CodeDeploy. Click here for Part 1.
Installing CodeDeploy agent via Chef
Next we need to write a custom chef recipe to install the CodeDeploy agent and perform our desired configuration.
Checkout your cookbooks repository and create the following files:
1 2 3 4 5 |
|
Populate these files with the following:
1
|
|
(We won’t be using Berkshelf in this tutorial, however you’ll probably want to create this file any way if you’re planning to extend this tutorial with your own configuration)
1 2 |
|
This is the code which downloads, installs and starts the CodeDeploy agent service:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
This code creates a directory for the CodeDeploy to deploy to, creates the vhost and enables it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
This is a standard Apache vhost configuration based on the default OpsWorks template:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
In this step you may also like to create additional recipes for other configuration tasks, such as installing dependencies or configuring your HTTP server.
Adding recipes and packages to layer via OpsWorks
Once you’ve committed and pushed your recipes, go to OpsWorks and add the agent recipe to the configure lifecycle event
of your application server layer. Also add ruby2.0
and awscli
to the OS packages.
Creating placeholder deployment
Because OpsWorks doesn’t perform certain default configuration tasks (such as creating a www-data group) until a deployment occurs it’s easiest to create a placeholder OpsWorks deployment with a holding page which will be replaced by CodeDeploy. You could of course skip this step and manually configure everything via custom recipes.
In this instance we’ll create a new repository for the placeholder which contains nothing but an index.php file containing a placeholder message.
1
|
|
Create this deployment in OpsWorks:
Starting an instance
You can now start an instance in OpsWorks. It usually takes at least 20 minutes to boot and execute the setup and configure recipes. After this has complete your instance should have a status of online:
You should also see the placeholder message when you visit the IP in a browser:
This should also have installed and started the CodeDeploy agent.