예제 #1
0
    def GenerateConfigs(self):
        """Generate all config files for the module."""
        # Write "Saving file" messages to the user or to log depending on whether
        # we're in "deploy."
        if self.params.deploy:
            notify = log.info
        else:
            notify = log.status.Print

        # Generate app.yaml.
        cleaner = fingerprinting.Cleaner()
        if not self.params.deploy:
            app_yaml = os.path.join(self.root, 'app.yaml')
            if not os.path.exists(app_yaml):
                notify('Saving [app.yaml] to [%s].' % self.root)
                runtime = 'custom' if self.params.custom else 'python'
                with open(app_yaml, 'w') as f:
                    f.write(
                        PYTHON_APP_YAML.format(entrypoint=self.entrypoint,
                                               runtime=runtime))
                cleaner.Add(app_yaml)

        if self.params.custom or self.params.deploy:
            dockerfile = os.path.join(self.root, config.DOCKERFILE)
            if not os.path.exists(dockerfile):
                notify('Saving [%s] to [%s].' % (config.DOCKERFILE, self.root))
                # Customize the dockerfile.
                with open(dockerfile, 'w') as out:
                    out.write(DOCKERFILE_PREAMBLE)

                    if self.got_requirements_txt:
                        out.write(DOCKERFILE_REQUIREMENTS_TXT)

                    out.write(DOCKERFILE_INSTALL_APP)

                    # Generate the appropriate start command.
                    if self.entrypoint:
                        out.write('CMD %s\n' % self.entrypoint)

                cleaner.Add(dockerfile)

            # Generate .dockerignore TODO(user): eventually this file will just be
            # copied verbatim.
            dockerignore = os.path.join(self.root, '.dockerignore')
            if not os.path.exists(dockerignore):
                notify('Saving [.dockerignore] to [%s].' % self.root)
                with open(dockerignore, 'w') as f:
                    f.write(DOCKERIGNORE)
                cleaner.Add(dockerignore)

        if not cleaner.HasFiles():
            notify('All config files already exist, not generating anything.')

        return cleaner
예제 #2
0
    def GenerateConfigs(self):
        """Generate all config files for the module.

    Returns:
      (callable()) fingerprinting.Cleaner instance.
    """
        # Write "Saving file" messages to the user or to log depending on whether
        # we're in "deploy."
        if self.params.deploy:
            notify = log.info
        else:
            notify = log.status.Print

        # Generate app.yaml.
        cleaner = fingerprinting.Cleaner()
        if not self.params.deploy:
            app_yaml = os.path.join(self.root, 'app.yaml')
            if not os.path.exists(app_yaml):
                notify('Saving [app.yaml] to [%s].' % self.root)
                runtime = 'custom' if self.params.custom else 'go'
                with open(app_yaml, 'w') as f:
                    f.write(GO_APP_YAML.format(runtime=runtime))
                cleaner.Add(app_yaml)

        if self.params.custom or self.params.deploy:
            dockerfile = os.path.join(self.root, config.DOCKERFILE)
            if not os.path.exists(dockerfile):
                notify('Saving [%s] to [%s].' % (config.DOCKERFILE, self.root))
                util.FindOrCopyDockerfile(GO_RUNTIME_NAME,
                                          self.root,
                                          cleanup=self.params.deploy)
                cleaner.Add(dockerfile)

            # Generate .dockerignore TODO(user): eventually this file will just be
            # copied verbatim.
            dockerignore = os.path.join(self.root, '.dockerignore')
            if not os.path.exists(dockerignore):
                notify('Saving [.dockerignore] to [%s].' % self.root)
                with open(dockerignore, 'w') as f:
                    f.write(DOCKERIGNORE)
                cleaner.Add(dockerignore)

                if self.params.deploy:
                    atexit.register(util.Clean, dockerignore)

        if not cleaner.HasFiles():
            notify('All config files already exist, not generating anything.')

        return cleaner
예제 #3
0
    def GenerateConfigs(self):
        """Generates all config files for the module.

    Returns:
      (fingerprinting.Cleaner) A cleaner populated with the generated files
    """

        cleaner = fingerprinting.Cleaner()

        if not self.params.deploy:
            self._GenerateAppYaml(cleaner)
        if self.params.custom or self.params.deploy:
            self._GenerateDockerfile(cleaner)
            self._GenerateDockerignore(cleaner)

        if not cleaner.HasFiles():
            self.notify(
                'All config files already exist, not generating anything.')

        return cleaner
예제 #4
0
    def GenerateConfigs(self):
        """Generate all config files for the module."""
        # Write "Saving file" messages to the user or to log depending on whether
        # we're in "deploy."
        if self.params.deploy:
            notify = log.info
        else:
            notify = log.status.Print

        # Generate app.yaml.
        cleaner = fingerprinting.Cleaner()
        if not self.params.deploy:
            app_yaml = os.path.join(self.root, 'app.yaml')
            if not os.path.exists(app_yaml):
                notify('Saving [app.yaml] to [%s].' % self.root)
                cleaner.Add(app_yaml)
                runtime = 'custom' if self.params.custom else 'nodejs'
                with open(app_yaml, 'w') as f:
                    f.write(NODEJS_APP_YAML.format(runtime=runtime))

        if self.params.custom or self.params.deploy:
            dockerfile = os.path.join(self.root, config.DOCKERFILE)
            if not os.path.exists(dockerfile):
                notify('Saving [%s] to [%s].' % (config.DOCKERFILE, self.root))
                util.FindOrCopyDockerfile(NODEJS_RUNTIME_NAME,
                                          self.root,
                                          cleanup=self.params.deploy)
                cleaner.Add(dockerfile)

                # Customize the dockerfile.
                os.chmod(dockerfile, os.stat(dockerfile).st_mode | 0200)
                with open(dockerfile, 'a') as out:

                    # Generate copy for shrinkwrap file.
                    if self.got_shrinkwrap:
                        out.write('COPY npm-shrinkwrap.json /app/\n')

                    # Generate npm install if there is a package.json.
                    if self.got_package_json:
                        out.write(
                            textwrap.dedent("""\
                COPY package.json /app/
                # You have to specify "--unsafe-perm" with npm install
                # when running as root.  Failing to do this can cause
                # install to appear to succeed even if a preinstall
                # script fails, and may have other adverse consequences
                # as well.
                RUN npm --unsafe-perm install
                """))

                    out.write('COPY . /app/\n')

                    if self.nodejs_version:
                        # Let node check to see if it satisfies the version constraint and
                        # try to install the correct version if not.
                        out.write(INSTALL_NODE_TEMPLATE %
                                  {'version_spec': self.nodejs_version})

                    # Generate the appropriate start command.
                    if self.got_npm_start:
                        out.write('CMD npm start\n')
                    else:
                        out.write('CMD node server.js\n')

            # Generate .dockerignore TODO(user): eventually this file will just be
            # copied verbatim.
            dockerignore = os.path.join(self.root, '.dockerignore')
            if not os.path.exists(dockerignore):
                notify('Saving [.dockerignore] to [%s].' % self.root)
                cleaner.Add(dockerignore)
                with open(dockerignore, 'w') as f:
                    f.write(DOCKERIGNORE)

                if self.params.deploy:
                    atexit.register(util.Clean, dockerignore)

        if not cleaner.HasFiles():
            notify('All config files already exist, not generating anything.')

        return cleaner