Beispiel #1
0
def run(root, *args, **kwargs):

    name = args[0].strip() if args else None
    if name:
        args = list(args)
        args.pop(0)
        mounting = root.project['mounting'].get(name)
        if mounting:
            logger.success(u'Prepare mounting <b>%s</b> to be created.' %
                           mounting.name)
        else:
            logger.error(u'Mounting <b>%s</b> unknow.' % name)
            exit(1)
    else:
        mounting = root.mounting

    if not mounting.is_localhost:

        logger.cmd('Create machine <b>%s</b>' %
                   (mounting.docker_machine_name, ))
        logger.cmd('With driver <b>%s</b>' % (mounting.get_machine_driver(), ))
        cmd = root.bash(
            mounting.docker_machine_bin,
            'rm',
            mounting.docker_machine_name,  #root.compose.name,
            *args,
            is_system=True)
    else:
        logger.warning(mounting.LOCAL_MACHINE_WARNING)
Beispiel #2
0
def run(root, *args, **kwargs):

    mounting = root.mounting
    if mounting.is_localhost:
        logger.warning(mounting.LOCAL_MACHINE_WARNING)
    else:
        cmd = root.bash(mounting.docker_machine_bin,
                        'ssh',
                        mounting.docker_machine_name,
                        *args,
                        is_system=True)
        if cmd.is_success:
            logger.success('')
Beispiel #3
0
def run(root, *args, **kwargs):

    project = None

    project_name = args[0] if len(args) else None
    if project_name:
        project = root.projects.get(project_name)
        if not project:
            logger.warning('Project <b>%s</b> unknow.' % project_name)

    if not project:

        def select_project():
            # logger.ask('0) no machine (localhost)')
            logger.ask('Select the project to work on')
            for i, p in enumerate(root.projects.items()):
                key, value = p
                logger.choice('<b>{}]</b> {}'.format(i + 1, key))
            pi = six.moves.input(': ')
            try:
                if pi == '0':
                    raise Exception
                return root.projects.items()[int(pi) - 1]
            except Exception as e:
                logger.error('{} is not a valid choice'.format(pi))
                return select_project()

        project_name, project = select_project()

    if project:
        workdir = project.get('workdir')
        if workdir and os.path.isdir(workdir):
            logger.success('Workon the project <b>%s</b> in <b>%s</b>' %
                           (project_name, workdir))
            os.chdir(workdir)
            shell = os.environ.get('SHELL', '/bin/sh')
            # root.run_command('info', internal=True)
            os.execl(shell, shell)
            return
Beispiel #4
0
def run(root, *args, **kwargs):

    name = args[0].strip() if args else None
    if name:
        if name in root.project['contexts']:
            root.project.config['context'] = name
            logger.success(u'Context <b>%s</b> selected.' % root.context.name)
        else:
            logger.error(u'Context <b>%s</b> unknow.' % name)
            exit(0)

    else:
        contexts = root.project['contexts']
        if not contexts:
            contexts['default'] = Context('default')
            root.project.config['context'] = 'default'
            logger.warning(u'No context defines, use <b>%s</b>.' %
                           root.context.name)
        else:

            def select_context_name(contexts):
                logger.ask(
                    u'Please select the <b>{}</b> context to work on'.format(
                        root.project.name))
                for i, c in enumerate(contexts):
                    logger.choice(u'<b>%s</b>] %s' % (i + 1, c.name))
                ci = six.moves.input(': ')
                try:
                    if ci == '0':
                        raise Exception
                    return contexts[int(ci) - 1].name
                except Exception as e:
                    logger.error(u'<b>%s/b> is not a valid choice' % ci)
                    return select_context_name(contexts)

            root.project.config['context'] = select_context_name(contexts)
            logger.success(u'Context <b>%s</b> selected.' % root.context.name)
Beispiel #5
0
def run(root, *args, **kwargs):

    logger.cmd('Sync files for project <b>%s</b>' % (root.compose.name, ))
    root.run_command('machine:start', internal=True)
    if not root.mounting.is_localhost:

        # ex. docker-machine scp -r -d . virtualbox:/home/docker/project.dev.localhost/
        for file in root.mounting['files']:

            cmd = root.bash(
                root.mounting.docker_machine_bin,
                'scp',
                '--quiet',
                '-r',
                '-d',
                file,
                '{}:{}'.format(
                    root.mounting.docker_machine_name,  #root.compose.name, 
                    root.mounting['workdir']),
                is_system=True,
            )
            print(cmd.cmd_line)
    else:
        logger.warning(root.mounting.LOCAL_MACHINE_WARNING)
Beispiel #6
0
def run(root, *args, **kwargs):

    status = Command(root.machine.bin, 'status', root.machine.name).out

    logger.warning(status)