......@@ -2,6 +2,7 @@ from .deploy import *
import drush
import behat
import docker
import core
from .environments import e
from fabric.api import lcd, cd, task, roles, env, local, run, runs_once, execute
......
from __future__ import unicode_literals
from fabric.api import lcd, cd, task, roles, env, local, run, runs_once, execute
from fabric.contrib.console import confirm
from fabric.colors import red, green
import helpers as h
import os.path
@task
@roles('local')
def db_import(filename, role='local'):
"""Import and restore the specified database dump.
$ fab core.db_import:/tmp/db_dump.sql.gz
:param filename: a full path to a gzipped sql dump.
"""
if os.path.isfile(filename):
print green('Database dump {} found.'.format(filename))
with h.fab_cd(role, env.site_root):
h.fab_run(role, 'zcat {} | mysql -u{} -p{} -h{} {}'.format(filename, env.site_db_user, env.site_db_pass, env.container_ip, env.site_db_name))
print(green('Database dump successfully restored.'))
else:
print red('Could not find database dump at {}'.format(filename))
......@@ -35,7 +35,9 @@ env.docker_workspace = '/opt/sfl'
env.docker_site_root = '{}/src/drupal'.format(env.docker_workspace)
env.bind_port = 8001
env.apache_user = 'www-data'
env.container_ip = '172.0.0.0'
# Docker auto-added container IP
env.container_ip = '172.17.0.0'
# Hook commands
......
......@@ -141,17 +141,16 @@ def container_start(role='local'):
'-d -p {}:80'.format(env.bind_port),
mounts=[(env.workspace, env.docker_workspace, True)]):
# If container was successful build, get the IP address and show it to the user.
global CONTAINER_IP
CONTAINER_IP = h.fab_run(role, 'docker inspect -f "{{{{.NetworkSettings.IPAddress}}}}" '
env.container_ip = h.fab_run(role, 'docker inspect -f "{{{{.NetworkSettings.IPAddress}}}}" '
'{}_container'.format(env.project_name), capture=True)
if env.interactive_mode:
h.fab_update_hosts(CONTAINER_IP, env.site_hostname)
h.fab_update_hosts(env.container_ip, env.site_hostname)
print(green('Docker container {}_container was build successful. '
'To visit the Website open a web browser in http://{} or '
'http://localhost:{}.'.format(env.project_name, env.site_hostname, env.bind_port)))
h.fab_update_container_ip()
h.fab_update_container_ip(env.container_ip)
else:
print(red('Docker image {}/drupal not found and is a requirement to run the {}_container.'
......
......@@ -130,8 +130,8 @@ def site_install():
@task
@roles('local')
def archive_dump(role='local'):
@roles('docker')
def archive_dump(role='docker'):
"""
Archive the platform for release or deployment.
:param role Default 'role' where to run the task
......@@ -163,3 +163,4 @@ def gen_doc(role='local'):
h.fab_run(role, 'asciidoctor -b html5 -o {}/CHANGELOG.html {}/CHANGELOG.adoc'.format(env.workspace, env.workspace))
print(green('CHANGELOG.html generated in {}'.format(env.workspace)))
......@@ -123,13 +123,10 @@ def fab_remove_from_hosts(site_hostname):
local('sudo sed -i "/{}/d" /etc/hosts'.format(site_hostname))
def fab_update_container_ip():
container_ip = fab_run('local', 'docker inspect -f "{{{{.NetworkSettings.IPAddress}}}}" '
'{}_container'.format(env.project_name), capture=True)
def fab_update_container_ip(container_ip):
local('sed -i "/env.container_ip/d" {}/local_vars.py'.format(os.path.dirname(os.path.abspath(__file__))))
local('sed -i "/# Docker auto-added container IP/a env.container_ip = \'{}\'" {}/local_vars.py'.format(''.join(container_ip), os.path.dirname(os.path.abspath(__file__))))
local('sed -i "/# Docker auto-added container IP/a env.container_ip = \'{}\'" '
'{}/local_vars.py'.format(''.join(container_ip), os.path.dirname(os.path.abspath(__file__))))
def fab_update_hosts(ip, site_hostname):
......