def prepare_deploy(args, previous_deploys, app):
    if len(previous_deploys) > 0:
        last_deploy = select_last_deploy(previous_deploys)

        app['instances'] = args.initial_instances
        next_colour = select_next_colour(last_deploy)
        next_port = select_next_port(last_deploy)
        deployment_target_instances = last_deploy['instances']
    else:
        next_colour = 'blue'
        next_port = get_service_port(app)
        deployment_target_instances = app['instances']

    app = set_app_ids(app, next_colour)
    app = set_service_ports(app, next_port)
    app['labels']['HAPROXY_DEPLOYMENT_TARGET_INSTANCES'] = \
        str(deployment_target_instances)
    app['labels']['HAPROXY_DEPLOYMENT_COLOUR'] = next_colour
    app['labels']['HAPROXY_DEPLOYMENT_STARTED_AT'] = datetime.now().isoformat()

    return app
Return a blue or a green version of `app` based on prexisting deploys
dataset/ETHPy150Open mesosphere/marathon-lb/bluegreen_deploy.py/prepare_deploy