Пример #1
0
  def Run(self, args):
    """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.

    Raises:
      FailedBuildException: If the build is completed and not 'SUCCESS'.
    """

    messages = cloudbuild_util.GetMessagesModule()

    # Create the build request.
    build_config = submit_util.CreateBuildConfig(
        args.tag, args.no_cache, messages, args.substitutions, args.config,
        args.IsSpecified('source'), args.no_source, args.source,
        args.gcs_source_staging_dir, args.ignore_file, args.gcs_log_dir,
        args.machine_type, args.disk_size)

    # Start the build.
    return submit_util.Build(messages, args.async_, build_config)
Пример #2
0
    def BuildAndStoreFlexTemplateImage(image_gcr_path,
                                       flex_template_base_image, jar_paths,
                                       py_paths, env, sdk_language,
                                       gcs_log_dir):
        """Builds the flex template docker container image and stores it in GCR.

    Args:
      image_gcr_path: GCR location to store the flex template container image.
      flex_template_base_image: SDK version or base image to use.
      jar_paths: List of jar paths to pipelines and dependencies.
      py_paths: List of python paths to pipelines and dependencies.
      env: Dictionary of env variables to set in the container image.
      sdk_language: SDK language of the flex template.
      gcs_log_dir: Path to Google Cloud Storage directory to store build logs.

    Returns:
      True if container is built and store successfully.

    Raises:
      ValueError: If the parameters values are invalid.
    """
        Templates.__ValidateFlexTemplateEnv(env, sdk_language)
        with files.TemporaryDirectory() as temp_dir:
            log.status.Print(
                'Copying files to a temp directory {}'.format(temp_dir))

            pipeline_files = []
            paths = jar_paths
            if py_paths:
                paths = py_paths
            for path in paths:
                absl_path = os.path.abspath(path)
                if os.path.isfile(absl_path):
                    shutil.copy2(absl_path, temp_dir)
                else:
                    shutil.copytree(
                        absl_path, '{}/{}'.format(temp_dir,
                                                  os.path.basename(absl_path)))
                pipeline_files.append(os.path.split(absl_path)[1])

            log.status.Print(
                'Generating dockerfile to build the flex template container image...'
            )
            dockerfile_contents = Templates.BuildDockerfile(
                flex_template_base_image, pipeline_files, env, sdk_language)

            dockerfile_path = os.path.join(temp_dir, 'Dockerfile')
            files.WriteFileContents(dockerfile_path, dockerfile_contents)
            log.status.Print('Generated Dockerfile. Contents: {}'.format(
                dockerfile_contents))

            messages = cloudbuild_util.GetMessagesModule()
            build_config = submit_util.CreateBuildConfig(
                image_gcr_path, False, messages, None, 'cloudbuild.yaml', True,
                False, temp_dir, None, None, gcs_log_dir, None, None, None,
                None)
            log.status.Print('Pushing flex template container image to GCR...')

            submit_util.Build(messages, False, build_config)
            return True
Пример #3
0
  def Run(self, args):
    """Deploy a container to Cloud Run."""
    service_ref = flags.GetService(args)
    image = args.image
    # Build an image from source if source specified.
    if flags.FlagIsExplicitlySet(args, 'source'):
      # Create a tag for the image creation
      if image is None and not args.IsSpecified('config'):
        image = 'gcr.io/{projectID}/cloud-run-source-deploy/{service}:{tag}'.format(
            projectID=properties.VALUES.core.project.Get(required=True),
            service=service_ref.servicesId,
            tag=uuid.uuid4().hex)
      messages = cloudbuild_util.GetMessagesModule()
      build_config = submit_util.CreateBuildConfig(
          image, args.no_cache, messages, args.substitutions, args.config,
          args.IsSpecified('source'), False, args.source,
          args.gcs_source_staging_dir, args.ignore_file, args.gcs_log_dir,
          args.machine_type, args.disk_size)
      submit_util.Build(messages, args.async_, build_config)

    # Deploy a container with an image
    conn_context = connection_context.GetConnectionContext(
        args, flags.Product.RUN, self.ReleaseTrack())
    config_changes = flags.GetConfigurationChanges(args)

    with serverless_operations.Connect(conn_context) as operations:
      image_change = config_changes_mod.ImageChange(image)
      changes = [image_change]
      if config_changes:
        changes.extend(config_changes)
      service = operations.GetService(service_ref)
      allow_unauth = GetAllowUnauth(args, operations, service_ref, service)

      pretty_print.Info(GetStartDeployMessage(conn_context, service_ref))
      has_latest = (service is None or
                    traffic.LATEST_REVISION_KEY in service.spec_traffic)
      deployment_stages = stages.ServiceStages(
          include_iam_policy_set=allow_unauth is not None,
          include_route=has_latest)
      header = 'Deploying...' if service 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_,
            allow_unauthenticated=allow_unauth,
            prefetch=service)
      if args.async_:
        pretty_print.Success(
            'Service [{{bold}}{serv}{{reset}}] is deploying '
            'asynchronously.'.format(serv=service_ref.servicesId))
      else:
        pretty_print.Success(GetSuccessMessageForSynchronousDeploy(
            operations, service_ref))
Пример #4
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.

    Raises:
      FailedBuildException: If the build is completed and not 'SUCCESS'.
    """
        build_region = args.region

        messages = cloudbuild_util.GetMessagesModule()

        # Create the build request.
        build_config = submit_util.CreateBuildConfigAlpha(
            args.tag,
            args.no_cache,
            messages,
            args.substitutions,
            args.config,
            args.IsSpecified('source'),
            args.no_source,
            args.source,
            args.gcs_source_staging_dir,
            args.ignore_file,
            args.gcs_log_dir,
            args.machine_type,
            args.disk_size,
            args.worker_pool,
            args.pack,
            arg_cluster_name=args.cluster,
            arg_cluster_location=args.cluster_location)

        build_region = submit_util.DetermineBuildRegion(
            build_config, build_region)
        build_region = build_region or cloudbuild_util.DEFAULT_REGION

        # Start the build.
        build, _ = submit_util.Build(messages,
                                     args.async_,
                                     build_config,
                                     build_region=build_region,
                                     support_gcl=True)
        return build