Commit c2496b21 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

Merge branch 'educaloi' into '2.x'

Educaloi

@emmanuel.milou j'ai changé certains choses.
La plus part des changements sont pour respecter PEP 8
L'autre part c'est afin de faire compatible drupalizer avec les projets comme Educaloi ou CSDN dont il n'y a pas des profiles d'installation personnalisé et on utilise une sauvegarde de base de données pour installer le projet.

See merge request !1
parents 0b330cef 57c340b7
......@@ -4,7 +4,7 @@ import drush
import behat
from .environments import e
from fabric.api import lcd, cd, task, roles, env, local, run, runs_once, execute
from fabric.api import task, env, execute
import helpers as h
......@@ -17,9 +17,9 @@ def init():
execute(docker.image_create)
execute(docker.container_start)
execute(drush.make, 'install')
execute(drush.site_install)
execute(drush.site_install, host='root@{}'.format(env.container_ip))
execute(drush.aliases)
execute(behat.init)
execute(behat.init, host='root@{}'.format(env.container_ip))
......
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
from fabric.api import task, roles, env
from fabric.colors import green
import helpers as h
......
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.api import task, roles, env
from fabric.colors import red, green
import helpers as h
import os.path
@task
@roles('docker')
def db_import(filename=env.db_dump, role='docker'):
def db_import(filename, role='docker'):
"""Import and restore the specified database dump.
$ fab core.db_import:/tmp/db_dump.sql.gz
......@@ -16,10 +14,9 @@ def db_import(filename=env.db_dump, role='docker'):
:param filename: a full path to a gzipped sql dump.
"""
if os.path.isfile(filename):
if h.fab_exists(role, 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.'))
h.fab_run(role, 'zcat {} | mysql -u{} -p{} {}'.format(filename, env.site_db_user, env.site_db_pass, env.site_db_name))
print green('Database dump successfully restored.')
else:
print red('Could not find database dump at {}'.format(filename))
......@@ -17,8 +17,7 @@
#
from __future__ import unicode_literals
from fabric.api import lcd, cd, task, roles, env, local, run, runs_once, execute
from fabric.contrib.project import rsync_project
from fabric.api import task, roles, env, local, run
from fabric.colors import red, green
from fabric.utils import abort
......
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.api import task, roles, env, local, run
from fabric.colors import red, green
import helpers as h
......@@ -93,7 +92,6 @@ def docker_images():
return [line.strip().split(' ')[0] for line in lines]
@task
@roles('local')
def connect(role='local'):
......@@ -122,7 +120,7 @@ def image_create(role='local'):
if '{}/drupal'.format(env.project_name) in docker_images():
print(red('Docker image {}/drupal was found, you has already build this image'.format(env.project_name)))
else:
h._copy_public_ssh_keys(role)
h.copy_public_ssh_keys(role)
h.fab_run(role, 'docker build -t {}/drupal .'.format(env.project_name))
print(green('Docker image {}/drupal was build successful'.format(env.project_name)))
......@@ -147,8 +145,8 @@ def container_start(role='local'):
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)))
'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(env.container_ip)
......@@ -204,7 +202,8 @@ def image_remove(role='local'):
with h.fab_cd(role, env.workspace):
if docker_isrunning('{}_container'.format(env.project_name)):
print(red('Docker container {}_container is running, '
'you should stopped it after remove the image {}/drupal'.format(env.project_name, env.project_name)))
'you should stopped it after remove the image {}/drupal'.format(env.project_name,
env.project_name)))
if '{}/drupal'.format(env.project_name) in docker_images():
h.fab_run(role, 'docker rmi -f {}/drupal'.format(env.project_name))
# Remove dangling docker images to free space.
......@@ -224,8 +223,7 @@ def update_host():
site_hostname = run("hostname")
run("sed '/{}/c\{} {} localhost.domainlocal' "
"/etc/hosts > /root/hosts.backup".format(env.container_ip, env.container_ip, site_hostname))
"/etc/hosts > /root/hosts.backup".format(env.container_ip, env.container_ip, site_hostname))
run("cat /root/hosts.backup > /etc/hosts")
h.fab_update_container_ip()
......@@ -17,7 +17,7 @@
#
from __future__ import unicode_literals
from fabric.api import lcd, cd, task, roles, env, local, run, runs_once, execute
from fabric.api import task, roles, env
from fabric.contrib.console import confirm
from fabric.colors import red, green
......@@ -27,32 +27,35 @@ from datetime import datetime
import os.path
import helpers as h
import core as c
@task(alias='make')
@roles('local')
def make(action='install'):
"""
Build the platform by running the Makefile specified in the local_vars.py configuration file.
"""
# Update profile codebase
h._update_profile()
drush_opts = "--prepare-install " if action != 'update' else ''
if (env.interactive_mode and confirm(red('Say [Y] to {} the site at {} with the French translation, if you say [n] '
'the site will be installed in English only'.format(action, env.site_root)))
) or not env.interactive_mode:
# Update profile codebase
if env.site_profile and env.site_profile != '':
drush_opts += "--contrib-destination=profiles/{} ".format(env.site_profile)
h.update_profile()
if not env.interactive_mode:
drush_opts += "--translations=fr "
elif confirm(red('Say [Y] to {} the site at {} with the French translation, if you say [n] '
'the site will be installed in English only'.format(action, env.site_root))):
drush_opts += "--translations=fr "
drush_opts += "--contrib-destination=profiles/{} ".format(env.site_profile)
if env.interactive_mode:
drush_opts += " --working-copy --no-gitinfofile"
if not h.fab_exists('local', env.site_root):
h.fab_run('local', "mkdir {}".format(env.site_root))
with h.fab_cd('local', env.site_root):
h.fab_run('local', 'drush make {} {} -y'.format(drush_opts, env.makefile))
h.fab_run('local', 'drush make {} {} -y'.format(drush_opts, env.makefile))
@task
......@@ -63,18 +66,18 @@ def aliases():
"""
role = 'local'
aliases = env.site_drush_aliases
drush_aliases = env.site_drush_aliases
workspace = env.workspace
if not h.fab_exists(role, aliases):
h.fab_run(role, 'mkdir {}'.format(aliases))
with h.fab_cd(role, aliases):
if not h.fab_exists(role, drush_aliases):
h.fab_run(role, 'mkdir {}'.format(drush_aliases))
with h.fab_cd(role, drush_aliases):
# Create aliases
if h.fab_exists(role, '{}/aliases.drushrc.php'.format(aliases)):
if h.fab_exists(role, '{}/aliases.drushrc.php'.format(drush_aliases)):
h.fab_run(role, 'rm aliases.drushrc.php')
h.fab_run(role, 'ln -s {}/conf/aliases.drushrc.php .'.format(workspace))
print green('Drush aliases have been copied to {} directory.'.format(aliases))
print green('Drush aliases have been copied to {} directory.'.format(drush_aliases))
@task
......@@ -87,13 +90,12 @@ def updatedb():
role = 'docker'
with h.fab_cd(role, env.docker_site_root):
h.fab_run(role, 'drush updatedb -y')
h.fab_run(role, 'drush updatedb -y')
@task
@roles('docker')
def site_install():
"""
Run the site installation procedure.
"""
......@@ -112,25 +114,24 @@ def site_install():
site_subdir = env.site_subdir
# Create first the database if necessary
h._init_db('docker')
h.init_db('docker')
with h.fab_cd(role, site_root):
locale = '--locale="fr"' if env.locale else ''
h.fab_run(role, 'sudo -u {} drush site-install {} {} --db-url=mysql://{}:{}@{}/{} --site-name={} '
'--account-name={} --account-pass={} --sites-subdir={} -y'.format(apache, profile, locale,
db_user, db_pass,
db_host, db_name, site_name,
site_admin_name,
site_admin_pass,
site_subdir))
'--account-name={} --account-pass={} --sites-subdir={} -y'.format(apache, 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!')
# Import db_dump if it exists.
if 'db_dump' in env and env.db_dump is not False:
h._db_import(env.db_dump)
c.db_import(env.db_dump, role)
h.hook_execute('post_install', role)
......@@ -150,9 +151,12 @@ def archive_dump(role='docker'):
h.fab_run(
role,
'drush archive-dump --destination={}/build/{} --tags="sflinux {}" --generatorversion="2.x" --generator="Drupalizer::fab drush.archive_dump" --tar-options="--exclude=.git"'.format(env.docker_workspace, platform, env.project_name)
'drush archive-dump --destination={}/build/{} --tags="sflinux {}" --generatorversion="2.x" '
'--generator="Drupalizer::fab drush.archive_dump" --tar-options="--exclude=.git"'
''.format(env.docker_workspace, platform, env.project_name)
)
@task
@roles('docker')
def gen_doc(role='docker'):
......@@ -170,5 +174,3 @@ def gen_doc(role='docker'):
h.fab_run(role, 'asciidoctor -b html5 -o {}/CHANGELOG.html {}/CHANGELOG.adoc'.format(env.docker_workspace,
env.docker_workspace))
print(green('CHANGELOG.html generated in {}'.format(env.docker_workspace)))
......@@ -18,8 +18,8 @@
from __future__ import unicode_literals
from getpass import getuser
from fabric.api import lcd, cd, task, roles, env, local, run, runs_once, execute
from fabric.colors import red, green
from fabric.api import lcd, cd, roles, local, run
from fabric.colors import green
from fabric.contrib.console import confirm
from fabric.contrib.files import exists
......@@ -154,7 +154,7 @@ def hook_execute(hook, role='docker'):
fab_run(role, cmd)
def _copy_public_ssh_keys(role='local'):
def copy_public_ssh_keys(role='local'):
"""
Copy your public SSH keys to use it in the docker container to connect to it using ssh protocol.
......@@ -166,7 +166,7 @@ def _copy_public_ssh_keys(role='local'):
print green('Public SSH key copied successful to {}/conf directory'.format(env.workspace))
def _update_profile(role='local'):
def update_profile(role='local'):
"""
Update or clone the installation profile specified in the configuration file.
The build file included will be used to build the application.
......@@ -182,7 +182,7 @@ def _update_profile(role='local'):
@roles('docker')
def _init_db(role='docker'):
def init_db(role='docker'):
"""
Create a database and a user that can access it.
......@@ -197,18 +197,3 @@ def _init_db(role='docker'):
'\'{}\'@\'localhost\' IDENTIFIED BY \'{}\'; GRANT ALL PRIVILEGES ON {}.* TO \'{}\'@\'{}\' '
'IDENTIFIED BY \'{}\'; FLUSH PRIVILEGES;"'.format(env.site_db_name, env.site_db_name, env.site_db_user, env.site_db_pass,
env.site_db_name, env.site_db_user, docker_iface_ip, env.site_db_user))
def _db_import(filename, role='local'):
"""Import and restore the specified database dump.
:param filename: a full path to a gzipped sql dump.
"""
if path.isfile(filename):
print green('Database dump {} found.'.format(filename))
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))
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