Пример #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)
Пример #2
0
    def run_command(self, name, *args):
        commands = self['commands']
        commands < self.mounting['commands']

        if name in commands:
            command = commands[name]
            logger.cmd('Run custom command <b>%s</b>' % (command.name, ))
            for line in command.commands:
                if line == name:
                    logger.error('Comand loop error: <b>%s</b>' % (line, ))
                else:
                    # TODO: Improve with @mounting detection and Split by | and < or >
                    if self.root.current_mounting and line.split(
                    )[-1][0] != '@':
                        local_args = tuple(args) + (
                            '@%s' % self.root.current_mounting, )
                    else:
                        local_args = tuple(args)

                    for name, value in self.compose.environment:
                        line = line.replace('${%s}' % (name), value)

                    logger.cmd('Run %s %s' % (line, " ".join(local_args)))
                    cmd_args = tuple(line.split()) + local_args

                    cmd = self.root.bash('docker-emperor',
                                         *cmd_args,
                                         compose=self.compose,
                                         is_system=True)
                    if not cmd.is_success:
                        break
            return True
        return False
Пример #3
0
def run(root, *args, **kwargs):

    root.run_command('machine:start', internal=True)

    mounting = root.mounting
    hosts = mounting.get_machine_hosts()
    if hosts:
        
        for host in hosts:

            ip_address = '0.0.0.0'
            logger.cmd('Set host <b>%s</b> mapped at %s in /etc/hosts.' % (host, ip_address))
            cmd = root.bash(
                "docker", 
                "run", 
                "-t", 
                "-i" ,
                "-v", "%s/managehosts:/bin/managehosts" % root.bin_root,
                "-v", "/etc/hosts:/etc/host_hosts",
                "-v", "/etc/hosts.bak:/etc/host_hosts.bak",
                "busybox",
                "sh", 
                "/bin/managehosts" ,
                "add %s %s %s" % (host, ip_address, root.project.name),
                mounting=mounting,
                is_system=True
            )

            if cmd.is_success:
                logger.success('Host <b>%s</b> has been set on %s.' % (host, mounting, ))
Пример #4
0
def run(root, *args, **kwargs):

    logger.cmd('Command aliases for <b>%s</b> : \r' %
               root.project.compose.name)
    for aliase in root.project['aliases']:
        logger.choice(' <b>%s</b>%s%s' % (aliase.name, ' ' *
                                          (20 - len(aliase.name)), aliase))
Пример #5
0
def run(root, *args, **kwargs):

    if not root.mounting.is_running:
        if root.mounting.is_startable:
            logger.cmd('Start mounting <b>%s</b>' % (root.mounting.name, ))
            cmd = root.bash(root.mounting.docker_machine_bin,
                            'start',
                            root.mounting.name,
                            *args,
                            sys=True)
            if root.mounting.is_running:
                root.logger.success('Machine <b>%s</b> started.' %
                                    (root.mounting.name, ))
        else:
            root.logger.warning('Machine <b>%s</b> is not startable.' %
                                (root.mounting.name, ))

    return root.mounting.is_running


# class Command():

#     def run(self, *args, **kwargs):
#         if not self.interna
#         self.success('Machine <b>%s</b> started.' % (root.mounting.name, ))
Пример #6
0
def run(root, *args, **kwargs):

    logger.cmd('Down project <b>%s</b>' % (root.compose.name, ))
    cmd = root.bash(root.compose.bin,
                    'down',
                    '--remove-orphans',
                    compose=root.compose,
                    is_system=True)
    if cmd.is_success:
        logger.success('<b>%s</b> is down.' % (root.compose.name, ))
Пример #7
0
def run(root, *args, **kwargs):
    logger.cmd('Run project <b>%s</b>' % (root.compose.name, ))
    root.run_command('machine:start', internal=True)
    cmd = root.bash(root.compose.bin,
                    'run',
                    *args,
                    compose=root.compose,
                    is_system=True)
    if cmd.is_success:
        logger.success('<b>%s</b> is started.' % (root.compose.name, ))
Пример #8
0
def run(root, *args, **kwargs):

    logger.cmd('Rebuild <b>%s</b>' % (root.project.compose.name, ))
    root.project.machine.start()
    cmd = root.bash(root.project.compose.bin,
                    '--no-cache',
                    'build',
                    *args,
                    compose=root.compose,
                    is_system=True)
    if cmd.is_success:
        logger.success('<b>%s</b> rebuilt.' % (root.project.compose.name, ))
Пример #9
0
def run(root, *args, **kwargs):

    root.run_command('machine:start', internal=True)

    if '--set-hosts' in args:
        root.run_command('hosts:set', internal=True)
        args = filter(lambda s: s != '--set-hosts', args)
    else:
        logger.cmd('Hosts mapping ignored.')

    logger.cmd('Up project <b>%s</b>' % (root.compose.name, ))
    cmd = root.bash(root.compose.bin,
                    'up',
                    *args,
                    compose=root.compose,
                    is_system=True)
    if cmd.is_success:
        logger.success('<b>%s</b> is up.' % (root.compose.name, ))

    if root.mounting['hosts']:
        for host in root.mounting['hosts']:
            logger.success('Project is accessible by http://%s.' % (host, ))
Пример #10
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)
Пример #11
0
def run(root, *args, **kwargs):

    logger.cmd('Active mounting <b>%s</b>' % (root.project.compose.name, ))
Пример #12
0
def run(root, *args, **kwargs):
    logger.cmd('Run project <b>%s</b>' % (root.compose.name, ))
    root.run_command('machine:start', internal=True)
    root.run_command('down', internal=True)
    root.run_command('up', *args, internal=True)
Пример #13
0
def run(root, *args, **kwargs):

    logger.cmd('Removing all docker containers..')
    root.bash('docker rm $(docker ps -a -q) -f',
              compose=root.compose,
              is_system=True)