Skip to content

Instantly share code, notes, and snippets.

@rhenning
Created February 13, 2014 01:11
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save rhenning/8967855 to your computer and use it in GitHub Desktop.
Save rhenning/8967855 to your computer and use it in GitHub Desktop.
AWS OpsWorks full-stack blue/green deploy test
$ aws opsworks describe-stacks
{
"Stacks": [
{
"ServiceRoleArn": "arn:aws:iam::047170177871:role/aws-opsworks-service-role",
"StackId": "575e1389-1df3-427d-99d3-d60f89a41442",
"DefaultRootDeviceType": "ebs",
"Name": "rhenning_test",
"ConfigurationManager": {
"Version": "11.4",
"Name": "Chef"
},
"UseCustomCookbooks": false,
"Region": "us-east-1",
"DefaultInstanceProfileArn": "arn:aws:iam::047170177871:instance-profile/aws-opsworks-ec2-role.1392238762264",
"CustomCookbooksSource": {},
"DefaultSshKeyName": "provision_dev",
"Arn": "arn:aws:opsworks:us-east-1:047170177871:stack/575e1389-1df3-427d-99d3-d60f89a41442/",
"DefaultAvailabilityZone": "us-east-1a",
"HostnameTheme": "Layer_Dependent",
"Attributes": {
"Color": "rgb(45, 114, 184)"
},
"DefaultOs": "Ubuntu 12.04 LTS",
"CreatedAt": "2014-02-12T20:59:22+00:00"
}
]
}
$ aws opsworks describe-layers --stack-id 575e1389-1df3-427d-99d3-d60f89a41442
{
"Layers": [
{
"StackId": "575e1389-1df3-427d-99d3-d60f89a41442",
"Type": "custom",
"DefaultSecurityGroupNames": [
"AWS-OpsWorks-Custom-Server"
],
"Name": "rhenning-test-blue",
"Packages": [
"nginx"
],
"DefaultRecipes": {
"Undeploy": [],
"Setup": [
"opsworks_initial_setup",
"ssh_host_keys",
"ssh_users",
"mysql::client",
"dependencies",
"ebs",
"opsworks_ganglia::client"
],
"Configure": [
"opsworks_ganglia::configure-client",
"ssh_users",
"agent_version"
],
"Shutdown": [
"opsworks_shutdown::default"
],
"Deploy": [
"deploy::default"
]
},
"CustomRecipes": {
"Undeploy": [],
"Setup": [],
"Configure": [],
"Shutdown": [],
"Deploy": []
},
"AutoAssignPublicIps": true,
"EnableAutoHealing": true,
"UseEbsOptimizedInstances": false,
"LayerId": "32922d14-ffdf-42b1-915d-0b0a6d2231c3",
"Attributes": {
"JvmVersion": null,
"RailsStack": null,
"EnableHaproxyStats": null,
"MysqlRootPasswordUbiquitous": null,
"NodejsVersion": null,
"HaproxyHealthCheckUrl": null,
"GangliaPassword": null,
"Jvm": null,
"HaproxyHealthCheckMethod": null,
"RubyVersion": null,
"HaproxyStatsPassword": null,
"MysqlRootPassword": null,
"JavaAppServer": null,
"MemcachedMemory": null,
"JavaAppServerVersion": null,
"BundlerVersion": null,
"PassengerVersion": null,
"ManageBundler": null,
"HaproxyStatsUrl": null,
"HaproxyStatsUser": null,
"GangliaUser": null,
"JvmOptions": null,
"RubygemsVersion": null,
"GangliaUrl": null
},
"Shortname": "rhenning-test-blue",
"AutoAssignElasticIps": false,
"CustomSecurityGroupIds": [],
"CreatedAt": "2014-02-12T23:30:34+00:00",
"VolumeConfigurations": []
},
{
"StackId": "575e1389-1df3-427d-99d3-d60f89a41442",
"Type": "custom",
"DefaultSecurityGroupNames": [
"AWS-OpsWorks-Custom-Server"
],
"Name": "rhenning-test-green",
"Packages": [
"nginx"
],
"DefaultRecipes": {
"Undeploy": [],
"Setup": [
"opsworks_initial_setup",
"ssh_host_keys",
"ssh_users",
"mysql::client",
"dependencies",
"ebs",
"opsworks_ganglia::client"
],
"Configure": [
"opsworks_ganglia::configure-client",
"ssh_users",
"agent_version"
],
"Shutdown": [
"opsworks_shutdown::default"
],
"Deploy": [
"deploy::default"
]
},
"CustomRecipes": {
"Undeploy": [],
"Setup": [],
"Configure": [],
"Shutdown": [],
"Deploy": []
},
"AutoAssignPublicIps": true,
"EnableAutoHealing": true,
"UseEbsOptimizedInstances": false,
"LayerId": "de3f3cb3-39a2-43ad-a5b0-94f066b9c04b",
"Attributes": {
"JvmVersion": null,
"RailsStack": null,
"EnableHaproxyStats": null,
"MysqlRootPasswordUbiquitous": null,
"NodejsVersion": null,
"HaproxyHealthCheckUrl": null,
"GangliaPassword": null,
"Jvm": null,
"HaproxyHealthCheckMethod": null,
"RubyVersion": null,
"HaproxyStatsPassword": null,
"MysqlRootPassword": null,
"JavaAppServer": null,
"MemcachedMemory": null,
"JavaAppServerVersion": null,
"BundlerVersion": null,
"PassengerVersion": null,
"ManageBundler": null,
"HaproxyStatsUrl": null,
"HaproxyStatsUser": null,
"GangliaUser": null,
"JvmOptions": null,
"RubygemsVersion": null,
"GangliaUrl": null
},
"Shortname": "rhenning-test-green",
"AutoAssignElasticIps": false,
"CustomSecurityGroupIds": [],
"CreatedAt": "2014-02-12T23:30:54+00:00",
"VolumeConfigurations": []
}
]
}
$ aws opsworks describe-elastic-load-balancers --stack-id 575e1389-1df3-427d-99d3-d60f89a41442
{
"ElasticLoadBalancers": [
{
"StackId": "575e1389-1df3-427d-99d3-d60f89a41442",
"ElasticLoadBalancerName": "rhenning-test-elb",
"Ec2InstanceIds": [
"i-8097e4a1"
],
"Region": "us-east-1",
"DnsName": "rhenning-test-elb-102127177.us-east-1.elb.amazonaws.com",
"LayerId": "32922d14-ffdf-42b1-915d-0b0a6d2231c3",
"AvailabilityZones": [
"us-east-1a"
],
"SubnetIds": []
}
]
}
# ELB was attached to blue layer during setup
$ curl --silent http://rhenning-test-elb-102127177.us-east-1.elb.amazonaws.com | fgrep DEPLOY
<center><h1>THIS IS THE BLUE DEPLOY LAYER.</h1></center>
$ aws opsworks detach-elastic-load-balancer --layer-id 32922d14-ffdf-42b1-915d-0b0a6d2231c3 --elastic-load-balancer-name rhenning-test-elb
$ aws opsworks attach-elastic-load-balancer --layer-id de3f3cb3-39a2-43ad-a5b0-94f066b9c04b --elastic-load-balancer-name rhenning-test-elb
$ curl --silent http://rhenning-test-elb-102127177.us-east-1.elb.amazonaws.com | fgrep DEPLOY
<center><h1>THIS IS THE GREEN DEPLOY LAYER.</h1></center>
$ OPSWORKS_STACK_ID=$(aws opsworks describe-stacks | ruby -r json -e 'puts JSON.parse(ARGF.read)["Stacks"].detect { |s| s["Name"] == "rhenning_test" }["StackId"]')
$ aws opsworks describe-elastic-load-balancers --stack-id $OPSWORKS_STACK_ID
{
"ElasticLoadBalancers": [
{
"StackId": "575e1389-1df3-427d-99d3-d60f89a41442",
"ElasticLoadBalancerName": "rhenning-test-elb",
"Ec2InstanceIds": [
"i-8097e4a1"
],
"Region": "us-east-1",
"DnsName": "rhenning-test-elb-102127177.us-east-1.elb.amazonaws.com",
"LayerId": "32922d14-ffdf-42b1-915d-0b0a6d2231c3",
"AvailabilityZones": [
"us-east-1a"
],
"SubnetIds": []
}
]
}
$ OPSWORKS_BLUE_LAYER_ID=$(aws opsworks describe-elastic-load-balancers --stack-id $OPSWORKS_STACK_ID | ruby -r json -e 'puts JSON.parse(ARGF.read)["ElasticLoadBalancers"].detect { |elb| elb["ElasticLoadBalancerName"] == "rhenning-test-elb" }["LayerId"]')
$ curl --silent http://rhenning-test-elb-102127177.us-east-1.elb.amazonaws.com | fgrep DEPLOY
<center><h1>THIS IS THE BLUE DEPLOY LAYER.</h1></center>
$ aws opsworks detach-elastic-load-balancer --layer-id $OPSWORKS_BLUE_LAYER_ID --elastic-load-balancer-name rhenning-test-elb
$ OPSWORKS_GREEN_LAYER_ID=$(aws opsworks describe-layers --stack-id $OPSWORKS_STACK_ID | ruby -r json -e 'puts JSON.parse(ARGF.read)["Layers"].detect { |l| l["Name"] == "rhenning-test-green" }["LayerId"]')
$ aws opsworks attach-elastic-load-balancer --layer-id $OPSWORKS_GREEN_LAYER_ID --elastic-load-balancer-name rhenning-test-elb
$ curl --silent http://rhenning-test-elb-102127177.us-east-1.elb.amazonaws.com | fgrep DEPLOY
<center><h1>THIS IS THE GREEN DEPLOY LAYER.</h1></center>
# dance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment