예제 #1
0
  def FromFile(file_path):
    """Parses the given service file.

    Args:
      file_path: str, The full path to the service file.

    Raises:
      YamlParseError: If the file is not a valid Yaml-file.
      YamlValidationError: If validation of parsed info fails.

    Returns:
      A ServiceYamlInfo object for the parsed file.
    """
    try:
      parsed = _YamlInfo._ParseYaml(file_path, appinfo_includes.Parse)
    except (yaml_errors.Error, appinfo_errors.Error) as e:
      raise YamlParseError(file_path, e)

    if parsed.runtime == 'vm':
      vm_runtime = parsed.GetEffectiveRuntime()
    else:
      vm_runtime = None
      if parsed.runtime == 'python':
        raise YamlValidationError(
            'Service [{service}] uses unsupported Python 2.5 runtime. '
            'Please use [runtime: python27] instead.'.format(
                service=parsed.module))
      elif parsed.runtime == 'python-compat':
        raise YamlValidationError(
            '"python-compat" is not a supported runtime.')
      elif parsed.runtime == 'custom' and not parsed.env:
        raise YamlValidationError(
            'runtime "custom" requires that env be explicitly specified.')

    if util.IsFlex(parsed.env) and vm_runtime == 'python27':
      raise YamlValidationError(
          'The "python27" is not a valid runtime in env: 2.  '
          'Please use [python-compat] instead.')

    if parsed.module:
      log.warn('The "module" parameter in application .yaml files is '
               'deprecated. Please use the "service" parameter instead.')
    else:
      parsed.module = parsed.service or ServiceYamlInfo.DEFAULT_SERVICE_NAME

    _CheckIllegalAttribute(
        name='application',
        yaml_info=parsed,
        extractor_func=lambda yaml: yaml.application,
        file_path=file_path,
        msg=HINT_PROJECT)

    _CheckIllegalAttribute(
        name='version',
        yaml_info=parsed,
        extractor_func=lambda yaml: yaml.version,
        file_path=file_path,
        msg=HINT_VERSION)

    return ServiceYamlInfo(file_path, parsed)
예제 #2
0
  def __init__(self, file_path, parsed):
    """Creates a new ServiceYamlInfo.

    Args:
      file_path: str, The full path the file that was parsed.
      parsed: appinfo.AppInfoExternal, parsed Application Configuration.
    """
    super(ServiceYamlInfo, self).__init__(file_path, parsed)
    self.module = parsed.module

    # All env: 2 apps are hermetic. All vm: false apps are not hermetic.
    # vm: true apps are hermetic IFF they don't use static files.
    if util.IsFlex(parsed.env):
      self.is_hermetic = True
    elif parsed.vm:
      for urlmap in parsed.handlers:
        if urlmap.static_dir or urlmap.static_files:
          self.is_hermetic = False
          break
      else:
        self.is_hermetic = True
    else:
      self.is_hermetic = False

    self.is_vm = parsed.runtime == 'vm' or self.is_hermetic
    self.runtime = (parsed.GetEffectiveRuntime()
                    if self.is_vm else parsed.runtime)
    if self.is_vm:
      self._UpdateManagedVMConfig()
    def FromFile(file_path):
        """Parses the given module file.

    Args:
      file_path: str, The full path to the module file.

    Raises:
      YamlParseError: If the file is not a valid Yaml-file.
      YamlValidationError: If validation of parsed info fails.

    Returns:
      A ModuleYamlInfo object for the parsed file.
    """
        try:
            parsed = _YamlInfo._ParseYaml(file_path, appinfo_includes.Parse)
        except (yaml_errors.Error, appinfo_errors.Error) as e:
            raise YamlParseError(file_path, e)

        if parsed.runtime == 'vm':
            vm_runtime = parsed.GetEffectiveRuntime()
        else:
            vm_runtime = None
            if parsed.runtime == 'python':
                raise YamlValidationError(
                    'Module [{module}] uses unsupported Python 2.5 runtime. '
                    'Please use [runtime: python27] instead.'.format(
                        module=parsed.module))
            elif parsed.runtime == 'python-compat':
                raise YamlValidationError(
                    '"python-compat" is not a supported runtime.')

        if util.IsFlex(parsed.env) and vm_runtime == 'python27':
            raise YamlValidationError(
                'The "python27" is not a valid runtime in env: 2.  '
                'Please use [python-compat] instead.')

        if not parsed.module:
            parsed.module = ModuleYamlInfo.DEFAULT_MODULE_NAME

        _CheckIllegalAttribute(name='application',
                               yaml_info=parsed,
                               extractor_func=lambda yaml: yaml.application,
                               file_path=file_path,
                               msg=HINT_PROJECT)

        _CheckIllegalAttribute(name='version',
                               yaml_info=parsed,
                               extractor_func=lambda yaml: yaml.version,
                               file_path=file_path,
                               msg=HINT_VERSION)

        return ModuleYamlInfo(file_path, parsed)
    def _GenerateDockerfile(self, cleaner):
        """Generates a Dockerfile appropriate to this application.

    Args:
      cleaner: (ext_runtime.Cleaner) A cleaner to populate

    Raises:
      JavaConfigError: if there is an app.yaml configuration error.
    """
        dockerfile = os.path.join(self.root, config.DOCKERFILE)
        if not os.path.exists(dockerfile):
            self.notify('Writing [%s] to [%s].' %
                        (config.DOCKERFILE, self.root))
            # Customize the dockerfile.
            with open(dockerfile, 'w') as out:
                if self.artifact_to_deploy.endswith('.war'):
                    out.write(DOCKERFILE_JETTY9_PREAMBLE)
                    out.write(
                        DOCKERFILE_INSTALL_WAR.format(self.artifact_to_deploy))
                if self.artifact_to_deploy.endswith('.jar'):
                    if self.server is not None:
                        raise JavaConfigError('Cannot use server %s '
                                              'for jar deployment.' %
                                              self.server)
                    out.write(DOCKERFILE_JAVA8_PREAMBLE)
                    out.write(
                        DOCKERFILE_INSTALL_APP.format(self.artifact_to_deploy))
                if self.artifact_to_deploy == '.':
                    if self.appinfo and util.IsFlex(self.appinfo.env):
                        out.write(DOCKERFILE_COMPAT_PREAMBLE)
                    elif self.openjdk == 'openjdk8':
                        out.write(DOCKERFILE_COMPAT_PREAMBLE)
                    else:
                        out.write(DOCKERFILE_LEGACY_PREAMBLE)
                    out.write(
                        DOCKERFILE_INSTALL_APP.format(self.artifact_to_deploy))

                # Generate the appropriate start command.
                if self.entrypoint:
                    out.write(DOCKEFILE_CMD % self.entrypoint)
                elif self.artifact_to_deploy.endswith('.jar'):
                    # for jar execution generate the command to run:
                    out.write(
                        DOCKERFILE_JAVA8_ENTRYPOINT.format(
                            self.artifact_to_deploy))

            cleaner.Add(dockerfile)
예제 #5
0
  def __init__(self, file_path, parsed):
    """Creates a new ServiceYamlInfo.

    Args:
      file_path: str, The full path the file that was parsed.
      parsed: appinfo.AppInfoExternal, parsed Application Configuration.
    """
    super(ServiceYamlInfo, self).__init__(file_path, parsed)
    self.module = parsed.module

    if util.IsFlex(parsed.env):
      self.env = util.Environment.FLEX
    elif parsed.vm or parsed.runtime == 'vm':
      self.env = util.Environment.MANAGED_VMS
    else:
      self.env = util.Environment.STANDARD

    # All env: 2 apps are hermetic. All vm: false apps are not hermetic except
    # for those with (explicit) env: 1 and runtime: custom. vm: true apps are
    # hermetic IFF they don't use static files.
    if self.env is util.Environment.FLEX:
      self.is_hermetic = True
    elif util.IsStandard(parsed.env):
      self.is_hermetic = parsed.runtime == 'custom'
    elif parsed.vm:
      for urlmap in parsed.handlers:
        if urlmap.static_dir or urlmap.static_files:
          self.is_hermetic = False
          break
      else:
        self.is_hermetic = True
    else:
      self.is_hermetic = False

    self._UpdateSkipFiles(file_path, parsed)

    if self.env is util.Environment.STANDARD and self.is_hermetic:
      self.runtime = parsed.runtime
    elif (self.env is util.Environment.MANAGED_VMS) or self.is_hermetic:
      self.runtime = parsed.GetEffectiveRuntime()
      self._UpdateVMSettings()
    else:
      self.runtime = parsed.runtime
예제 #6
0
    def __init__(self, file_path, parsed):
        """Creates a new ServiceYamlInfo.

    Args:
      file_path: str, The full path the file that was parsed.
      parsed: appinfo.AppInfoExternal, parsed Application Configuration.
    """
        super(ServiceYamlInfo, self).__init__(file_path, parsed)
        self.module = parsed.service or ServiceYamlInfo.DEFAULT_SERVICE_NAME

        if util.IsFlex(parsed.env):
            self.env = util.Environment.FLEX
        elif parsed.vm or parsed.runtime == 'vm':
            self.env = util.Environment.MANAGED_VMS
        else:
            self.env = util.Environment.STANDARD

        # All `env: flex` apps are hermetic. All `env: standard` apps are not
        # hermetic. All `vm: true` apps are hermetic IFF they don't use static
        # files.
        if self.env is util.Environment.FLEX:
            self.is_hermetic = True
        elif parsed.vm:
            for urlmap in parsed.handlers:
                if urlmap.static_dir or urlmap.static_files:
                    self.is_hermetic = False
                    break
            else:
                self.is_hermetic = True
        else:
            self.is_hermetic = False

        self._InitializeHasExplicitSkipFiles(file_path, parsed)
        self._UpdateSkipFiles(parsed)

        if (self.env is util.Environment.MANAGED_VMS) or self.is_hermetic:
            self.runtime = parsed.GetEffectiveRuntime()
            self._UpdateVMSettings()
        else:
            self.runtime = parsed.runtime
예제 #7
0
    def FromFile(file_path):
        """Parses the given service file.

    Args:
      file_path: str, The full path to the service file.

    Raises:
      YamlParseError: If the file is not a valid Yaml-file.
      YamlValidationError: If validation of parsed info fails.

    Returns:
      A ServiceYamlInfo object for the parsed file.
    """
        try:
            parsed = _YamlInfo._ParseYaml(file_path, appinfo_includes.Parse)
        except (yaml_errors.Error, appinfo_errors.Error) as e:
            raise YamlParseError(file_path, e)

        if parsed.runtime == 'vm':
            vm_runtime = parsed.GetEffectiveRuntime()
        else:
            vm_runtime = None
            if parsed.runtime == 'python':
                raise YamlValidationError(
                    'Service [{service}] uses unsupported Python 2.5 runtime. '
                    'Please use [runtime: python27] instead.'.format(
                        service=(parsed.service
                                 or ServiceYamlInfo.DEFAULT_SERVICE_NAME)))
            elif parsed.runtime == 'python-compat':
                raise YamlValidationError(
                    '"python-compat" is not a supported runtime.')
            elif parsed.runtime == 'custom' and not parsed.env:
                raise YamlValidationError(
                    'runtime "custom" requires that env be explicitly specified.'
                )

        if parsed.vm:
            log.warning(MANAGED_VMS_DEPRECATION_WARNING)

        if (util.IsFlex(parsed.env) and parsed.beta_settings
                and parsed.beta_settings.get('enable_app_engine_apis')):
            log.warning(APP_ENGINE_APIS_DEPRECATION_WARNING)

        if util.IsFlex(parsed.env) and vm_runtime == 'python27':
            raise YamlValidationError(
                'The "python27" is not a valid runtime in env: flex.  '
                'Please use [python] instead.')

        if util.IsFlex(parsed.env) and vm_runtime == 'python-compat':
            log.warning(
                '[runtime: {}] is deprecated.  Please use [runtime: python] '
                'instead.  See {} for more info.'.format(
                    vm_runtime, UPGRADE_FLEX_PYTHON_URL))

        for warn_text in parsed.GetWarnings():
            log.warning('In file [{0}]: {1}'.format(file_path, warn_text))

        if (util.IsStandard(parsed.env) and parsed.runtime == 'python27'
                and HasLib(parsed, 'ssl', '2.7')):
            log.warning(PYTHON_SSL_WARNING)

        _CheckIllegalAttribute(name='application',
                               yaml_info=parsed,
                               extractor_func=lambda yaml: yaml.application,
                               file_path=file_path,
                               msg=HINT_PROJECT)

        _CheckIllegalAttribute(name='version',
                               yaml_info=parsed,
                               extractor_func=lambda yaml: yaml.version,
                               file_path=file_path,
                               msg=HINT_VERSION)

        return ServiceYamlInfo(file_path, parsed)