Пример #1
0
    def start(self, pull: bool, recreate: bool):
        """If not started, start the containers defined in config"""

        verb = self.context['VERBOSE']
        debug = self.context['DEBUG']

        try:
            docker_actions.check_cts_are_running(self.project_name)
            puts(colored.yellow('[INFO]') + ' stakkr is already started ...')
            sys.exit(0)
        except SystemError:
            pass

        if pull is True:
            command.launch_cmd_displays_output(
                self.compose_base_cmd + ['pull'], verb, debug, True)

        recreate_param = '--force-recreate' if recreate is True else '--no-recreate'
        cmd = self.compose_base_cmd + [
            'up', '-d', recreate_param, '--remove-orphans'
        ]
        command.verbose(self.context['VERBOSE'], 'Command: ' + ' '.join(cmd))
        command.launch_cmd_displays_output(cmd, verb, debug, True)

        self.running_cts, self.cts = docker_actions.get_running_containers(
            self.project_name)
        if self.running_cts is 0:
            raise SystemError(
                "Couldn't start the containers, run the start with '-v' and '-d'"
            )

        os_patch.start(self.project_name)
        self._run_iptables_rules()
        self._run_services_post_scripts()
Пример #2
0
    def start(self, pull: bool, recreate: bool):
        """If not started, start the containers defined in config"""

        verb = self.context['VERBOSE']
        debug = self.context['DEBUG']

        try:
            docker_actions.check_cts_are_running(self.project_name)
            puts(colored.yellow('[INFO]') + ' stakkr is already started ...')
            sys.exit(0)
        except SystemError:
            pass

        if pull is True:
            command.launch_cmd_displays_output(self.compose_base_cmd + ['pull'], verb, debug, True)

        recreate_param = '--force-recreate' if recreate is True else '--no-recreate'
        cmd = self.compose_base_cmd + ['up', '-d', recreate_param, '--remove-orphans']
        command.verbose(self.context['VERBOSE'], 'Command: ' + ' '.join(cmd))
        command.launch_cmd_displays_output(cmd, verb, debug, True)

        self.running_cts, self.cts = docker_actions.get_running_containers(self.project_name)
        if self.running_cts is 0:
            raise SystemError("Couldn't start the containers, run the start with '-v' and '-d'")

        os_patch.start(self.project_name)
        self._run_iptables_rules()
        self._run_services_post_scripts()
Пример #3
0
    def status(self):
        """Return a nice table with the list of started containers."""
        try:
            docker.check_cts_are_running(self.project_name)
        except SystemError:
            puts(colored.yellow('[INFO]') + ' stakkr is currently stopped')
            sys.exit(0)

        self._print_status_headers()
        self._print_status_body()
Пример #4
0
def sugarcli(ctx, run_args: tuple):
    run_args = ' '.join(run_args)

    stakkr = ctx.obj['STAKKR']
    docker_actions.check_cts_are_running(stakkr.project_name)

    if stakkr.cwd_abs.find(stakkr.stakkr_base_dir) != 0:
        raise Exception('You are not in a sub-directory of your stakkr instance')

    sugarcli_wrapper.run(docker_actions.get_ct_item('php', 'name'), stakkr.cwd_relative, run_args)
Пример #5
0
def composer(ctx, run_args: tuple):
    run_args = ' '.join(run_args)

    stakkr = ctx.obj['STAKKR']
    docker_actions.check_cts_are_running(stakkr.project_name)

    if stakkr.cwd_abs.find(stakkr.stakkr_base_dir) != 0:
        raise Exception('You are not in a sub-directory of your stakkr instance')

    run(stakkr, run_args)
Пример #6
0
def composer(ctx, run_args: tuple):
    run_args = ' '.join(run_args)

    stakkr = ctx.obj['STAKKR']
    docker_actions.check_cts_are_running(stakkr.project_name)

    if stakkr.cwd_abs.find(stakkr.stakkr_base_dir) != 0:
        raise Exception(
            'You are not in a sub-directory of your stakkr instance')

    run(stakkr, run_args)
Пример #7
0
    def console(self, container: str, user: str, tty: bool):
        """Enter a container (stakkr allows only apache / php and mysql)"""

        docker_actions.check_cts_are_running(self.project_name)

        tty = 't' if tty is True else ''
        ct_name = docker_actions.get_ct_name(container)
        cmd = ['docker', 'exec', '-u', user, '-i' + tty]
        cmd += [docker_actions.get_ct_name(container), docker_actions.guess_shell(ct_name)]
        subprocess.call(cmd)

        command.verbose(self.context['VERBOSE'], 'Command : "' + ' '.join(cmd) + '"')
Пример #8
0
    def console(self, container: str, user: str, tty: bool):
        """Enter a container. Stakkr will try to guess the right shell."""
        docker.check_cts_are_running(self.project_name)

        tty = 't' if tty is True else ''
        ct_name = docker.get_ct_name(container)
        cmd = ['docker', 'exec', '-u', user, '-i' + tty]
        cmd += [docker.get_ct_name(container), docker.guess_shell(ct_name)]
        subprocess.call(cmd)

        command.verbose(self.context['VERBOSE'],
                        'Command : "' + ' '.join(cmd) + '"')
Пример #9
0
    def stop(self):
        """If started, stop the containers defined in config. Else throw an error"""

        verb = self.context['VERBOSE']
        debug = self.context['DEBUG']

        docker_actions.check_cts_are_running(self.project_name)
        command.launch_cmd_displays_output(self.compose_base_cmd + ['stop'], verb, debug, True)
        os_patch.stop(self.project_name)

        self.running_cts, self.cts = docker_actions.get_running_containers(self.project_name)
        if self.running_cts is not 0:
            raise SystemError("Couldn't stop services ...")
Пример #10
0
    def console(self, container: str, user: str, tty: bool):
        """Enter a container. Stakkr will try to guess the right shell."""
        self.init_project()

        docker.check_cts_are_running(self.project_name)

        tty = 't' if tty is True else ''
        ct_name = docker.get_ct_name(container)
        cmd = ['docker', 'exec', '-u', user, '-i' + tty]
        cmd += [docker.get_ct_name(container), docker.guess_shell(ct_name)]
        subprocess.call(cmd)

        command.verbose(self.context['VERBOSE'], 'Command : "' + ' '.join(cmd) + '"')
Пример #11
0
    def status(self):
        """Returns a nice table with the list of started containers"""

        try:
            docker_actions.check_cts_are_running(self.project_name)
        except SystemError:
            puts(colored.yellow('[INFO]') + ' stakkr is currently stopped')
            sys.exit(0)

        dns_started = docker_actions.container_running('docker_dns')

        self._print_status_headers(dns_started)
        self._print_status_body(dns_started)
Пример #12
0
    def status(self):
        """Return a nice table with the list of started containers."""
        self.init_project()

        try:
            docker.check_cts_are_running(self.project_name)
        except SystemError:
            puts(colored.yellow('[INFO]') + ' stakkr is currently stopped')
            sys.exit(0)

        _, cts = docker.get_running_containers(self.project_name)

        _print_status_headers()
        _print_status_body(cts)
Пример #13
0
    def exec_cmd(self, container: str, user: str, args: tuple, tty: bool):
        """Run a command from outside to any container. Wrapped into /bin/sh"""

        docker_actions.check_cts_are_running(self.project_name)

        # Protect args to avoid strange behavior in exec
        args = ['"{}"'.format(arg) for arg in args]

        tty = 't' if tty is True else ''
        ct_name = docker_actions.get_ct_name(container)
        cmd = ['docker', 'exec', '-u', user, '-i' + tty, ct_name, 'sh', '-c']
        cmd += ["""test -d "/var/{0}" && cd "/var/{0}" ; exec {1}""".format(self.cwd_relative, ' '.join(args))]
        command.verbose(self.context['VERBOSE'], 'Command : "' + ' '.join(cmd) + '"')
        subprocess.call(cmd, stdin=sys.stdin)
Пример #14
0
    def exec_cmd(self, container: str, user: str, args: tuple, tty: bool):
        """Run a command from outside to any container. Wrapped into /bin/sh"""

        docker_actions.check_cts_are_running(self.project_name)

        # Protect args to avoid strange behavior in exec
        args = ['"{}"'.format(arg) for arg in args]

        tty = 't' if tty is True else ''
        ct_name = docker_actions.get_ct_name(container)
        cmd = ['docker', 'exec', '-u', user, '-i' + tty, ct_name, 'sh', '-c']
        cmd += ["""test -d "/var/{0}" && cd "/var/{0}" ; exec {1}""".format(self.cwd_relative, ' '.join(args))]
        command.verbose(self.context['VERBOSE'], 'Command : "' + ' '.join(cmd) + '"')
        subprocess.call(cmd, stdin=sys.stdin)
Пример #15
0
    def stop(self, container: str):
        """If started, stop the containers defined in config. Else throw an error"""

        verb = self.context['VERBOSE']
        debug = self.context['DEBUG']

        docker_actions.check_cts_are_running(self.project_name)

        cmd = self.compose_base_cmd + ['stop'] + self._get_single_container_option(container)
        command.launch_cmd_displays_output(cmd, verb, debug, True)

        self.running_cts, self.cts = docker_actions.get_running_containers(self.project_name)
        if self.running_cts is not 0 and container is None:
            raise SystemError("Couldn't stop services ...")
Пример #16
0
    def _is_up(self, container: str):
        try:
            docker.check_cts_are_running(self.project_name)
        except SystemError:
            return

        if container is None:
            puts(colored.yellow('[INFO]') + ' stakkr is already started ...')
            sys.exit(0)

        # If single container : check if that specific one is running
        ct_name = docker.get_ct_item(container, 'name')
        if docker.container_running(ct_name):
            puts(colored.yellow('[INFO]') + ' service {} is already started ...'.format(container))
            sys.exit(0)
Пример #17
0
    def _is_containers_running(self, container: str):

        try:
            docker_actions.check_cts_are_running(self.project_name)
        except SystemError:
            return

        if container is None:
            puts(colored.yellow('[INFO]') + ' stakkr is already started ...')
            sys.exit(0)

        # If single container : check if that specific one is running
        ct_name = docker_actions.get_ct_item(container, 'name')
        if docker_actions.container_running(ct_name):
            puts(colored.yellow('[INFO]') + ' service {} is already started ...'.format(container))
            sys.exit(0)
Пример #18
0
    def console(self, container: str, user: str, tty: bool):
        """Enter a container (stakkr allows only apache / php and mysql)"""

        docker_actions.check_cts_are_running(self.project_name)

        tty = 't' if tty is True else ''
        ct_name = docker_actions.get_ct_name(container)
        cmd = ['docker', 'exec', '-u', user, '-i' + tty]
        cmd += [
            docker_actions.get_ct_name(container),
            docker_actions.guess_shell(ct_name)
        ]
        subprocess.call(cmd)

        command.verbose(self.context['VERBOSE'],
                        'Command : "' + ' '.join(cmd) + '"')
Пример #19
0
    def stop(self, container: str, proxy: bool):
        """If started, stop the containers defined in config. Else throw an error."""
        self.init_project()
        verb = self.context['VERBOSE']
        debug = self.context['DEBUG']

        docker.check_cts_are_running(self.project_name)

        cmd = self._get_compose_base_cmd() + ['stop'] + _get_single_container_option(container)
        command.launch_cmd_displays_output(cmd, verb, debug, True)

        running_cts, _ = docker.get_running_containers(self.project_name)
        if running_cts and container is None:
            raise SystemError("Couldn't stop services ...")

        if proxy is True:
            Proxy().stop()
Пример #20
0
    def stop(self, container: str, proxy: bool):
        """If started, stop the containers defined in config. Else throw an error."""
        self.init_project()
        verb = self.context['VERBOSE']
        debug = self.context['DEBUG']

        docker.check_cts_are_running(self.project_name)

        cmd = self._get_compose_base_cmd() + [
            'stop'
        ] + _get_single_container_option(container)
        command.launch_cmd_displays_output(cmd, verb, debug, True)

        running_cts, _ = docker.get_running_containers(self.project_name)
        if running_cts and container is None:
            raise SystemError("Couldn't stop services ...")

        if proxy is True:
            Proxy().stop()
Пример #21
0
    def exec_cmd(self, container: str, user: str, args: tuple, tty: bool,
                 workdir: str):
        """Run a command from outside to any container. Wrapped into /bin/sh."""
        self.init_project()

        docker.check_cts_are_running(self.project_name)

        # Protect args to avoid strange behavior in exec
        args = ['"{}"'.format(arg) for arg in args]
        workdir = "/var/{}".format(
            self.cwd_relative) if workdir is None else workdir
        tty = 't' if tty is True else ''
        ct_name = docker.get_ct_name(container)
        cmd = [
            'docker', 'exec', '-u', user, '-i' + tty, '-w', workdir, ct_name,
            'sh', '-c'
        ]
        cmd += ["""exec {}""".format(' '.join(args))]
        command.verbose(self.context['VERBOSE'],
                        'Command : "' + ' '.join(cmd) + '"')
        subprocess.call(cmd, stdin=sys.stdin)