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