def _ValidateRuntime(self, service_info):
        """Validates explicit runtime builders are not used without the feature on.

    Args:
      service_info: yaml_parsing.ServiceYamlInfo, service configuration to be
        deployed

    Raises:
      InvalidRuntimeNameError: if the runtime name is invalid for the deployment
        (see above).
    """
        runtime = service_info.runtime
        if runtime == 'custom':
            return

        # This may or may not be accurate, but it only matters for custom runtimes,
        # which are handled above.
        needs_dockerfile = True
        strategy = self.deploy_options.runtime_builder_strategy
        use_runtime_builders = deploy_command_util.ShouldUseRuntimeBuilders(
            service_info, strategy, needs_dockerfile)
        if not use_runtime_builders and not ORIGINAL_RUNTIME_RE.match(runtime):
            raise InvalidRuntimeNameError(runtime, ORIGINAL_RUNTIME_RE_STRING)
Esempio n. 2
0
    def _PossiblyRewriteRuntime(self, service_info):
        """Rewrites the effective runtime of the service to 'custom' if necessary.

    Some runtimes which are valid client-side are *not* valid in the server.
    Namely, `gs://` URL runtimes (which are effectively `custom`) and runtimes
    with `.` in the names (ex. `go-1.8`). For these, we need to rewrite the
    runtime that we send up to the server to "custom" so that it passes
    validation.

    This *only* applies when we're using runtime builders to build the
    application (that is, runtime builders are turned on *and* the environment
    is Flexible), since neither of these runtime types are valid otherwise. If
    not, it results in an error.

    Args:
      service_info: yaml_parsing.ServiceYamlInfo, service configuration to be
        deployed

    Raises:
      InvalidRuntimeNameError: if the runtime name is invalid for the deployment
        (see above).
    """
        # TODO(b/63040070) Remove this whole method (which is a hack) once the API
        # can take the paths we need as a runtime name.
        runtime = service_info.runtime
        if runtime == 'custom':
            return

        # This may or may not be accurate, but it only matters for custom runtimes,
        # which are handled above.
        needs_dockerfile = True
        strategy = self.deploy_options.runtime_builder_strategy
        use_runtime_builders = deploy_command_util.ShouldUseRuntimeBuilders(
            service_info, strategy, needs_dockerfile)
        if _ShouldRewriteRuntime(runtime, use_runtime_builders):
            service_info.parsed.SetEffectiveRuntime('custom')