Exemplo n.º 1
0
    def Run(self, args):
        """Deploy an app, function or container to Cloud Run."""
        source_ref = flags.GetSourceRef(args.source, args.image)
        config_changes = flags.GetConfigurationChanges(args)

        conn_context = connection_context.GetConnectionContext(args)
        service_ref = flags.GetService(args)
        function_entrypoint = flags.GetFunction(args.function)
        msg = ('Deploying {dep_type} to service [{{bold}}{{service}}{{reset}}]'
               ' in {ns_label} [{{bold}}{{ns}}{{reset}}]')

        msg += conn_context.location_label

        if function_entrypoint:
            pretty_print.Info(msg.format(
                ns_label=conn_context.ns_label,
                dep_type='function [{bold}{function}{reset}]'),
                              function=function_entrypoint,
                              service=service_ref.servicesId,
                              ns=service_ref.namespacesId)
        elif source_ref.source_type is source_ref.SourceType.IMAGE:
            pretty_print.Info(msg.format(ns_label=conn_context.ns_label,
                                         dep_type='container'),
                              service=service_ref.servicesId,
                              ns=service_ref.namespacesId)
        else:
            pretty_print.Info(msg.format(ns_label=conn_context.ns_label,
                                         dep_type='app'),
                              service=service_ref.servicesId,
                              ns=service_ref.namespacesId)

        with serverless_operations.Connect(conn_context) as operations:
            if not (source_ref.source_type is source_ref.SourceType.IMAGE
                    or operations.IsSourceBranch()):
                raise exceptions.SourceNotSupportedError()
            new_deployable = operations.Detect(service_ref.Parent(),
                                               source_ref, function_entrypoint)
            operations.Upload(new_deployable)
            changes = [new_deployable]
            if config_changes:
                changes.extend(config_changes)
            operations.ReleaseService(service_ref, changes, asyn=args. async)
            url = operations.GetServiceUrl(service_ref)
            conf = operations.GetConfiguration(service_ref)

        msg = ('{{bold}}Service [{serv}] revision [{rev}] has been deployed'
               ' and is serving traffic at{{reset}} {url}')
        msg = msg.format(serv=service_ref.servicesId,
                         rev=conf.status.latestReadyRevisionName,
                         url=url)
        pretty_print.Success(msg)
Exemplo n.º 2
0
  def Run(self, args):
    """Deploy an app, function or container to Cloud Run."""
    source_ref = flags.GetSourceRef(args.source, args.image)
    config_changes = flags.GetConfigurationChanges(args)

    conn_context = connection_context.GetConnectionContext(args)

    # pylint: disable=protected-access
    if (not isinstance(conn_context, connection_context._GKEConnectionContext)
        and getattr(args, 'endpoint', None)):
      raise exceptions.ConfigurationError(
          'The `--endpoint=[internal|external]` flag '
          'is only supported with Cloud Run on GKE.')
    # pylint: enable=protected-access

    service_ref = flags.GetService(args)
    function_entrypoint = flags.GetFunction(args.function)
    msg = ('Deploying {dep_type} to {operator} '
           'service [{{bold}}{service}{{reset}}]'
           ' in {ns_label} [{{bold}}{ns}{{reset}}]')

    msg += conn_context.location_label

    if function_entrypoint:
      dep_type = 'function [{{bold}}{}{{reset}}]'.format(function_entrypoint)
      pretty_print.Info(msg.format(
          operator=conn_context.operator,
          ns_label=conn_context.ns_label,
          dep_type=dep_type,
          function=function_entrypoint,
          service=service_ref.servicesId,
          ns=service_ref.namespacesId))
    elif source_ref.source_type is source_ref.SourceType.IMAGE:
      pretty_print.Info(msg.format(
          operator=conn_context.operator,
          ns_label=conn_context.ns_label,
          dep_type='container',
          service=service_ref.servicesId,
          ns=service_ref.namespacesId))
    else:
      pretty_print.Info(msg.format(
          operator=conn_context.operator,
          ns_label=conn_context.ns_label,
          dep_type='app',
          service=service_ref.servicesId,
          ns=service_ref.namespacesId))

    with serverless_operations.Connect(conn_context) as operations:
      if not (source_ref.source_type is source_ref.SourceType.IMAGE
              or operations.IsSourceBranch()):
        raise exceptions.SourceNotSupportedError()
      new_deployable = operations.Detect(service_ref.Parent(),
                                         source_ref, function_entrypoint)
      operations.Upload(new_deployable)
      changes = [new_deployable]
      if config_changes:
        changes.extend(config_changes)

      if args.endpoint == 'internal':
        private_endpoint = True
      elif args.endpoint == 'external':
        private_endpoint = False
      else:
        private_endpoint = None

      operations.ReleaseService(service_ref, changes, asyn=args.async,
                                private_endpoint=private_endpoint)
      url = operations.GetServiceUrl(service_ref)
      conf = operations.GetConfiguration(service_ref)

    msg = (
        'Service [{{bold}}{serv}{{reset}}] revision [{{bold}}{rev}{{reset}}] '
        'has been deployed and is serving traffic at {{bold}}{url}{{reset}}')
    msg = msg.format(
        serv=service_ref.servicesId,
        rev=conf.status.latestReadyRevisionName,
        url=url)
    pretty_print.Success(msg)
Exemplo n.º 3
0
    def Run(self, args):
        """Deploy an app, function or container to Cloud Run."""
        source_ref = flags.GetSourceRef(args.source, args.image)
        config_changes = flags.GetConfigurationChanges(args)

        conn_context = connection_context.GetConnectionContext(args)

        if (conn_context.supports_one_platform
                and getattr(args, 'connectivity', None)):
            raise exceptions.ConfigurationError(
                'The `--endpoint=[internal|external]` flag '
                'is only supported with Cloud Run on GKE.')

        if (not conn_context.supports_one_platform
                and getattr(args, 'allow_unauthenticated', None)):
            raise exceptions.ConfigurationError(
                'The `--allow-unauthenticated` flag '
                'is not supported with Cloud Run on GKE.')

        service_ref = flags.GetService(args)
        function_entrypoint = flags.GetFunction(args.function)
        msg = ('Deploying {dep_type} to {operator} '
               'service [{{bold}}{service}{{reset}}]'
               ' in {ns_label} [{{bold}}{ns}{{reset}}]')

        msg += conn_context.location_label

        if function_entrypoint:
            dep_type = 'function [{{bold}}{}{{reset}}]'.format(
                function_entrypoint)
            pretty_print.Info(
                msg.format(operator=conn_context.operator,
                           ns_label=conn_context.ns_label,
                           dep_type=dep_type,
                           function=function_entrypoint,
                           service=service_ref.servicesId,
                           ns=service_ref.namespacesId))
        elif source_ref.source_type is source_ref.SourceType.IMAGE:
            pretty_print.Info(
                msg.format(operator=conn_context.operator,
                           ns_label=conn_context.ns_label,
                           dep_type='container',
                           service=service_ref.servicesId,
                           ns=service_ref.namespacesId))
        else:
            pretty_print.Info(
                msg.format(operator=conn_context.operator,
                           ns_label=conn_context.ns_label,
                           dep_type='app',
                           service=service_ref.servicesId,
                           ns=service_ref.namespacesId))

        with serverless_operations.Connect(conn_context) as operations:
            if not (source_ref.source_type is source_ref.SourceType.IMAGE
                    or operations.IsSourceBranch()):
                raise exceptions.SourceNotSupportedError()
            new_deployable = operations.Detect(service_ref.Parent(),
                                               source_ref, function_entrypoint)
            operations.Upload(new_deployable)
            changes = [new_deployable]
            if config_changes:
                changes.extend(config_changes)
            if args.connectivity == 'internal':
                private_endpoint = True
            elif args.connectivity == 'external':
                private_endpoint = False
            else:
                private_endpoint = None
            deployment_stages = stages.ServiceStages()
            exists = operations.GetService(service_ref)

            if (not exists and not args.allow_unauthenticated
                    and conn_context.supports_one_platform):

                if operations.CanAddIamPolicyBinding(service_ref):
                    allow_unauth = console_io.PromptContinue(
                        prompt_string=('Allow unauthenticated invocations '
                                       'to new service [{}]?'.format(
                                           service_ref.servicesId)),
                        default=False)
                else:
                    allow_unauth = False
                    pretty_print.Info(
                        'This new service will require authentication to be invoked.'
                    )
            else:
                allow_unauth = False

            header = 'Deploying...' if exists else 'Deploying new service...'
            with progress_tracker.StagedProgressTracker(
                    header,
                    deployment_stages,
                    failure_message='Deployment failed',
                    suppress_output=args. async) as tracker:
                operations.ReleaseService(service_ref,
                                          changes,
                                          tracker,
                                          asyn=args. async,
                                          private_endpoint=private_endpoint,
                                          allow_unauthenticated=allow_unauth
                                          or args.allow_unauthenticated)
            if args. async:
                pretty_print.Success(
                    'Service [{{bold}}{serv}{{reset}}] is deploying '
                    'asynchronously.'.format(serv=service_ref.servicesId))
            else:
                url = operations.GetServiceUrl(service_ref)
                conf = operations.GetConfiguration(service_ref)
                msg = ('Service [{{bold}}{serv}{{reset}}] '
                       'revision [{{bold}}{rev}{{reset}}] '
                       'has been deployed and is serving traffic at '
                       '{{bold}}{url}{{reset}}')
                msg = msg.format(serv=service_ref.servicesId,
                                 rev=conf.status.latestReadyRevisionName,
                                 url=url)
                pretty_print.Success(msg)