Ejemplo n.º 1
0
    def Run(self, args):
        """Update environment variables."""
        cluster_ref = args.CONCEPTS.cluster.Parse()
        service_ref = flags.GetService(args)

        with serverless_operations.Connect(cluster_ref) as client:
            changes = flags.GetConfigurationChanges(args)
            if not changes:
                raise exceptions.NoConfigurationChangeError(
                    'No configuration change requested. '
                    'Did you mean to include the flags --update-env-vars, '
                    '--memory, or --concurrency?')
            client.ReleaseService(service_ref, changes, args. async)
            url = client.GetServiceUrl(service_ref)
            active_revs = client.GetActiveRevisions(service_ref)

        msg = ('{{bold}}Service [{serv}] revision{plural} {rev_msg} is active'
               ' and serving traffic at{{reset}} {url}')

        rev_msg = ' '.join(['[{}]'.format(rev) for rev in active_revs])

        msg = msg.format(serv=service_ref.servicesId,
                         plural='s' if len(active_revs) > 1 else '',
                         rev_msg=rev_msg,
                         url=url)

        pretty_print.Success(msg)
Ejemplo n.º 2
0
    def Run(self, args):
        """Deploy an app, function or container to Serverless Engine."""
        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)