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] 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)
def deploy_app_gae(yaml): logging.debug('Starting deploy to GAE') deployed_version = test_util.generate_version() # TODO: once sdk driver is published, use it here deploy_command = ['gcloud', 'app', 'deploy', '--no-promote', '--version', deployed_version, '-q'] if yaml: logging.info(yaml) deploy_command.append(yaml) test_util.execute_command(deploy_command, True) return (deployed_version, test_util.retrieve_url_for_version(deployed_version))
def stop_deployment(namespace): logging.debug('Removing namespace %s', namespace) try: service_command = ['kubectl', 'get', 'services', '--namespace', namespace, '--output=json'] output = test_util.execute_command(service_command, True) logging.info(output) services = json.loads(output)['items'] for service in services: name = service['metadata']['name'] delete_service_cmd = ['kubectl', 'delete', 'service', name, '--namespace', namespace] test_util.execute_command(delete_service_cmd, True) delete_command = ['kubectl', 'delete', 'namespace', namespace] test_util.execute_command(delete_command, True) except subprocess.CalledProcessError as cpe: logging.error('Error encountered when deleting namespace! ' 'Manual cleanup may be necessary. %s', cpe.output) except Exception as e: logging.error('Error encountered when deleting services! ' 'Manual cleanup may be necessary. %s', e)
def deploy_app_gae(yaml): logging.debug('Starting deploy to GAE') deployed_version = test_util.generate_version() # TODO: once sdk driver is published, use it here deploy_command = ['gcloud', 'app', 'deploy', '--no-promote', '--version', deployed_version, '-q'] if yaml: logging.info(yaml) deploy_command.append(yaml) try: test_util.execute_command(deploy_command, True) return (deployed_version, test_util.retrieve_url_for_version(deployed_version)) except subprocess.CalledProcessError as e: try: stop_version(deployed_version) except Exception: pass raise e