def deploy_app_gke()

in appengine/integration_tests/testsuite/deploy_app.py [0:0]


def deploy_app_gke(yaml):
    logging.debug('Starting deploy to GKE')

    image_name = test_util.generate_gke_image_name()
    service_name = test_util.generate_gke_service_name()
    namespace = test_util.generate_namespace()

    build_command = ['docker', 'build', '-t', image_name, '.']
    test_util.execute_command(build_command, True)

    push_command = ['gcloud', 'docker', '--', 'push', image_name]
    test_util.execute_command(push_command, True)

    # This command updates the kubeconfig file with credentials for the given
    # GKE cluster. Essentially, points kubectl to our preconfigured cluster.
    cred_command = ['gcloud', 'container', 'clusters',
                    'get-credentials', constants.CLUSTER_NAME]
    test_util.execute_command(cred_command, True)

    namespace_command = ['kubectl', 'create', 'namespace', namespace]
    test_util.execute_command(namespace_command, True)

    deploy_command = ['kubectl', 'apply', '-f', '-',
                      '--namespace', namespace]

    try:
        test_util.execute_command(deploy_command, True,
                                  template.GKE_TEMPLATE.format(
                                    service_name=service_name,
                                    test_image=image_name))

        return namespace, test_util.get_external_ip_for_cluster(service_name,
                                                                namespace)
    except subprocess.CalledProcessError as e:
        try:
            stop_deployment(namespace)
        except Exception:
            pass
        raise e