Ejemplo n.º 1
0
def test_host_ip(m_getenv):
    m_getenv.side_effect = [
        '192.168.0.100 54321 192.168.0.69 22',
        '',
    ]
    assert utils.host_ip() == '192.168.0.69'
    assert utils.host_ip() == '127.0.0.1'
Ejemplo n.º 2
0
def editor(ctx, port):
    """Run web-based docker-compose.yml editor.

    This will start a new docker container listening on a host port (default: 8300).
    Navigate there in your browser to access the GUI for editing docker-compose.yml.

    When you're done editing, save your file in the GUI, and press Ctrl+C in the terminal.
    """
    utils.check_config()
    utils.confirm_mode()

    orig = utils.read_file('docker-compose.yml')

    sudo = utils.optsudo()
    host_ip = utils.host_ip()
    editor = 'brewblox/brewblox-web-editor:{}'.format(utils.docker_tag())

    utils.info('Pulling image...')
    sh('{}docker pull {}'.format(sudo, editor))

    try:
        utils.info('Starting editor...')
        sh('{}docker run'.format(sudo) + ' --rm --init' +
           ' -p "{}:8300"'.format(port) + ' -v "$(pwd):/app/config"' +
           ' {}'.format(editor) + ' --host-address {}'.format(host_ip) +
           ' --host-port {}'.format(port))
    except KeyboardInterrupt:  # pragma: no cover
        pass

    if orig != utils.read_file('docker-compose.yml'):
        utils.info('Configuration changes detected.')
        restart_services(ctx)
Ejemplo n.º 3
0
def add_node_red(force):
    """
    Create a service for Node-RED.
    """
    utils.check_config()
    utils.confirm_mode()

    name = 'node-red'
    sudo = utils.optsudo()
    host = utils.host_ip()
    port = utils.getenv(const.HTTPS_PORT_KEY)
    config = utils.read_compose()

    if not force:
        check_duplicate(config, name)

    config['services'][name] = {
        'image': 'brewblox/node-red:${BREWBLOX_RELEASE}',
        'restart': 'unless-stopped',
        'volumes': [
            f'./{name}:/data',
        ]
    }

    sh(f'mkdir -p ./{name}')
    if [getgid(), getuid()] != [1000, 1000]:
        sh(f'sudo chown -R 1000:1000 ./{name}')

    utils.write_compose(config)
    click.echo(f'Added Node-RED service `{name}`.')
    if utils.confirm('Do you want to run `brewblox-ctl up` now?'):
        sh(f'{sudo}docker-compose up -d')
        click.echo(
            f'Visit https://{host}:{port}/{name} in your browser to load the editor.'
        )
Ejemplo n.º 4
0
def add_node_red():
    """
    Create a service for Node-RED.
    """
    utils.check_config()
    utils.confirm_mode()

    name = 'node-red'
    sudo = utils.optsudo()
    host = utils.host_ip()
    port = utils.getenv(const.HTTPS_PORT_KEY)
    config = utils.read_compose()

    if name in config['services']:
        click.echo('The {} service already exists'.format(name))
        raise SystemExit(1)

    config['services'][name] = {
        'image': 'brewblox/node-red:${BREWBLOX_RELEASE}',
        'restart': 'unless-stopped',
        'volumes': [
            './{}:/data'.format(name),
        ]
    }

    sh('mkdir -p ./{}'.format(name))
    if [getgid(), getuid()] != [1000, 1000]:
        sh('sudo chown 1000:1000 ./{}'.format(name))

    utils.write_compose(config)
    click.echo("Added Node-RED service '{}'.".format(name))
    if utils.confirm("Do you want to run 'brewblox-ctl up' now?"):
        sh('{}docker-compose up -d --remove-orphans'.format(sudo))
        click.echo(
            'Visit https://{}:{}/{} in your browser to load the editor.'.
            format(host, port, name))