Example #1
0
def main():
    if sys.version_info[:3] > (2, 7, 8):
        print "There is currently an SSL issue with Python 2.7.9 and newer."
        print "Please setup a virtualenv with Python 2.7.8 or less to proceed."
        sys.exit(1)
    new_hash = hashlib.md5(str(time.time())).hexdigest()[:8]
    parser = argparse.ArgumentParser()
    parser.add_argument("action", choices=ALLOWED_ACTIONS, action="store",
                        help="Action to take against the stack(s)")
    parser.add_argument("-l", "--location", nargs='*', action="store",
                        dest="locations", help="""If building, provide the
                        IP Address(es) from which ssh is allowed.\n
                        Example: './go.py build -l xx.xx.xx.xx yy.yy.yy.yy""",
                        type=ip_address_type, default=["0.0.0.0"])
    parser.add_argument('--region', action="store", dest="region",
                        default=DEFAULT_REGION)
    parser.add_argument('--hash', action="store", dest="hash_id",
                        help="""Define the hash to use for multiple
                        deployments.  If left blank, the hash will be
                        generated.""", default=new_hash)
    parser.add_argument('-u', '--user', action="store", dest="jenkins_user",
                        default=JENKINS_USER, help="Username for Jenkins")
    parser.add_argument('-e', '--email', action="store", dest="jenkins_email",
                        default=JENKINS_EMAIL, help="Email for Jenkins")
    parser.add_argument('-p', '--password', action="store_true",
                        dest="password_prompt",
                        help="Prompt for Jenkins Password")
    parser.add_argument('--full', action='store_true',
                        help="Always build all components. (VPC, RDS, etc.)")
    parser.add_argument('--warm', action='store_true',
                        help="Only build VPC, SG, and RDS")
    args = parser.parse_args()
    if args.password_prompt:
        print "WARNING: Password will be passed to CFN in plain text."
        args.jenkins_password = getpass.getpass()
    else:
        args.jenkins_password = JENKINS_PASSWORD
    connections = dict()
    connections['cfn'] = cfn_connect(args.region)
    if args.action == "info":
        info(connections)
        sys.exit(0)
    connections['codedeploy'] = codedeploy_connect(args.region)
    connections['ec2'] = ec2_connect(args.region)
    connections['iam'] = iam_connect(args.region)
    connections['s3'] = s3_connect(args.region)
    if args.action == "test":
        #  Test pieces here
        sys.exit(0)
    if args.action == "build":
        if not args.locations:
            print "Please provide at least one IP Address."
            parser.print_help()
            sys.exit(1)
        build(connections, args)
    elif args.action == "destroy":
        destroy(connections, args)
Example #2
0
def main():
    new_hash = hashlib.md5(str(time.time())).hexdigest()[:8]
    parser = argparse.ArgumentParser()
    parser.add_argument("action",
                        choices=ALLOWED_ACTIONS,
                        action="store",
                        help="Action to take against the stack(s)")
    parser.add_argument("-l",
                        "--location",
                        nargs='*',
                        action="store",
                        dest="locations",
                        help="""If building, provide the
                        IP Address(es) from which ssh is allowed.\n
                        Example: './go.py build -l xx.xx.xx.xx yy.yy.yy.yy""",
                        type=ip_address_type,
                        default=["0.0.0.0"])
    parser.add_argument('--region',
                        action="store",
                        dest="region",
                        default=DEFAULT_REGION)
    parser.add_argument('--hash',
                        action="store",
                        dest="hash_id",
                        help="""Define the hash to use for multiple
                        deployments.  If left blank, the hash will be
                        generated.""",
                        default=new_hash)
    parser.add_argument('--full',
                        action='store_true',
                        help="Always build all components. (VPC, RDS, etc.)")
    args = parser.parse_args()
    full = args.full
    connections = dict()
    connections['cfn'] = cfn_connect(args.region)
    if args.action == "info":
        info(connections)
        sys.exit(0)
    connections['codedeploy'] = codedeploy_connect(args.region)
    connections['ec2'] = ec2_connect(args.region)
    connections['iam'] = iam_connect(args.region)
    connections['main_s3'] = s3_connect(MAIN_S3_BUCKET_REGION)
    connections['s3'] = s3_connect(args.region)
    if args.action == "test":
        #  Test pieces here
        sys.exit(0)
    if args.action == "build":
        if not args.locations:
            print "Please provide at least one IP Address."
            parser.print_help()
            sys.exit(1)
        build(connections, args.region, args.locations, args.hash_id, full)
    elif args.action == "destroy":
        destroy(connections, args.region)
def main():
    # Fetch our region and stack arn written during the cfn deployment
    region, stack_arn = get_stack_config(CFN_HUP_LOCATION)

    # Make our AWS connections
    connections = dict()
    connections['cfn'] = cfn_connect(region)
    connections['codedeploy'] = codedeploy_connect(region)

    # Fetch the codedeploy details from the cfn stack arn
    codedeploy = get_codedeploy_app_and_group(connections['cfn'], stack_arn)

    # Get the latest git revision number
    commit_id = get_git_commit_id()

    # Create the codedeploy deployment
    revision = {
                    'revisionType': 'GitHub',
                    'gitHubLocation': {
                        'repository': GITHUB_REPOSITORY,
                        'commitId': commit_id
                    }
               }
    deploy_result = connections['codedeploy'].create_deployment(
        codedeploy['application'],
        codedeploy['group'],
        revision
    )

    # Wait for deployment to complete before we exit
    # Any suggestions to improve this code block are welcome
    cnt = 0
    done = False
    while (not done):
        deployment = connections['codedeploy'].get_deployment(deploy_result['deploymentId'])
        status = deployment['deploymentInfo']['status']

        if (cnt >= TIMEOUT):
            sys.stderr.write("Deployment failed to finish before %d minutes "
                             "timeout period.\n" % (TIMEOUT * 10))
            sys.exit(1)
        if status == "Failed":
            sys.stderr.write("Deployment returning FAILED status!\n")
            sys.exit(1)
        if status == "Succeeded":
            done = True

        time.sleep(SLEEP_SECONDS)
        cnt = cnt + SLEEP_SECONDS

    print "Deployment completed"
Example #4
0
def main():
    # Fetch our region and stack arn written during the cfn deployment
    region, stack_arn = get_stack_config(CFN_HUP_LOCATION)

    # Make our AWS connections
    connections = dict()
    connections['cfn'] = cfn_connect(region)
    connections['codedeploy'] = codedeploy_connect(region)

    # Fetch the codedeploy details from the cfn stack arn
    codedeploy = get_codedeploy_app_and_group(connections['cfn'], stack_arn)

    # Get the latest git revision number
    commit_id = get_git_commit_id()

    # Create the codedeploy deployment
    revision = {
                    'revisionType': 'GitHub',
                    'gitHubLocation': {
                        'repository': GITHUB_REPOSITORY,
                        'commitId': commit_id
                    }
               }
    deploy_result = connections['codedeploy'].create_deployment(
        codedeploy['application'],
        codedeploy['group'],
        revision
    )

    # Wait for deployment to complete before we exit
    # Any suggestions to improve this code block are welcome
    cnt = 0
    done = False
    while (not done):
        deployment = connections['codedeploy'].get_deployment(deploy_result['deploymentId'])
        status = deployment['deploymentInfo']['status']

        if (cnt >= TIMEOUT):
            sys.stderr.write("Deployment failed to finish before %d minutes "
                             "timeout period.\n" % (TIMEOUT * 10))
            sys.exit(1)
        if status == "Failed":
            sys.stderr.write("Deployment returning FAILED status!\n")
            sys.exit(1)
        if status == "Succeeded":
            done = True

        time.sleep(SLEEP_SECONDS)
        cnt = cnt + SLEEP_SECONDS

    print "Deployment completed"
Example #5
0
def main():
    new_hash = hashlib.md5(str(time.time())).hexdigest()[:8]
    parser = argparse.ArgumentParser()
    parser.add_argument("action", choices=ALLOWED_ACTIONS, action="store",
                        help="Action to take against the stack(s)")
    parser.add_argument("-l", "--location", nargs='*', action="store",
                        dest="locations", help="""If building, provide the
                        IP Address(es) from which ssh is allowed.\n
                        Example: './go.py build -l xx.xx.xx.xx yy.yy.yy.yy""",
                        type=ip_address_type, default=["0.0.0.0"])
    parser.add_argument('--region', action="store", dest="region",
                        default=DEFAULT_REGION)
    parser.add_argument('--hash', action="store", dest="hash_id",
                        help="""Define the hash to use for multiple
                        deployments.  If left blank, the hash will be
                        generated.""", default=new_hash)
    parser.add_argument('--full', action='store_true',
                        help="Always build all components. (VPC, RDS, etc.)")
    args = parser.parse_args()
    full = args.full
    connections = dict()
    connections['cfn'] = cfn_connect(args.region)
    if args.action == "info":
        info(connections)
        sys.exit(0)
    connections['codedeploy'] = codedeploy_connect(args.region)
    connections['ec2'] = ec2_connect(args.region)
    connections['iam'] = iam_connect(args.region)
    connections['main_s3'] = s3_connect(MAIN_S3_BUCKET_REGION)
    connections['s3'] = s3_connect(args.region)
    if args.action == "test":
        #  Test pieces here
        sys.exit(0)
    if args.action == "build":
        if not args.locations:
            print "Please provide at least one IP Address."
            parser.print_help()
            sys.exit(1)
        build(connections, args.region, args.locations, args.hash_id, full)
    elif args.action == "destroy":
        destroy(connections, args.region)