def _PossiblyConfigureEndpoints(self, service, new_version):
        """Configures endpoints for this service (if enabled).

    If the app has enabled Endpoints API Management features, pass control to
    the cloud_endpoints handler.

    The cloud_endpoints handler calls the Service Management APIs and creates an
    endpoints/service.json file on disk which will need to be bundled into the
    app Docker image.

    Args:
      service: yaml_parsing.ServiceYamlInfo, service configuration to be
        deployed
      new_version: version_util.Version describing where to deploy the service

    Returns:
      EndpointsServiceInfo, or None if endpoints were not created.
    """
        if self.deploy_options.enable_endpoints:
            return cloud_endpoints.ProcessEndpointsService(
                service, new_version.project)
        return None
Exemplo n.º 2
0
    def Deploy(self, service, new_version, code_bucket_ref, image,
               all_services):
        """Deploy the given service.

    Performs all deployment steps for the given service (if applicable):
    * Enable endpoints (for beta deployments)
    * Build and push the Docker image (Flex only, if image_url not provided)
    * Upload files (non-hermetic deployments)
    * Create the new version
    * Promote the version to receieve all traffic (if --promote given (default))
    * Stop the previous version (if new version promoted and
      --stop-previous-version given (default))

    Args:
      service: yaml_parsing.ServiceYamlInfo, service configuration to be
        deployed
      new_version: version_util.Version describing where to deploy the service
      code_bucket_ref: cloud_storage.BucketReference where the service's files
        have been uploaded
      image: str or None, the URL for the Docker image to be deployed (if image
        already exists).
      all_services: dict of service ID to service_util.Service objects
        corresponding to all pre-existing services (used to determine how to
        promote this version to receive all traffic, if applicable).
    """
        log.status.Print(
            'Beginning deployment of service [{service}]...'.format(
                service=new_version.service))

        # If the app has enabled Endpoints API Management features, pass
        # control to the cloud_endpoints handler.
        # The cloud_endpoints handler calls the Service Management APIs and
        # creates an endpoints/service.json file on disk which will need to
        # be bundled into the app Docker image.
        if self.deploy_options.enable_endpoints:
            cloud_endpoints.ProcessEndpointsService(service,
                                                    new_version.project)

        # Build and Push the Docker image if necessary for this service.
        if service.RequiresImage():
            log.warning(
                'Deployment of App Engine Flexible Environment apps is '
                'currently in Beta')
            if not image:
                image = deploy_command_util.BuildAndPushDockerImage(
                    new_version.project, service, new_version.id,
                    code_bucket_ref)
        else:
            image = None

        manifest = _UploadFiles(service, code_bucket_ref)

        # Actually create the new version of the service.
        message = 'Updating service [{service}]'.format(
            service=new_version.service)
        with console_io.ProgressTracker(message):
            self.api_client.DeployService(new_version.service, new_version.id,
                                          service, manifest, image)
            metrics.CustomTimedEvent(metric_names.DEPLOY_API)
            if self.deploy_options.promote:
                try:
                    version_util.PromoteVersion(
                        all_services, new_version, self.api_client,
                        self.deploy_options.stop_previous_version)
                except calliope_exceptions.HttpException as err:
                    raise VersionPromotionError(err)
            elif self.deploy_options.stop_previous_version:
                log.info(
                    'Not stopping previous version because new version was '
                    'not promoted.')