def create_build(self, service_dir, build_template, service_definition):
        language_ = build_template.get('language', 'python')
        args = ['init', language_]
        if language_ == 'python':
            args.append('--python')
            args.append('2.7')

        install_script = build_template.get('install', None)
        if install_script:
            args.append('--install')
            self._append_rendered_arguments(args, install_script,
                                            service_definition)

        script = build_template.get('script', None)
        if script:
            args.append('--script')
            self._append_rendered_arguments(args, script, service_definition)

        self._invoke_travis(args, exec_dir=service_dir)
        use_pypi = build_template.get('pypi-deploy', False)
        if use_pypi:
            self._write_deploy_stanza(service_dir)
            self._invoke_travis(
                ['encrypt', self.pypi_pass, '--add', 'deploy.password'],
                exec_dir=service_dir)
        invoke_process(['git', 'add', '.travis.yml'],
                       exec_dir=service_dir,
                       dry_run=self.dry_run)
        invoke_process([
            'git', 'commit', '-m',
            'Travis build file - generated by service-buddy'
        ],
                       exec_dir=service_dir,
                       dry_run=self.dry_run)
 def _invoke_travis(self, args, exec_dir=None, append_org=True):
     base_args = ['travis']
     base_args.extend(args)
     base_args.extend(self.default_args)
     if append_org: base_args.append('--org' if self.use_org else '--pro')
     if exec_dir:
         return invoke_process(args=base_args,
                               exec_dir=exec_dir,
                               dry_run=self.dry_run)
     else:
         return invoke_process(args=base_args, dry_run=self.dry_run)
Пример #3
0
 def init_repo(self, service_definition, service_dir):
     repo_url = self._get_default_vcs_provider().create_repo(
         service_definition)
     args = ['git', 'init']
     invoke_process(args, exec_dir=service_dir, dry_run=self.dry_run)
     args = ['git', 'add', '*', '**/*']
     invoke_process(args, exec_dir=service_dir, dry_run=self.dry_run)
     args = ['git', 'commit', '-m', 'Initial commit']
     invoke_process(args, exec_dir=service_dir, dry_run=self.dry_run)
     args = ['git', 'remote', 'add', 'origin', repo_url]
     invoke_process(args, exec_dir=service_dir, dry_run=self.dry_run)
     args = ['git', 'push', '-u', 'origin', 'master']
     invoke_process(args, exec_dir=service_dir, dry_run=self.dry_run)
     service_definition.set_git_url(repo_url)
Пример #4
0
 def clone_repository(service_defintion):
     # type: (Service) -> None
     app_dir = ensure_app_directory_exists(destination_directory,
                                           service_defintion)
     if service_defintion.repo_exists():
         clone_url = service_defintion.get_git_url()
         args = [
             'git', 'clone', clone_url,
             service_defintion.get_fully_qualified_service_name()
         ]
         service_directory = service_defintion.get_service_directory(
             app_dir=app_dir)
         if os.path.exists(service_directory):
             logging.warn(
                 "Skipping clone step directory exists - {}".format(
                     service_directory))
         else:
             invoke_process(args, app_dir, self.dry_run)
Пример #5
0
 def git_exec(service_defintion):
     # type: (Service) -> None
     destination_dir = ensure_service_directory_exists(
         destination_directory=destination_directory,
         service_defintion=service_defintion,
         create=False)
     if not destination_directory:
         logging.warn(
             "Service '{}' did not exist in destination directory - {}".
             format(
                 service_defintion.get_fully_qualified_service_name(),
                 destination_directory))
         logging.warn("Skipping running git command - git {}".format(
             str(args)))
         return
     logging.warn(
         "Invoking git in directory - '{}' ".format(destination_dir))
     git_args = ['git']
     git_args.extend(args)
     invoke_process(git_args, destination_dir, self.dry_run)
 def find_repo(self, service_definition):
     fq_repository_name = "{}/{}".format(
         self.team_root_user, service_definition.get_repository_name())
     # logging.info("bitbucket find_repo: %r", fq_repository_name)
     if self.client:
         bitbucket_url = self._find_repo_api(fq_repository_name)
     else:
         bitbucket_url = 'ssh://[email protected]/{}'.format(
             fq_repository_name)
         result = invoke_process(
             args=['git', 'ls-remote', bitbucket_url, '>', '/dev/null'],
             exec_dir=None,
             dry_run=self.dry_run)
         if result != 0:
             logging.info(
                 "Could not find repository with git executable - %r",
                 service_definition.get_repository_name())
             bitbucket_url = None
     return bitbucket_url
 def find_repo(self, service_definition):
     fq_repository_name = "{}/{}".format(self.repo_root, service_definition.get_repository_name())
     try:
         if self.client:
             ssh_url = None
             for repo in self.client.get_repos():
                 if repo.name == fq_repository_name:
                     ssh_url = repo.ssh_url
                     break
         else:
             ssh_url = 'ssh://[email protected]/{}'.format(fq_repository_name)
             result = invoke_process(args=['git', 'ls-remote', ssh_url, '>', '/dev/null'], exec_dir=None,
                                     dry_run=self.dry_run)
             if result != 0:
                 logging.info("Could not find repository with git executable - {}".format(
                     service_definition.get_repository_name()))
                 ssh_url = None
         return ssh_url
     except HTTPError:
         logging.info("Could not find repository through github API - {}".format(service_definition.get_repository_name()))
    def create_project(self, service_definition, app_dir):
        logging.info("Creating bamboo build")
        if service_definition.get_service_type() not in self.build_templates:
            raise Exception("Build template not found for service type {}".format(service_definition.get_service_type()))

        build_template = self.build_templates.get(service_definition.get_service_type())['type']
        args = [
            'java',
            '-Dbamboo.specs.log.level=DEBUG',
            '-jar',
            'bamboo-plan-1.0-SNAPSHOT.jar',
            '--build-template', build_template,
            '--bamboo-url', self.url,
            '--application', service_definition.get_app(),
            '--role', service_definition.get_role()
        ]

        res = invoke_process(args, dry_run=self.dry_run)
        if res > 0:
            raise Exception("Error creating bamboo build")
        else:
            logging.info("Done creating bamboo build")
Пример #9
0
 def test_invoke(self):
     return_code = command_util.invoke_process(
         ["echo", "foo", '>', '/dev/null'])
     self.assertEqual(return_code, 0, "Did not invoke trivial process")