예제 #1
0
def clone(context, instance, user=get_local_user(), branch=BRANCH):
    """
    Clone the project repository into a host instance.
    """
    local = False
    no_stack = None
    no_compose = False

    env_path = f"{HOST_PATH}/{instance}/.envs"
    env_file = f"{instance}.tar.gz"

    command = f"tar czvf .envs/{env_file} .envs/.{instance}"
    run_command(context, user, local, instance, no_stack, command, no_compose)

    with get_connection(user, HOST) as c:
        with c.cd(f"{HOST_PATH}"):
            c.run(f"mkdir -p {HOST_PATH}/{instance}")

    remote = True

    command = f"git clone {REPOSITORY} . && git checkout {branch}"
    run_command(context, user, remote, instance, no_stack, command, no_compose)

    with get_connection(user, HOST) as c:
        c.put(f".envs/{env_file}", env_path)

    command = f"tar zxvf {env_path}/{env_file} && rm {env_path}/{env_file}"
    run_command(context, user, remote, instance, no_stack, command, no_compose)

    command = f"mkdir -p {PROJECT}/media"
    run_command(context, user, remote, instance, no_stack, command, no_compose)
예제 #2
0
def compose(
    context, command, user=get_local_user(), remote=False, instance=None, stack=None
):
    """
    Run a raw compose command.
    """
    run_command(context, user, remote, instance, stack, command)
예제 #3
0
 def submits_connect_timeout(self, client):
     Connection('host', connect_timeout=27).open()
     client.connect.assert_called_with(
         username=get_local_user(),
         hostname='host',
         port=22,
         timeout=27,
     )
예제 #4
0
 def calls_SSHClient_connect(self, client):
     "calls paramiko.SSHClient.connect() with correct args"
     Connection('host').open()
     client.connect.assert_called_with(
         username=get_local_user(),
         hostname='host',
         port=22,
     )
예제 #5
0
 def calls_SSHClient_connect(self, client):
     "calls paramiko.SSHClient.connect() with correct args"
     Connection('host').open()
     client.connect.assert_called_with(
         username=get_local_user(),
         hostname='host',
         port=22,
     )
예제 #6
0
 def passes_through_connect_kwargs(self, client):
     Connection('host', connect_kwargs={'foobar': 'bizbaz'}).open()
     client.connect.assert_called_with(
         username=get_local_user(),
         hostname='host',
         port=22,
         foobar='bizbaz',
     )
예제 #7
0
파일: config.py 프로젝트: bossjones/fabric
 def has_various_Fabric_specific_default_keys(self):
     c = Config()
     assert c.port == 22
     assert c.user == get_local_user()
     assert c.forward_agent is False
     assert c.connect_kwargs == {}
     assert c.timeouts.connect is None
     assert c.ssh_config_path is None
예제 #8
0
 def connect_kwargs_protection_not_tripped_by_defaults(self, client):
     Connection('host', connect_kwargs={'timeout': 300}).open()
     client.connect.assert_called_with(
         username=get_local_user(),
         hostname='host',
         port=22,
         timeout=300,
     )
예제 #9
0
파일: config.py 프로젝트: omadjoudj/fabric
 def has_various_Fabric_specific_default_keys(self):
     c = Config()
     assert c.port == 22
     assert c.user == get_local_user()
     assert c.forward_agent is False
     assert c.connect_kwargs == {}
     assert c.timeouts.connect is None
     assert c.ssh_config_path is None
예제 #10
0
 def passes_through_connect_kwargs(self, client):
     Connection("host", connect_kwargs={"foobar": "bizbaz"}).open()
     client.connect.assert_called_with(
         username=get_local_user(),
         hostname="host",
         port=22,
         foobar="bizbaz",
     )
예제 #11
0
def django(
    context, command, user=get_local_user(), remote=False, instance=None, stack=None
):
    """
    Run a Django management command.
    """
    command = f"run --rm django python manage.py {command}"
    run_command(context, user, remote, instance, stack, command)
예제 #12
0
 def connect_kwargs_protection_not_tripped_by_defaults(self, client):
     Connection("host", connect_kwargs={"timeout": 300}).open()
     client.connect.assert_called_with(
         username=get_local_user(),
         hostname="host",
         port=22,
         timeout=300,
     )
예제 #13
0
 def passes_through_connect_kwargs(self, client):
     Connection('host', connect_kwargs={'foobar': 'bizbaz'}).open()
     client.connect.assert_called_with(
         username=get_local_user(),
         hostname='host',
         port=22,
         foobar='bizbaz',
     )
예제 #14
0
 def submits_connect_timeout(self, client):
     Connection('host', connect_timeout=27).open()
     client.connect.assert_called_with(
         username=get_local_user(),
         hostname='host',
         port=22,
         timeout=27,
     )
예제 #15
0
def hello(c, path='参数值'):
    init(autoreset=True)
    print('*' * 50)
    print(Fore.CYAN + '  Fabric 使用指南\n')
    print(Fore.GREEN + '  查看所有命令: fab -l')
    print(Fore.GREEN + '      查看命令: fab -d 命令')
    print(Fore.YELLOW + '    带参数命令: fab 命令 --参数 值\n')
    print(Fore.GREEN + '  Hello ~ ' + get_local_user())
    print('*' * 50)
예제 #16
0
 def ipv6_addresses_work_ok_but_avoid_port_shorthand(self):
     for addr in ("2001:DB8:0:0:0:0:0:1", "2001:DB8::1", "::1"):
         c = Connection(addr, port=123)
         assert c.user == get_local_user()
         assert c.host == addr
         assert c.port == 123
         c2 = Connection("somebody@{}".format(addr), port=123)
         assert c2.user == "somebody"
         assert c2.host == addr
         assert c2.port == 123
예제 #17
0
def backup(context,
           user=get_local_user(),
           remote=False,
           instance=None,
           stack=None):
    """
    Create a database backup.
    """
    command = "run --rm postgres backup"
    run_command(context, user, remote, instance, stack, command)
예제 #18
0
def requirements(context):
    """
    Run piptools pip-compile to update requirements.
    """
    pip_compile = "pip-compile --annotate --quiet"

    command = (f"{pip_compile} requirements/base.in "
               f"&& {pip_compile} requirements/local.in "
               f"&& {pip_compile} requirements/production.in")
    command = f"run --rm django bash -c '{command}'"
    run_command(context, get_local_user(), False, None, None, command)
예제 #19
0
def restore(
    context, backup, user=get_local_user(), remote=False, instance=None, stack=None,
):
    """
    Restore a database backup.
    """
    command = f"exec postgres pkill -f {PROJECT}"
    run_command(context, user, remote, instance, stack, command)

    command = f"run --rm postgres restore {backup}"
    run_command(context, user, remote, instance, stack, command)
예제 #20
0
def update(context, user=get_local_user(), remote=False, instance=None, branch=BRANCH):
    """
    Update the host instance from source control.
    """
    no_stack = None
    no_compose = False

    command = f"git checkout {branch} || git pull && git checkout {branch}"
    run_command(context, user, remote, instance, no_stack, command, no_compose)

    command = f"git pull"
    run_command(context, user, remote, instance, no_stack, command, no_compose)
예제 #21
0
def restart(
    context,
    user=get_local_user(),
    remote=False,
    instance=None,
    stack=None,
    services=None,
):
    """
    Restart one or more services.
    """
    command = f"restart"
    run_command_with_services(context, user, remote, instance, stack, command, services)
예제 #22
0
def shell(
    context,
    user=get_local_user(),
    remote=False,
    instance=None,
    stack=None,
    service="django",
):
    """
    Connect to a running service.
    """
    command = f"run --rm {service} bash"
    run_command(context, user, remote, instance, stack, command)
예제 #23
0
def stop(
    context,
    user=get_local_user(),
    remote=False,
    instance=None,
    stack=None,
    services=None,
):
    """
    Stop one or more services.
    """
    command = f"stop"
    run_command_with_services(context, user, remote, instance, stack, command, services)
예제 #24
0
 def ipv6_addresses_work_ok_but_avoid_port_shorthand(self):
     for addr in (
         '2001:DB8:0:0:0:0:0:1',
         '2001:DB8::1',
         '::1',
     ):
         c = Connection(addr, port=123)
         assert c.user == get_local_user()
         assert c.host == addr
         assert c.port == 123
         c2 = Connection("somebody@{}".format(addr), port=123)
         assert c2.user == "somebody"
         assert c2.host == addr
         assert c2.port == 123
예제 #25
0
def deploy(
    context, instance, user=get_local_user(), initial=False, stack=None, branch=BRANCH,
):
    """
    Deploy the project. By default it creates a database backup before updating from
    source control and rebuilding the docker stack.
    """
    remote = True

    if initial:
        clone(context, instance, user, branch)
    else:
        backup(context, user, remote, instance, stack)

    update(context, user, remote, instance, branch)
    up(context, user, remote, instance, stack)
예제 #26
0
def up(
    context,
    user=get_local_user(),
    remote=False,
    instance=None,
    stack=None,
    services=None,
):
    """
    Build the stack for the host instance.
    """
    command = f"up --build"

    if remote:
        command = f"{command} --detach"

    run_command_with_services(context, user, remote, instance, stack, command, services)
예제 #27
0
def test(
    context,
    user=get_local_user(),
    remote=False,
    instance=None,
    stack=None,
    app=None,
    coverage=False,
):
    """
    Run tests with pytest.
    """
    command = "pytest"

    if app:
        command = f"{command} {app}"

    if coverage:
        command = f"coverage run -m {command}"

    command = f"run --rm django {command}"
    run_command(context, user, remote, instance, stack, command)
예제 #28
0
def down(
    context,
    user=get_local_user(),
    remote=False,
    instance=None,
    stack=None,
    images="all",
    volumes=True,
    orphans=False,
):
    """
    Stop and remove stack components.
    """
    command = f"down --rmi {images}"

    if volumes:
        command = f"{command} --volumes"

    if orphans:
        command = f"{command} --remove-orphans"

    run_command(context, user, remote, instance, stack, command)
예제 #29
0
 def defaults_to_local_user_with_no_config(self):
     # Tautology-tastic!
     assert Connection('host').user == get_local_user()
예제 #30
0
 def KeyError_means_SaaS_and_thus_None(self, getuser):
     assert get_local_user() is None
예제 #31
0
 def defaults_to_local_user_with_no_config(self):
     # Tautology-tastic!
     assert Connection("host").user == get_local_user()
예제 #32
0
 def defaults_to_getpass_getuser(self, getuser):
     "defaults to getpass.getuser"
     get_local_user()
     getuser.assert_called_once_with()
예제 #33
0
"""General program configurations"""

from fabric.util import get_local_user
from rich.theme import Theme

_PROG = 'vem'
_VERSION = '0.5.0-dev'

_DEFAULT_SSH_PORT = 22
_DEFAULT_SSH_USER = get_local_user()

# custom 'rich' theme to use for rich output formatting.
rich_theme = Theme(
    {
        'h1': 'bold red',
        'h2': 'cyan',
        'info': 'cyan',
        'keyword': 'bold bright_white',
        'var': 'cornflower_blue',
        'example': 'italic grey58',
        'path': 'grey58',
        'error': 'red',
        'warning': 'gold3',
        'todo': 'bold bright_magenta on purple4',
    },
    inherit=True)