Example #1
0
def setup_docs_web_proxy():
    """Set up a mod proxy based vhost to forward web traffic to internal host.

    If container_id is none, it will also install docker and set up the
    entire documentation web site inside that docker container.

    """

    require.directory(work_dir)
    with cd(work_dir):
        run('echo "fabgis" > requirements.txt')
        setup_venv(work_dir)

        container_id_file = 'fabgis.container.id'
        if not exists(container_id_file):
            setup_docker()

        setup_remotely()
        container_id = current_docker_container()

        port_mappings = get_docker_port_mappings(container_id)

        http_port = port_mappings[80]

        fabtools.require.deb.package('apache2')
        sudo('a2enmod proxy proxy_http')

        context = {
            'internal_host': env.host,
            'internal_port': http_port,
            'server_name': 'inasafe.org'
        }

        apache_conf_template = 'inasafe.org.mod_proxy.conf.templ'
        apache_path = '/etc/apache2/sites-available'

        # Clone and replace tokens in apache conf

        local_dir = os.path.dirname(__file__)
        local_file = os.path.abspath(os.path.join(
            local_dir,
            'scripts',
            apache_conf_template))

        fastprint(green('Using %s for template' % local_file))

        destination = '%s/inasafe.org.conf' % apache_path

        upload_template(
            local_file,
            destination,
            context=context,
            use_sudo=True)

        require.apache.enable('inasafe.org')
        restart('apache2')
Example #2
0
def setup_remotely():
    """Set up the container on a remote server - uses nested fabgis calls.

    Use this task when you want to set up the container on a remote server.
    It will log in to the server and then run fabric in a shell session so
    that all requests appear to originate locally. This is a work around for
    current inability to tunnel cleanly into the docker container from
    outside the docker's host.

    """
    with cd(work_dir):
        run('echo "fabgis" > requirements.txt')
        setup_venv(work_dir)

        container_id = current_docker_container()

        if container_id is None:
            container_id = create_docker_container(image='fabgis/sshd')

        port_mappings = get_docker_port_mappings(container_id)
        ssh_port = port_mappings[22]

        run('wget -O fabfile.py https://github.com/AIFDR/inasafe-doc'
            '/raw/master/fabfile.py')
        require.directory('scripts')

        run(
            'wget -O scripts/inasafe-doc.conf.templ https://github'
            '.com/AIFDR/inasafe-doc/raw/master/scripts/inasafe-doc.conf.templ')
        run(
            'wget -O scripts/inasafe.org.mod_proxy.conf.templ https://github'
            '.com/AIFDR/inasafe-doc/raw/master/scripts/inasafe.org.mod_proxy.'
            'conf.templ')

        run('venv/bin/fab -H [email protected]%s:%i setup_web_user' % (
            env.host, ssh_port))
        run('venv/bin/fab -H [email protected]%s:%i setup_docs_web_site' % (
            env.host, ssh_port))