Commit db82bd22 authored by Ernesto Rodriguez Ortiz's avatar Ernesto Rodriguez Ortiz
Browse files

Cleaning and reordering the fabric tasks

parent 93a80cca
......@@ -133,21 +133,6 @@ def fab_remove_from_hosts(site_hostname):
local('sudo sed -i "/{}/d" /etc/hosts'.format(site_hostname))
@task(alias='dkuh')
@roles('docker')
def docker_update_host():
"""
Helper function to update the ip and hostname in docker container
# Fix complains of sendmail about "unable to qualify my own domain name"
:return:
"""
# Get the ip of the container, this
ip = local('docker inspect -f "{{{{.NetworkSettings.IPAddress}}}}" {}_container'.format(PROJECT_NAME), capture=True)
site_hostname = run("hostname")
run("sed '/{}/c\{} {} localhost.domainlocal' /etc/hosts > /root/hosts.backup".format(ip, ip, site_hostname))
run("cat /root/hosts.backup > /etc/hosts")
def fab_update_hosts(ip, site_hostname):
"""
Helper function to update the file /etc/hosts
......@@ -374,6 +359,21 @@ def docker_ssh(role='local', path_key='~/.ssh/id_rsa'):
fab_run(role, 'ssh -i {} root@{}'.format(path_key, ip))
@task(alias='dkuh')
@roles('docker')
def docker_update_host():
"""
Helper function to update the ip and hostname in docker container
# Fix complains of sendmail about "unable to qualify my own domain name"
:return:
"""
# Get the ip of the container, this
ip = local('docker inspect -f "{{{{.NetworkSettings.IPAddress}}}}" {}_container'.format(PROJECT_NAME), capture=True)
site_hostname = run("hostname")
run("sed '/{}/c\{} {} localhost.domainlocal' /etc/hosts > /root/hosts.backup".format(ip, ip, site_hostname))
run("cat /root/hosts.backup > /etc/hosts")
@task(alias='cp_keys')
@roles('local')
def copy_ssh_keys(role='local', ):
......@@ -475,48 +475,22 @@ def drush_make(role='local', action='install'):
print green('Drush make finished!')
@task(alias='csy')
@roles('docker')
def create_symlinks(role='docker'):
"""
Create symlinks for the site
"""
set_env(role)
fab_run(role, 'rm -rf {}'.format(DRUPAL_ROOT))
fab_run(role, 'ln -s {}/src/drupal {}'.format(WORKSPACE, DRUPAL_ROOT))
print green('Symlinks created')
@task(alias='dbs')
@task(alias='dc')
@roles('docker')
def data_base_setup(role='docker'):
def drush_commands(role='docker', cmds=POST_INSTALL):
"""
Setup database for site install
Execute a list of drush commands after the installation or update process
"""
set_env(role)
fab_run(role, 'mysql -uroot -e "CREATE DATABASE IF NOT EXISTS {}; GRANT ALL PRIVILEGES ON {}.* TO '
'\'{}\'@\'localhost\' IDENTIFIED BY \'{}\'; FLUSH PRIVILEGES;"'.format(DB_NAME, DB_NAME,
DB_USER, DB_PASS))
if not LOCALE:
cmds.remove('drush po-import fr --custom-only')
@task(alias='si')
@roles('docker')
def site_install(role='docker'):
"""
Install site
"""
set_env(role)
with fab_cd(role, DRUPAL_ROOT):
locale = '--locale="fr"' if LOCALE else ''
for cmd in cmds:
with fab_cd(role, DRUPAL_ROOT):
fab_run(role, cmd)
fab_run(role, 'sudo -u {} drush site-install {} {} --db-url=mysql://{}:{}@{}/{} --site-name={} '
'--account-name={} --account-pass={} --sites-subdir={} -y'.format(APACHE, SITE_PROFILE, locale,
DB_USER, DB_PASS,
DB_HOST, DB_NAME, SITE_NAME,
SITE_ADMIN_NAME,
SITE_ADMIN_PASS,
SITE_SUBDIR))
print green('Site installed successfully!')
print green('These Drush commands were executed: {}.'.format(', '.join(cmds)))
@task(alias='dcf')
......@@ -535,6 +509,30 @@ def drush_config(role='local'):
print green('Drush configuration done.')
@task(alias='csy')
@roles('docker')
def create_symlinks(role='docker'):
"""
Create symlinks for the site
"""
set_env(role)
fab_run(role, 'rm -rf {}'.format(DRUPAL_ROOT))
fab_run(role, 'ln -s {}/src/drupal {}'.format(WORKSPACE, DRUPAL_ROOT))
print green('Symlinks created')
@task(alias='dbs')
@roles('docker')
def data_base_setup(role='docker'):
"""
Setup database for site install
"""
set_env(role)
fab_run(role, 'mysql -uroot -e "CREATE DATABASE IF NOT EXISTS {}; GRANT ALL PRIVILEGES ON {}.* TO '
'\'{}\'@\'localhost\' IDENTIFIED BY \'{}\'; FLUSH PRIVILEGES;"'.format(DB_NAME, DB_NAME,
DB_USER, DB_PASS))
@task(alias='cs')
@roles('docker')
def copy_settings(role='docker', site_env=SITE_ENVIRONMENT):
......@@ -587,24 +585,6 @@ def set_permission(role='docker'):
secure_settings(env)
@task(alias='dc')
@roles('docker')
def drush_commands(role='docker', cmds=POST_INSTALL):
"""
Execute a list of drush commands after the installation or update process
"""
set_env(role)
if not LOCALE:
cmds.remove('drush po-import fr --custom-only')
for cmd in cmds:
with fab_cd(role, DRUPAL_ROOT):
fab_run(role, cmd)
print green('These Drush commands were executed: {}.'.format(', '.join(cmds)))
@task(alias='cb')
@roles('docker')
def behat_config(role='docker', rewrite=True):
......@@ -661,15 +641,24 @@ def run_behat(role='docker'):
# fab_run(role, 'behat --format pretty --tags "~@wip&&~@disabled&&@yourTest" --colors')
@task(alias='rbt')
@task(alias='si')
@roles('docker')
def run_behat_tests(role='docker'):
def site_install(role='docker'):
"""
Setup Behat configutation and run tests, the same that run fab rbht cbht
Install site
"""
set_env(role)
behat_config(role)
run_behat(role)
with fab_cd(role, DRUPAL_ROOT):
locale = '--locale="fr"' if LOCALE else ''
fab_run(role, 'sudo -u {} drush site-install {} {} --db-url=mysql://{}:{}@{}/{} --site-name={} '
'--account-name={} --account-pass={} --sites-subdir={} -y'.format(APACHE, SITE_PROFILE, locale,
DB_USER, DB_PASS,
DB_HOST, DB_NAME, SITE_NAME,
SITE_ADMIN_NAME,
SITE_ADMIN_PASS,
SITE_SUBDIR))
print green('Site installed successfully!')
@task(alias='su')
......@@ -696,22 +685,15 @@ def site_update(role='docker'):
print green('Aborting site updated!')
@task(alias='ls')
@runs_once
def local_setup():
@task(alias='sr')
def site_reinstall():
"""
Complete local installation process, used generally when building the docker image for install and configure Drupal.
The same that run: $ fab dr gcp cp_keys dmk icreate crun dkuh csy dbs si dcf cs es ss dc cb
Complete local re-installation process. To use generally inside the running container to reinstall the Drupal site.
The same that run: $ fab dr gpp dmk si dcf cs es ss dc cb
"""
execute(delete_root)
execute(git_clone_profile)
execute(copy_ssh_keys)
execute(git_pull_profile)
execute(drush_make)
execute(docker_create_image)
execute(docker_run_container)
execute(docker_update_host)
execute(create_symlinks)
execute(data_base_setup)
execute(site_install)
execute(drush_config)
execute(copy_settings)
......@@ -719,18 +701,25 @@ def local_setup():
execute(secure_settings)
execute(drush_commands)
execute(behat_config)
print green('Local setup finished with success!')
print green('Site reinstalled with success!')
@task(alias='sr')
def site_reinstall():
@task(alias='ls')
@runs_once
def local_setup():
"""
Complete local re-installation process. To use generally inside the running container to reinstall the Drupal site.
The same that run: $ fab dr gpp dmk si dcf cs es ss dc cb
Complete local installation process, used generally when building the docker image for install and configure Drupal.
The same that run: $ fab dr gcp cp_keys dmk icreate crun dkuh csy dbs si dcf cs es ss dc cb
"""
execute(delete_root)
execute(git_pull_profile)
execute(git_clone_profile)
execute(copy_ssh_keys)
execute(drush_make)
execute(docker_create_image)
execute(docker_run_container)
execute(docker_update_host)
execute(create_symlinks)
execute(data_base_setup)
execute(site_install)
execute(drush_config)
execute(copy_settings)
......@@ -738,4 +727,4 @@ def site_reinstall():
execute(secure_settings)
execute(drush_commands)
execute(behat_config)
print green('Site reinstalled with success!')
print green('Local setup finished with success!')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment