Commits (38)
# docker Drupal
# VERSION 0.3
FROM savoirfairelinux/lampd
MAINTAINER Ernesto Rodriguez Ortiz <ernesto.rodriguezortiz@savoirfairelinuc.com>
ENV initpath ./fabfile/docker
COPY ${initpath} /opt/init
RUN /opt/init/bootstrap
ENTRYPOINT ["/opt/init/init"]
CMD ["/sbin/my_init"]
......@@ -88,7 +88,10 @@ Those are global project parameters mandatory to Drupalizer.
|The Drupal site directory (only for multisite). Default: _default_.
|_site_languages_
|Translation files that must be downloaded when building Drupal and activated during installation (separate with comma). Default: _fr_.
|The languages for which the translation files will be downloaded (separate with comma). Default: _''_.
|_site_default_language_
|The default language for site installation. Default: _''_.
|===
......@@ -211,4 +214,4 @@ CAUTION: This command will wipe all the modifications made in the working direct
* _Generate_ the guide style:
$ fab patternlab.build
$ fab patternlab.build
\ No newline at end of file
......@@ -21,10 +21,10 @@ def init():
execute(docker.container_start)
execute(drush.make, 'install')
execute(drush.site_install, host='root@{}'.format(env.container_ip))
execute(drush.site_install)
execute(drush.aliases)
execute(behat.init, host='root@{}'.format(env.container_ip))
execute(behat.init)
@task
......
......@@ -24,7 +24,7 @@ def init(rewrite=True):
h.fab_run(role, 'cp example.behat.yml behat.yml')
h.fab_run(role, 'sed -i "s@%DRUPAL_ROOT@{}@g" behat.yml'.format(site_root))
h.fab_run(role, 'sed -i "s@%URL@http://{}@g" behat.yml'.format(host))
h.fab_run(role, 'echo "127.0.0.1 {}" >> /etc/hosts'.format(host))
h.fab_run(role, 'echo "127.0.0.1 {}" | sudo tee -a /etc/hosts'.format(host))
print green('Behat is now properly configured. The configuration file is {}/tests/behat/behat.yml'.format(workspace))
else:
......
......@@ -27,7 +27,7 @@ env.site_admin_user = 'admin'
env.site_admin_pass = 'admin'
env.site_subdir = 'default'
env.site_languages = ''
env.site_default_language = ''
# PatternLab
......
......@@ -128,7 +128,7 @@ def _rsync_platform(target, target_directory):
"""
Helper function to rsync platform to server.
"""
local('rsync -a --exclude sites/*/settings.php --exclude sites/*/files src/drupal/ {}@{}:{}'.format(target.get('user'), target.get('host'), target_directory))
local('rsync -a --delete --exclude sites/*/settings.php --exclude sites/*/files src/drupal/ {}@{}:{}'.format(target.get('user'), target.get('host'), target_directory))
def _aegir_provision_platform(platform, aegir_path, aegir_destsrv):
......
from __future__ import unicode_literals
import os
from fabric.api import task, roles, env, local, run, lcd, execute
from fabric.colors import red, green
from fabric.contrib.console import confirm
......@@ -54,6 +56,9 @@ def docker_tryrun(imgname, containername=None, opts='', mounts=None, cmd='', res
else:
containername_opt = ''
opts += ' -e USER_ID={}'.format(os.getuid())
opts += ' -e GROUP_ID={}'.format(os.getgid())
local('docker run %s %s %s %s' % (opts, containername_opt, imgname, cmd))
return True
......@@ -114,7 +119,7 @@ def connect():
"""
with lcd(env.workspace):
if docker_isrunning('{}_container'.format(env.project_name)):
local('docker exec -it {}_container bash'.format(env.project_name))
local('ssh drupalizer@{} -i {} -o StrictHostKeyChecking=no'.format(env.container_ip, h.fab_ssh_key()))
else:
print(red('Docker container {}_container is not running, it should be running to be able to connect.'))
......@@ -129,8 +134,8 @@ def image_create():
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('local')
local('docker build -t {}/drupal .'.format(env.project_name))
dockerfile = h.fab_path('Dockerfile')
local('docker build -t {}/drupal -f {} .'.format(env.project_name, dockerfile))
print(green('Docker image {}/drupal was build successful'.format(env.project_name)))
......
#!/bin/bash
set -e
INIT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/bootstrap.d"
if [[ -d $INIT_DIR && -r $INIT_DIR && -x $INIT_DIR ]]; then
for i in $(LC_ALL=C command ls "$INIT_DIR"); do
i=$INIT_DIR/$i
[[ -f $i && -r $i ]] && . "$i"
done
fi
##
# Create system users
#
# Main user for Drupalizer tasks
useradd --home-dir /opt/init drupalizer --shell /bin/bash
passwd -d drupalizer
chown drupalizer:drupalizer /opt/init
##
# Create required filesystem structure
#
# Shared filesystem mount point
mkdir -p /opt/sfl/
# Apache document root
mkdir -p /opt/sfl/src/drupal
# Ensure the correct owner
chown -R drupalizer:drupalizer /opt/sfl
##
# Configure SUDO rights
#
# Full access for `drupalizer` user without password
echo 'drupalizer ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
##
# Configure SSH access
#
# Use the same authorized_keys file for all users
echo 'AuthorizedKeysFile /etc/ssh/authorized_keys' >> /etc/ssh/sshd_config
# Add the default known key to allow access for all users
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDcJHyU5S4xRP4QyJuBOiS38mrEuwfgOoWoNFQM0gWhJCb2phByO4Xg68f4v0w3FWm2SQQKv3bG5aevTI2ST5n0o/GbcCpdT1udV9uQIxr1+cbXUrecaNPD3WyIxt1Rldtwm7+s0AlwHHk0zKvulyupzPfQGB4Ix0zUfIzt+U45ww==' > /etc/ssh/authorized_keys
service ssh restart
##
# Configure Apache webserver
#
# Configure default VirtualHost for Drupal
cat > /etc/apache2/sites-available/000-default.conf <<EOF
ServerName localhost
<VirtualHost *:80>
DocumentRoot /opt/sfl/src/drupal
<Directory /opt/sfl/src/drupal/>
AllowOverride All
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
EOF
# Make Apache run as the main `drupalizer` user
cat >> /etc/apache2/envvars << EOF
export APACHE_RUN_USER=drupalizer
export APACHE_RUN_GROUP=drupalizer
EOF
# Enable modules required by Drupal
a2enmod rewrite vhost_alias
service apache2 restart
##
# Configure .profile login script
#
# Change CWD instantly after login into Apache document root for convenience
echo 'cd /opt/sfl/src/drupal' > /opt/init/.profile
#!/bin/bash
if [[ ! -z "$USER_ID" ]]
then
which usermod 2>&1 >/dev/null && usermod -u $USER_ID drupalizer
service apache2 reload
fi
if [[ ! -z "$GROUP_ID" ]]
then
which groupmod 2>&1 >/dev/null && groupmod -g $GROUP_ID drupalizer
service apache2 reload
fi
exec /bin/sh -c "$*"
-----BEGIN RSA PRIVATE KEY-----
MIICX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 @@
from __future__ import unicode_literals
from datetime import datetime
import os
from fabric.api import task, roles, env, local
from fabric.colors import red, green
from fabric.contrib.console import confirm
......@@ -63,6 +65,12 @@ def make(action='install'):
local('mkdir {}'.format(env.site_root))
with h.fab_cd('local', env.site_root):
if os.path.isdir('{}/sites/default/'.format(env.site_root)):
local('chmod u+w sites/default')
if os.path.isfile('{}/sites/default/settings.php'.format(env.site_root)):
local('chmod u+w sites/default/settings.php')
local('drush make {} {} -y'.format(drush_opts, env.makefile))
......@@ -124,16 +132,13 @@ def site_install():
h.init_db('docker')
with h.fab_cd(role, site_root):
h.fab_run(role, 'chown {}:{} ./sites'.format(env.apache_user, env.apache_user))
h.fab_run(role, 'chmod ug+w ./sites/default'.format(env.docker_site_root))
if env.site_languages:
locale = '--locale="{}"'.format(env.site_languages.split(',')[0])
if env.site_default_language:
locale = '--locale="{}"'.format(env.site_default_language)
else:
locale = ''
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,
h.fab_run(role, 'drush site-install {} {} --db-url=mysql://{}:{}@{}/{} --site-name="{}" '
'--account-name={} --account-pass={} --sites-subdir={} -y'.format(profile, locale,
db_user, db_pass,
db_host, db_name, site_name,
site_admin_name,
......
......@@ -57,7 +57,7 @@ def _check_repo(repoLocalPath):
print green('---')
print green('Verify repo in ' + repoLocalPath)
remoteName = local('git remote', capture=True)
remoteName = local('LC_ALL=C git remote', capture=True)
filesStatusRawInfo = _get_files_status_information()
print green('Verify local files status against current HEAD commit...')
......@@ -120,9 +120,7 @@ def _check_local_branches_exist_on_remote(localBranchesRawInfo, remoteName):
def _check_local_branches_status_vs_remote(localBranchesRawInfo, remoteName):
nbWarnings = 0
pushableBranches = []
# on gere un git FR ou EN, a voir ce qu'on peut faire
# pour une internationalisation plus cool..
pattern = re.compile('.*\[.* (ahead|en avance de) .*\].*')
pattern = re.compile('.*\[.* (ahead) .*\].*')
for localBranchRawInfo in localBranchesRawInfo:
if (pattern.match(localBranchRawInfo)):
localBranchName = _get_branch_name(localBranchRawInfo)
......
......@@ -18,12 +18,14 @@
from __future__ import unicode_literals
import os
import socket
from getpass import getuser
from fabric.api import lcd, cd, roles, local, run
from fabric.colors import green
from fabric.context_managers import settings
from fabric.contrib.console import confirm
from fabric.contrib.files import exists
......@@ -43,7 +45,7 @@ host_name = local("hostname", capture=True)
# Set the env dict with the roles and the hosts
env.roledefs['local'] = ["{}@{}".format(user_name, host_name)]
env.roledefs['docker'] = ["root@{}".format(env.container_ip)]
env.roledefs['docker'] = ["drupalizer@{}".format(env.container_ip)]
env.builddir = path.join(env.workspace, 'build')
......@@ -68,7 +70,8 @@ def fab_run(role="local", cmd=""):
if role == "local":
return local(cmd)
else:
return run(cmd)
with settings(key_filename=fab_ssh_key()):
return run(cmd)
def fab_cd(role, directory):
......@@ -94,7 +97,8 @@ def fab_exists(role, directory):
if role == "local":
return path.exists(directory)
else:
return exists(directory)
with settings(key_filename=fab_ssh_key()):
return exists(directory)
def fab_add_to_hosts(ip, site_hostname):
......@@ -133,9 +137,15 @@ def fab_remove_from_hosts(site_hostname):
def fab_update_container_ip(container_ip):
local('sed -i "/env.container_ip/d" {}/local_vars.py'.format(path.dirname(path.abspath(__file__))))
local('sed -i "/# Docker auto-added container IP/a env.container_ip = \'{}\'" '
'{}/local_vars.py'.format(''.join(container_ip), path.dirname(path.abspath(__file__))))
local('sed -i "/env.container_ip/d" {}'.format(fab_path('local_vars.py')))
local('sed -i "/# Docker auto-added container IP/a env.container_ip = \'{}\'" {}'.format(''.join(container_ip), fab_path('local_vars.py')))
# Redeclare 'docker' role with updated IP
env.roledefs['docker'] = ["drupalizer@{}".format(env.container_ip)]
if os.path.exists(fab_path('local_vars.pyc')):
# Clear cached bytecode file
os.remove(fab_path('local_vars.pyc'))
def fab_update_hosts(ip, site_hostname):
......@@ -200,3 +210,24 @@ 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 fab_path(filename):
"""
Returns the full path a file relative to the location of fabfile.
:param filename Name of the file to compose path from.
"""
path = os.path.dirname(os.path.abspath(__file__))
return os.path.abspath('{0}/{1}'.format(path, filename))
def fab_ssh_key():
"""
Returns the full path to default RSA key for SSH connections.
This helper checks and (if necessary) fixes filesystem permissions on the
RSA key file to make sure that SSH does not ignore keys accessible by other
users.
"""
path = fab_path('docker/ssh/id_rsa')
local('chmod 600 {}'.format(path))
return path