This repo was cloned from a bitbucket repository from author Thiago Nache
For all cookbooks except: opsworks and alb, contact Thiago Nache B. de Carvalho thiagonbcarvalho@gmail.com
- It contains Chef Recipes you should use on Amazon Opsworks.
- Beta version
This helps automates your project deployments using Amazon Opsworks, Git, Docker and docker-compose. This cookbook requires the parameter app
to be sent via Custom JSON and a file named docker-compose-prod.yml
in the root of the project to function properly.
The list of supported parameters in the Custom JSON are:
app
- (<String>) name of your app (no spaces).external-files
(Array<Object>) extra files that you may need for your project. These Objects should have:path
(<String>),environment
(Object<String:String>)copy-files
(Array<Object>) intended to copy file templates under a new name that you may need for your project. These Objects should have:source
(<String>),destination
(<String>)commands
(Array<String>) commands that you want executed in your instance.
Here is an example:
{
"app":<my_app_name>,
"external-files":[{
"path":<path/to/file.js>,
"environment":{
<"export const MY_FIRST_VAR">:<"'value 1'">,
<"export const MY_SECOND_VAR">:<"'value 2'">,
.
.
.
}
}],
"copy-files":[{
"source": <absolute path of source file>,
"destination": <absolute path of destination file>
}],
"commands":["sudo docker exec -i my_container npm install",
"sudo docker exec -i my_container npm run build",
"sudo docker exec -i my_container supervisorctl restart all"]
}
This recipe will:
- Stop existing containers of the app and remove them
- Erase existing folder of the project
- Pull the project with git
- Rebuild the containers
This recipe will execute the commands passed in the Custom JSON
This recipe will pull the latest changes from the deployed app
This recipe will execute the copy-files
parameter passed in the Custom JSON
One fast way to update your servers would be to have in your layer:
setup
: docker-compose::default, opsworks::deploydeploy
: opsworks::pull, opsworks::commands
This will update your processes without rebuilding your containers. If you can't restart your processes with the recipe commands then you should do it like this:
setup
: docker-compose::defaultdeploy
: opsworks::deploy
Opsworks doesn't support yet a native integration between layers and Application Load Balancers, so this cookbook bridges that gap.
You need to give EC2 permissions to your user registered in your panel in Opsworks, otherwise the recipe won't be able to register the instance to the existing target groups. This recipe also requires a parameter in the Custom JSON:
balancers
- (Array<Object>) target groups to which to register your instance. These Objects should have:target-group-arn
(<String>),region
(<String>),ports
(Array<String>)
Here is an example:
{
"balancers":[{
"target-group-arn":<amazon target group ARN>,
"region":<amazon region (e.g. us-west-2)>,
"ports":[<port 1>]
},
.
.
.
]}
This will register the instance with all the declared target groups declared in the Custom JSON
This will deregister the instance with all the declared target groups declared in the Custom JSON.
Important!
You should consider that if you have draining enabled for your load balancer, once you deregister your instance, it will enter into draining
state, during this state you won't be able to register your instance back again and will generate a silent error.
Execute lambda functions
You need to give lambda permissions to your user registered in your panel in Opsworks, otherwise the recipe won't be able to execute the functions. This recipe also requires a parameter in the Custom JSON:
lambda
- (Array<Object>) lambda functions to execute. These Objects should have:function-arn
(<String>),region
(<String>),payload
(Object<String:String>)
Here is an example:
{
"lambda":[{
"function-arn":<lambda ARN>,
"region":<amazon region (e.g. us-west-2)>,
"payload":{"key1":"value1"}
},
.
.
.
]}
This will execute all the lambda functions declared in the Custom JSON
- You just need an Amazon Web Service account.