Beispiel #1
0
    def docker_create(self, img):
        env_vars = self.action.get('env', {})

        for s in self.action.get('secrets', []):
            env_vars.update({s: os.environ[s]})

        for e, v in self.env.items():
            env_vars.update({e: v})

        env_vars.update({'HOME': os.environ['HOME']})

        env_flags = [" -e {}='{}'".format(k, v) for k, v in env_vars.items()]

        docker_cmd = 'docker create '
        docker_cmd += ' --name={}'.format(self.cid)
        docker_cmd += ' --volume {0}:{0}'.format(self.workspace)
        docker_cmd += ' --volume {0}:{0}'.format(os.environ['HOME'])
        docker_cmd += ' --volume {0}:{0}'.format('/var/run/docker.sock')
        docker_cmd += ' --workdir={} '.format(self.workspace)
        docker_cmd += ''.join(env_flags)
        if self.action.get('runs', None):
            docker_cmd += ' --entrypoint={} '.format(self.action['runs'])
        docker_cmd += ' {}'.format(img)
        docker_cmd += ' {}'.format(' '.join(self.action.get('args', '')))

        pu.info('{}[{}] docker create {} {}\n'.format(
            self.msg_prefix, self.action['name'], img,
            ' '.join(self.action.get('args', ''))))

        pu.exec_cmd(docker_cmd, debug=self.debug, dry_run=self.dry_run)
Beispiel #2
0
def cli(ctx):
    """Resets a popper repository completely, removing all existing
    pipelines and folders, leaving behind a newly created .popper.yml file.

    Note: It only removes those files inside a pipeline folder that are also
    tracked by git. Untracked files will not be deleted.
    """
    msg = (
        "This will remove all the pipeline files in this "
        " project, do you want to continue?"
    )
    if(not click.confirm(msg, abort=False)):
        sys.exit(0)

    project_root = pu.get_project_root()

    if project_root != os.getcwd():
        msg = 'This command can only be executed from the project root folder'
        pu.fail(msg)

    config = pu.read_config()

    for _, p in config['pipelines'].items():
        pu.exec_cmd('git rm -r {}'.format(p['path']))
    pu.write_config(pu.init_config)
    content = pt.ReadMe()
    content.init_project()
    pu.info("Reset complete", fg="cyan")
Beispiel #3
0
    def run(self, action_name=None):
        """Run the pipeline or a specific action"""
        pu.exec_cmd('rm -rf {}/*'.format(self.workspace))
        os.environ['WORKSPACE'] = self.workspace

        self.instantiate_runners()

        if action_name:
            self.wf['action'][action_name]['runner'].run()
        else:
            for s in self.get_stages():
                self.run_stage(s)
Beispiel #4
0
    def run(self, reuse=False):
        cmd = self.action.get('runs', ['entrypoint.sh'])
        cmd[0] = os.path.join('./', cmd[0])
        cmd.extend(self.action.get('args', ''))

        cwd = os.getcwd()
        if not self.dry_run:
            if 'repo_dir' in self.action:
                os.chdir(self.action['repo_dir'])
            else:
                os.chdir(os.path.join(cwd, self.action['uses']))

        os.environ.update(self.action.get('env', {}))

        pu.info('{}[{}] {}\n'.format(self.msg_prefix, self.action['name'],
                                     ' '.join(cmd)))

        _, ecode = pu.exec_cmd(' '.join(cmd),
                               verbose=(not self.quiet),
                               debug=self.debug,
                               ignore_error=True,
                               log_file=self.log_filename,
                               dry_run=self.dry_run)

        for i in self.action.get('env', {}):
            os.environ.pop(i)

        os.chdir(cwd)

        if ecode != 0:
            pu.fail("\n\nAction '{}' failed.\n.".format(self.action['name']))
Beispiel #5
0
    def docker_exists(self):
        cmd_out, _ = pu.exec_cmd('docker ps -a',
                                 debug=self.debug, dry_run=self.dry_run)

        if self.cid in cmd_out:
            return True

        return False
Beispiel #6
0
    def docker_start(self):
        pu.info('{}[{}] docker start \n'.format(self.msg_prefix,
                                                self.action['name']))

        cmd = 'docker start --attach {}'.format(self.cid)
        _, ecode = pu.exec_cmd(
            cmd, verbose=(not self.quiet), debug=self.debug,
            log_file=self.log_filename, dry_run=self.dry_run)
        return ecode
Beispiel #7
0
def clone(org, repo, repo_parent_dir, version=None):
    """Clones a repository using Git. The URL for the repo is
    https://github.com/ by default. To override this, other URLs can be given
    by defining them in the 'action_urls' list specified in the .popper.yml
    file.
    """
    repo_dir = os.path.join(repo_parent_dir, repo)
    if os.path.exists(repo_dir):
        pu.exec_cmd('rm -rf {}'.format(repo_dir))

    cmd = 'git -C {} clone --depth=1 {}{}/{} &> /dev/null'.format(
        repo_parent_dir, get_repo_url(), org, repo)

    pu.exec_cmd(cmd)

    if version:
        pu.exec_cmd('git checkout {} &> /dev/null'.format(version))
Beispiel #8
0
 def docker_build(self, tag, path):
     cmd = 'docker build -t {} {}'.format(tag, path)
     pu.info('[{}] {}\n'.format(self.action['name'], cmd))
     pu.exec_cmd(cmd)
Beispiel #9
0
 def docker_pull(self, img):
     pu.info('[{}] docker pull {}\n'.format(self.action['name'], img))
     pu.exec_cmd('docker pull {}'.format(img))
Beispiel #10
0
 def docker_build(self, tag, path):
     cmd = 'docker build -t {} {}'.format(tag, path)
     pu.info('{}[{}] {}\n'.format(self.msg_prefix, self.action['name'],
                                  cmd))
     pu.exec_cmd(cmd, debug=self.debug, dry_run=self.dry_run)
Beispiel #11
0
 def docker_pull(self, img):
     pu.info('{}[{}] docker pull {}\n'.format(self.msg_prefix,
                                              self.action['name'], img))
     pu.exec_cmd('docker pull {}'.format(img),
                 debug=self.debug,
                 dry_run=self.dry_run)
Beispiel #12
0
 def docker_rm(self):
     pu.exec_cmd('docker rm {}'.format(self.cid),
                 debug=self.debug,
                 dry_run=self.dry_run)