The main entrypoint for this script. It parses CLI arguments and kicks off a rolling deployment.
"""
parser = argparse.ArgumentParser(description='Perform a rolling deployment of a server group.')
parser.add_argument('--aws-region', help='The AWS region to use.', required=True)
parser.add_argument('--server-group-size', help='The number of servers in the server group.', required=True, type=int)
parser.add_argument('--server-group-name', help='The name of the server group. This should stay the same across all deployments.', required=True)
parser.add_argument('--launch-config-name', help='The name of the Launch Configuration. This should change for each deployment.', required=True)
parser.add_argument('--alb-target-group-arns', help='The ARN of an ALB Target Group to use for health checks.', nargs='*')
parser.add_argument('--elb-names', help='The name of an ELB to use for health checks.', nargs='*')
parser.add_argument('--batch-size', help='The number of servers to redeploy at a time.', type=int, default=helpers.DEFAULT_BATCH_SIZE)
parser.add_argument('--max-retries', help='Maximum number of times to retry checking.', type=int, default=helpers.DEFAULT_MAX_RETRIES)
parser.add_argument('--retry-interval-sec', help='How long to wait between each health check in seconds.', type=int, default=helpers.DEFAULT_SLEEP_BETWEEN_RETRIES_SEC)
Questions? Ask away.
We're here to talk about our services, answer any questions, give advice, or just to chat.
{"treedata":{"name":"root","toggled":true,"children":[{"name":".circleci","children":[{"name":"config.yml","path":".circleci/config.yml","sha":"3b69f7bf481fe18ca42e8b40e0e6369d1efb4494"}]},{"name":".gitignore","path":".gitignore","sha":"62841321b0ad8768831d29e34422fafa4c24751e"},{"name":".pre-commit-config.yaml","path":".pre-commit-config.yaml","sha":"c727e29761f9d32c212546d1c47ebc05a16b2d37"},{"name":"CODEOWNERS","path":"CODEOWNERS","sha":"38e274e73edb347a7f35c6d9e84a125a2e7bb063"},{"name":"CONTRIBUTING.md","path":"CONTRIBUTING.md","sha":"6ce0d84e615b63ee870e407c93740f491cbcd27d"},{"name":"LICENSE.txt","path":"LICENSE.txt","sha":"f4e3d9bd4717a044ed31ad847a300eee74371a78"},{"name":"README.md","path":"README.md","sha":"648489bca9cb5d56b2a29d0eabf6d5ba5e2639e3"},{"name":"examples","children":[{"name":"asg-rolling-deploy","children":[{"name":"README.md","path":"examples/asg-rolling-deploy/README.md","sha":"f5f2a8e2db00bb7c95975437ac913ef2f9769f7c"},{"name":"with-elb","children":[{"name":"main.tf","path":"examples/asg-rolling-deploy/with-elb/main.tf","sha":"28c2f0037746c32e28e3083a4518c8ff5c03870d"},{"name":"outputs.tf","path":"examples/asg-rolling-deploy/with-elb/outputs.tf","sha":"330a02ec9378c2c9c4a1423b075384f4ae3ed241"},{"name":"user-data","children":[{"name":"user-data.sh","path":"examples/asg-rolling-deploy/with-elb/user-data/user-data.sh","sha":"7b5fbe6f33805eb5356e9c49db9bd5b141b0816a"}]},{"name":"vars.tf","path":"examples/asg-rolling-deploy/with-elb/vars.tf","sha":"dab89e417460b5fa2676796e945acf27803c6553"}]},{"name":"without-elb","children":[{"name":"main.tf","path":"examples/asg-rolling-deploy/without-elb/main.tf","sha":"e4591c78c05fc4178827e9291d55463320a0dea3"},{"name":"outputs.tf","path":"examples/asg-rolling-deploy/without-elb/outputs.tf","sha":"c8db3c807aab3d75888c2dd039b9e81b1312a137"},{"name":"vars.tf","path":"examples/asg-rolling-deploy/without-elb/vars.tf","sha":"1d6d2ee9904841723c7e7c29d9fe5e12e7f6fd6a"}]}]},{"name":"server-group","children":[{"name":"README.md","path":"examples/server-group/README.md","sha":"63c6917a20e10cb2b569e5314bbf3d4ec38ff491"},{"name":"ami","children":[{"name":"server.json","path":"examples/server-group/ami/server.json","sha":"8eb0e050068c94f085b4a4bf188365f5c0c45d1b"}]},{"name":"with-alb","children":[{"name":"main.tf","path":"examples/server-group/with-alb/main.tf","sha":"f911b264e56d9a465c703cd244dd82cea05ce29d"},{"name":"outputs.tf","path":"examples/server-group/with-alb/outputs.tf","sha":"3565caece2f11d61dc0b0a6ed23cc58ce7e6e61c"},{"name":"user-data","children":[{"name":"user-data.sh","path":"examples/server-group/with-alb/user-data/user-data.sh","sha":"064d042a5d0ba6956f4eb8d7ece309b4d6eb4b33"}]},{"name":"vars.tf","path":"examples/server-group/with-alb/vars.tf","sha":"dc708850a0e1169ba4101135f6a707e79bd82850"}]},{"name":"with-elb","children":[{"name":"main.tf","path":"examples/server-group/with-elb/main.tf","sha":"0dcff963a4e68e846366a894c356d37c712918ae"},{"name":"outputs.tf","path":"examples/server-group/with-elb/outputs.tf","sha":"fd38915d96770f9588e2fcc79369e64449492286"},{"name":"user-data","children":[{"name":"user-data.sh","path":"examples/server-group/with-elb/user-data/user-data.sh","sha":"f0b175520e85da002b8c26a4a92347fb1eaa1d13"}]},{"name":"vars.tf","path":"examples/server-group/with-elb/vars.tf","sha":"4eb70bfff00b837c8404d044fee311b16e0e0c73"}]},{"name":"without-load-balancer","children":[{"name":"main.tf","path":"examples/server-group/without-load-balancer/main.tf","sha":"70f8ee203e31736b3a87c273faae98ad0c2c1aa3"},{"name":"outputs.tf","path":"examples/server-group/without-load-balancer/outputs.tf","sha":"27911554f10688f23ba9f8e31eadd4409c635f97"},{"name":"user-data","children":[{"name":"user-data.sh","path":"examples/server-group/without-load-balancer/user-data/user-data.sh","sha":"064d042a5d0ba6956f4eb8d7ece309b4d6eb4b33"}]},{"name":"vars.tf","path":"examples/server-group/without-load-balancer/vars.tf","sha":"0724aa38905b313165b621e7866575e0e0abdd4b"}]}]}]},{"name":"modules","children":[{"name":"asg-rolling-deploy","children":[{"name":"README.md","path":"modules/asg-rolling-deploy/README.md","sha":"fbbc6657f0cef2493e9fdb7b42549d69e5ff4080"},{"name":"describe-autoscaling-group","children":[{"name":"README.md","path":"modules/asg-rolling-deploy/describe-autoscaling-group/README.md","sha":"062e4ebc0b65610874998a354f441f56114b4e7e"},{"name":"boto3-1.7.10.zip","path":"modules/asg-rolling-deploy/describe-autoscaling-group/boto3-1.7.10.zip","sha":"4b76be11cfa98ddb4314e11a0b28700a11cd2fcc"},{"name":"get-desired-capacity.py","path":"modules/asg-rolling-deploy/describe-autoscaling-group/get-desired-capacity.py","sha":"c4972706f07ca0275c08bb8acbdf03e3a0e7a778"}]},{"name":"main.tf","path":"modules/asg-rolling-deploy/main.tf","sha":"986f00d77f93eb2e6918b692820791451205be20"},{"name":"outputs.tf","path":"modules/asg-rolling-deploy/outputs.tf","sha":"7db73654cd55edcf3706aeb3ba4a2a0ddac8dc5b"},{"name":"vars.tf","path":"modules/asg-rolling-deploy/vars.tf","sha":"1c4052b26ddc2dc4ec71d5d1a759d201e5db9e9f"}]},{"name":"server-group","children":[{"name":"README.md","path":"modules/server-group/README.md","sha":"677f3bef60b5b90a1d2c32220dfd536887d7e805"},{"name":"main.tf","path":"modules/server-group/main.tf","sha":"3a9bd5e1a44f83e6a2161184f827eaf436d08ded"},{"name":"outputs.tf","path":"modules/server-group/outputs.tf","sha":"42217027f4a9807a5eae6e786b7a1cd0f6976137"},{"name":"rolling-deploy","children":[{"name":"boto3-1.7.10.zip","path":"modules/server-group/rolling-deploy/boto3-1.7.10.zip","sha":"852dcda88e4e760ce8bdb5c56823f08659959a50"},{"name":"helpers.py","path":"modules/server-group/rolling-deploy/helpers.py","sha":"cbd7f09f0877e7b18fa39e7db8dd70a7cf6eea02"},{"name":"rolling_deployment.py","path":"modules/server-group/rolling-deploy/rolling_deployment.py","sha":"e63f3e9a2072daf9d261b739ea9b6eddb2a95f0f","toggled":true}],"toggled":true},{"name":"vars.tf","path":"modules/server-group/vars.tf","sha":"895f03d536d9922a979009284ee40dcea681944a"}],"toggled":true}],"toggled":true},{"name":"test","children":[{"name":"Gopkg.lock","path":"test/Gopkg.lock","sha":"936d6a18e6c09a998aa0e4acabc41edb3bb3d3c6"},{"name":"Gopkg.toml","path":"test/Gopkg.toml","sha":"006fb2dc5bc7b10c5e40bc3dc36eef626b0bc4bc"},{"name":"README.md","path":"test/README.md","sha":"cfa55a38cc6fbd09a311291216eb758159973629"},{"name":"asg_rolling_deploy_test.go","path":"test/asg_rolling_deploy_test.go","sha":"612907b131f214a1b6faa1546be8e1ff2de8b600"},{"name":"server_group_test.go","path":"test/server_group_test.go","sha":"6afc3507ab079a0143ada7dbace01d6f7339dbe5"},{"name":"test_helpers.go","path":"test/test_helpers.go","sha":"4034c4614efff195db3ca30f01301b11dcb8fd56"}]}]},"detailsContent":"<div class=\"preview__body--content\"><div><ul class=\"code__list\"><li class=\"code__item\"><span class=\"code__text\">import argparse</span></li>\n<li class=\"code__item\"><span class=\"code__text\">import helpers</span></li>\n<li class=\"code__item\"><span class=\"code__text\">import os</span></li>\n<li class=\"code__item\"><span class=\"code__text\">import time</span></li>\n<li class=\"code__item\"><span class=\"code__text\">from threading import Thread</span></li>\n<li class=\"code__item\"><span class=\"code__text\"></span></li>\n<li class=\"code__item\"><span class=\"code__text\">LAUNCH_CONFIG_TAG_NAME = <span class=\"hljs-string\">'LaunchConfigName'</span></span></li>\n<li class=\"code__item\"><span class=\"code__text\"></span></li>\n<li class=\"code__item\"><span class=\"code__text\"></span></li>\n<li class=\"code__item\"><span class=\"code__text\">def run():</span></li>\n<li class=\"code__item\"><span class=\"code__text\"> <span class=\"hljs-string\">\"\"</span><span class=\"hljs-string\">\"</span></li>\n<li class=\"code__item\"><span class=\"code__text\"> The main entrypoint for this script. It parses CLI arguments and kicks off a rolling deployment.</span></li>\n<li class=\"code__item\"><span class=\"code__text\"> \"</span><span class=\"hljs-string\">\"\"</span></span></li>\n<li class=\"code__item\"><span class=\"code__text\"></span></li>\n<li class=\"code__item\"><span class=\"code__text\"> parser = argparse.ArgumentParser(description=<span class=\"hljs-string\">'Perform a rolling deployment of a server group.'</span>)</span></li>\n<li class=\"code__item\"><span class=\"code__text\"></span></li>\n<li class=\"code__item\"><span class=\"code__text\"> parser.add_argument(<span class=\"hljs-string\">'--aws-region'</span>, <span class=\"hljs-built_in\">help</span>=<span class=\"hljs-string\">'The AWS region to use.'</span>, required=True)</span></li>\n<li class=\"code__item\"><span class=\"code__text\"> parser.add_argument(<span class=\"hljs-string\">'--server-group-size'</span>, <span class=\"hljs-built_in\">help</span>=<span class=\"hljs-string\">'The number of servers in the server group.'</span>, required=True, <span class=\"hljs-built_in\">type</span>=int)</span></li>\n<li class=\"code__item\"><span class=\"code__text\"> parser.add_argument(<span class=\"hljs-string\">'--server-group-name'</span>, <span class=\"hljs-built_in\">help</span>=<span class=\"hljs-string\">'The name of the server group. This should stay the same across all deployments.'</span>, required=True)</span></li>\n<li class=\"code__item\"><span class=\"code__text\"> parser.add_argument(<span class=\"hljs-string\">'--launch-config-name'</span>, <span class=\"hljs-built_in\">help</span>=<span class=\"hljs-string\">'The name of the Launch Configuration. This should change for each deployment.'</span>, required=True)</span></li>\n<li class=\"code__item\"><span class=\"code__text\"> parser.add_argument(<span class=\"hljs-string\">'--alb-target-group-arns'</span>, <span class=\"hljs-built_in\">help</span>=<span class=\"hljs-string\">'The ARN of an ALB Target Group to use for health checks.'</span>, nargs=<span class=\"hljs-string\">'*'</span>)</span></li>\n<li class=\"code__item\"><span class=\"code__text\"> parser.add_argument(<span class=\"hljs-string\">'--elb-names'</span>, <span class=\"hljs-built_in\">help</span>=<span class=\"hljs-string\">'The name of an ELB to use for health checks.'</span>, nargs=<span class=\"hljs-string\">'*'</span>)</span></li>\n<li class=\"code__item\"><span class=\"code__text\"> parser.add_argument(<span class=\"hljs-string\">'--batch-size'</span>, <span class=\"hljs-built_in\">help</span>=<span class=\"hljs-string\">'The number of servers to redeploy at a time.'</span>, <span class=\"hljs-built_in\">type</span>=int, default=helpers.DEFAULT_BATCH_SIZE)</span></li>\n<li class=\"code__item\"><span class=\"code__text\"> parser.add_argument(<span class=\"hljs-string\">'--max-retries'</span>, <span class=\"hljs-built_in\">help</span>=<span class=\"hljs-string\">'Maximum number of times to retry checking.'</span>, <span class=\"hljs-built_in\">type</span>=int, default=helpers.DEFAULT_MAX_RETRIES)</span></li>\n<li class=\"code__item\"><span class=\"code__text\"> parser.add_argument(<span class=\"hljs-string\">'--retry-interval-sec'</span>, <span class=\"hljs-built_in\">help</span>=<span class=\"hljs-string\">'How long to wait between each health check in seconds.'</span>, <span class=\"hljs-built_in\">type</span>=int, default=helpers.DEFAULT_SLEEP_BETWEEN_RETRIES_SEC)</span></li></ul></div></div>","repoName":"module-asg","repoRef":"v0.8.3","serviceDescriptor":{"serviceName":"Auto Scaling Group (stateful)","serviceRepoName":"module-asg","serviceRepoOrg":"gruntwork-io","serviceMainReadmePath":"/modules/server-group","cloudProviders":["aws"],"description":"Run an Auto Scaling Group for stateful apps. Supports zero-downtime, rolling deployment, auto healing, IAM Roles, EBS Volumes, and ENIs.","imageUrl":"auto-scaling2.png","licenseType":"subscriber","technologies":["Terraform","Bash"],"compliance":[],"tags":[""]},"serviceCategoryName":"Server orchestration","fileName":"rolling_deployment.py","filePath":"/modules/server-group/rolling-deploy/rolling_deployment.py","title":"Repo Browser: Auto Scaling Group (stateful)","description":"Browse the repos in the Gruntwork Infrastructure as Code Library."}