Update directory structure & allow to configure paths (tmp, log, cache)

This commit is contained in:
Nicolas Le Goff
2014-09-05 11:28:25 +02:00
parent 69fd50906f
commit de7988689e
2201 changed files with 850 additions and 13650 deletions

View File

@@ -0,0 +1,6 @@
forge "http://forge.puppetlabs.com"
mod 'php', :git => 'https://github.com/puphpet/puppet-php.git'
mod 'composer', :git => 'https://github.com/puphpet/puppet-composer.git'
mod 'puphpet', :git => 'https://github.com/puphpet/puppet-puphpet.git'
mod 'puppi', :git => 'https://github.com/puphpet/puppi.git'

View File

@@ -0,0 +1,226 @@
DRUSH PUPPET MODULE
===================
This module manages Drush, a command line shell and scripting interface for
Drupal.
It can install and upgrade Drush from Debian packages or source, as well as
download, enable and disable Drupal modules and themes, build codebases from
Drush makefiles, run arbitrary Drush commands and optionally log its output.
DEPENDENCIES
------------
None.
REQUIREMENTS
------------
The Drush Puppet module is designed to work on Debian GNU/Linux systems and
derivatives. It provides rudimentary support for apt-get, but defaults to
letting the OS's default packaging system handle installation. As such, it
should work with other *nix systems, assuming Drush is available for install
in the OS's packaging system, or Drush is installed from source using the
provided 'drush::git' class.
INSTALLATION
------------
To use this module, follow these directions:
1. Your modules directory will need all the files included in this
repository placed under a directory called "drush".
2. To install Drush, add one of these entries to your manifests (such as in
manifests/nodes.pp):
include drush
or
class {'drush':
ensure => latest,
}
The following parameters are available:
api: The major version of Drush to install. Currently supports '4' or '5'.
dist: The Debian distribution from which to install via apt-get. Defaults
to 'stable'. Set to false to suppres adding custom sources for install
via apt-get.
ensure: What state the package should be in. Valid values are 'present'
(also called 'installed'), 'absent', 'purged', 'held', of 'latest'.
2a. To install Drush from source, add one of these entries to your manifests:
include drush::git::drush
or
class {'drush::git::drush':
git_branch => '8.x-6.x',
update => true,
}
The following parameters are available:
git_branch: The git branch to track.
git_tag: The git tag to check out.
git_url: The git URL from which to clone the repository.
update: Whether to update to the latest code with each Puppet run.
Defaults to false.
USAGE
-----
1. To run a Drush command, use the drush::run defined type like so:
drush::run { '@dev uli --uid=42': }
The following parameters are all optional:
command: The command to run. Defaults to the name of the resource.
site_alias: The alias against which to run the command.
options: Options to pass to Drush.
arguments: Arguments to pass to the command.
site_path: The path to the site or code-base in which to run the command.
drush_user: The user under which to execute the command.
drush_home: Set the drush_user's home directory, for alias search paths.
log: Path to the logfile in which to log all Drush output.
creates, unless, onlyif, refreshonly: Control whether the command is
executed at each Puppet run. Identical to these paramaters on the
built-in 'exec' resource.
timeout: The maximum time the command should take, specified in seconds.
Defaults to 300 seconds. Disable the timeout by setting to 0.
paths: provide alternative paths to search for your Drush executable.
2. To download projects from drupal.org to a site, add lines such as the
following to your manifests:
drush::dl {'token':
site_path => '/var/aegir/platforms/drupal/sites/example.com',
log => '/var/aegir/drush.log',
}
The following parameters are all optional:
type: The type of package to download. Defaults to 'module'.
version: The version of the package to download.
site_path: Operates the same as for drush::run. Set this parameter to avoid
having a package downloaded repeatedly, as it will allow Puppet to see
whether it already exists. Alternatively, do not set this parameter to
have the package continuously updated.
site_alias, options, arguments, drush_user, drush_home, log: All operate
the same as for drush::run.
3. To enable or disable projects on a Drupal site, add lines such as the following to your
manifests:
drush::en {'token':
site_alias => '@www.example.com',
}
drush::dis {'@prod devel, devel-generate':}
The following parameters are all optional:
site_alias, options, arguments, site_path, drush_user, drush_home, log: All
operate the same as for drush::run.
4. To display the status of a site in your Puppet log, add lines such as the
following to your manifests:
drush::dis {'@prod status':
options => '--full',
}
The following parameters are all optional:
site_alias, options, arguments, site_path, drush_user, drush_home, log: All
operate the same as for drush::run.
5. To build a Drupal code-base using Drush Make, add lines such as the following to your
manifests:
drush::make {'/var/aegir/platform/Drupal7':
makefile => '/var/aegir/makefiles/drupal7.make',
}
There is one required parameter:
makefile: The path to the makefile to use in building the code-base.
The following parameters are all optional:
make_path: The path to build the code-base. Defaults to the name of the
resource.
options, drush_user, drush_home, log: All operate the same as for
drush::run.
6. The module also provides a simple way to clone git repos and keep them up-
to-date:
drush::git { 'git://git.drupal.org:project/provision':
path => '/var/aegir/.drush',
}
There is one required parameter:
path: Where to clone the git repo.
The following parameters are all optional:
git_branch: The git branch to checkout.
git_tag: The git tag to check out. Overrides 'branch' if also specified.
git_repo: The git repository to clone. Defaults to the resource name.
dir_name: The name of the directory in which to clone the git repo.
update: Run 'git pull -r' in this repo on every Puppet run.
paths: Alternative search paths for your git binary.
DEVELOPING
----------
The drush::run defined type provides a basis on which to build pretty much any
Drush command imagineable. The other provided commands build upon it to provide
convenience resources for common use-cases. While quite simple, they should
form a good basis for creating your own custom defined types.
For more complex examples, take a look at the puppet-aegir module, which
extends this API further in the context of the Aegir Hosting System. It can be
found at:
https://drupal.org/project/puppet-aegir
Along similar lines, Skynet takes this way too far:
https://drupal.org/project/skynet
The drush::git resource is a minimalist general-purpose function to allow
cloning and updating git repositories. It is not intended to be a full-featured
git class/resource. It will not attempt to install git for you either, but this
should be sufficient:
package {'git':}
This Puppet module is published under the GNU GPLv2 (General Public License,
Version 2), and as such is, and will always remain, Free Software. Engagement
in the development process by users and other developers is very much appreci-
ated. So, please feel free to post to the issue queue, submit bug reports and
feature requests, and ask questions about how to use or extend it.
-------------------------------------------------------------------------------
Current maintainers: Christopher Gervais (mailto:chris@praxis.coop)
Guillaume Boudrias (mailto:gboudrias@praxis.coop)
Original authors: Christopher Gervais (mailto:chris@koumbit.org)
Antoine Beaupré (mailto:anarcat@koumbit.org)
Copyright:: Copyright (c) 2011-2013 Réseau Koumbit Networks
License:: GPLv2 or later

View File

@@ -0,0 +1,49 @@
class drush::apt ( $dist = false, $backports = false) {
if $backports {
file { "/etc/apt/preferences.d/drush-${backports}.pref":
ensure => 'present',
content => "Package: drush\nPin: release a=${backports}-backports\nPin-Priority: 1001\n",
owner => root, group => root, mode => '0644',
notify => Exec['drush_update_apt'],
}
file { "/etc/apt/sources.list.d/drush-${backports}-backports.list" :
ensure => 'present',
content => "deb http://backports.debian.org/debian-backports ${backports}-backports main",
owner => root, group => root, mode => '0644',
notify => Exec['drush_update_apt'],
}
}
else {
file { [
"/etc/apt/preferences.d/drush-${backports}.pref",
"/etc/apt/sources.list.d/drush-${backports}-backports.list",
]:
ensure => 'absent',
notify => Exec['drush_update_apt'],
}
}
if $dist {
file { "/etc/apt/sources.list.d/drush-${dist}.list" :
ensure => 'present',
content => "deb http://ftp.debian.org/debian ${dist} main",
owner => root, group => root, mode => '0644',
notify => Exec['drush_update_apt'],
before => Exec['drush_apt_update'],
}
}
exec { 'drush_update_apt':
command => 'apt-get update & sleep 1',
path => [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/' ],
refreshonly => true,
}
exec { 'drush_apt_update':
command => 'apt-get update && /usr/bin/apt-get autoclean',
path => [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/' ],
schedule => daily,
}
}

View File

@@ -0,0 +1,25 @@
define drush::dis (
$site_alias = $drush::params::site_alias,
$options = $drush::params::options,
$arguments = $drush::params::arguments,
$site_path = $drush::params::site_path,
$drush_user = $drush::params::drush_user,
$drush_home = $drush::params::drush_home,
$log = $drush::params::log
) {
if $arguments { $real_args = $arguments }
else { $real_args = $name }
drush::run {"drush-dis:${name}":
command => 'pm-disable',
site_alias => $site_alias,
options => $options,
arguments => $real_args,
site_path => $site_path,
drush_user => $drush_user,
drush_home => $drush_home,
log => $log,
}
}

View File

@@ -0,0 +1,48 @@
define drush::dl (
$type = 'module',
$site_alias = $drush::params::site_alias,
$options = $drush::params::options,
$arguments = $drush::params::arguments,
$drush_user = $drush::params::drush_user,
$drush_home = $drush::params::drush_home,
$log = $drush::params::log
) {
if $arguments { $real_args = $arguments }
else { $real_args = "${name}" }
# Always download drush extensions without a site alias.
if $type == 'extension' { $real_alias = '@none' }
else { $real_alias = "${site_alias}" }
drush::run {"drush-dl:${name}":
command => 'pm-download',
site_alias => $real_alias,
options => $options,
arguments => $real_args,
drush_user => $drush_user,
drush_home => $drush_home,
log => $log,
}
# Add an 'unless' argument depending on the project type.
case $type {
'module', 'theme': {
Drush::Run["drush-dl:${name}"] {
unless => "drush ${site_alias} pm-list | grep ${name}",
}
}
'extension': {
Drush::Run["drush-dl:${name}"] {
unless => "[ -d '${drush_home}/.drush/${name}' ]",
}
}
}
if defined(Drush::Run["drush-en:${name}"]) {
Drush::Run["drush-dl:${name}"] {
before +> Exec["drush-en:${name}"],
}
}
}

View File

@@ -0,0 +1,26 @@
define drush::en (
$site_alias = $drush::params::site_alias,
$options = $drush::params::options,
$arguments = $drush::params::arguments,
$drush_user = $drush::params::drush_user,
$drush_home = $drush::params::drush_home,
$log = $drush::params::log,
$refreshonly = false
) {
if $arguments { $real_args = $arguments }
else { $real_args = $name }
drush::run {"drush-en:${name}":
command => 'pm-enable',
site_alias => $site_alias,
options => $options,
arguments => $real_args,
drush_user => $drush_user,
drush_home => $drush_home,
refreshonly => $refreshonly,
log => $log,
unless => "drush ${site_alias} pm-list --status=enabled | grep ${name}",
}
}

View File

@@ -0,0 +1,60 @@
define drush::git (
$path,
$git_branch = '',
$git_tag = '',
$git_repo = false,
$dir_name = false,
$update = false,
$paths = $drush::params::paths,
$user = 'root',
) {
# Default to the resource name if no explicit git repo is provided.
if $git_repo { $real_git_repo = $git_repo }
else { $real_git_repo = $name }
# Figure out the path and directory name.
if $dir_name {
$real_path = "${path}/${dir_name}"
$real_dir = $dir_name
}
else {
# Figure out the name of the cloned into directory from the git repo.
$repo_array = split($real_git_repo, '[/]')
$last_element = $repo_array[-1]
$real_dir = regsubst($last_element, '\.git$', '')
$real_path = "${path}/${real_dir}"
}
exec {"drush-clone-repo:${name}":
command => "git clone ${real_git_repo} ${real_dir}",
creates => $real_path,
cwd => $path,
user => $user,
path => $paths,
timeout => 0,
}
# The specific (tag) overrides the general (branch).
if $git_tag { $git_ref = $git_tag }
else { $git_ref = $git_branch }
if $git_ref {
exec {"drush-checkout-ref:${name}":
command => "git checkout ${git_ref}",
cwd => $real_path,
path => $paths,
require => Exec["drush-clone-repo:${name}"],
}
}
if $update {
exec {"drush-update-repo:${name}":
command => 'git pull -r',
cwd => $real_path,
path => $paths,
require => Exec["drush-clone-repo:${name}"],
}
}
}

View File

@@ -0,0 +1,61 @@
class drush::git::drush (
$git_branch = '',
$git_tag = '',
$git_repo = 'https://github.com/drush-ops/drush.git',
$update = false
) inherits drush::params {
include php::params
Exec { path => ['/bin', '/usr/bin', '/usr/local/bin', '/usr/share'], }
if ! defined(Package['git']) {
package { 'git':
ensure => present,
before => Drush::Git[$git_repo]
}
}
if ! defined(Class['composer']) {
class { 'composer':
target_dir => '/usr/local/bin',
composer_file => 'composer',
download_method => 'curl',
logoutput => false,
tmp_path => '/tmp',
php_package => "${php::params::module_prefix}cli",
curl_package => 'curl',
suhosin_enabled => false,
}
}
drush::git { $git_repo :
path => '/usr/share',
git_branch => $git_branch,
git_tag => $git_tag,
update => $update,
}
composer::exec { 'drush':
cmd => 'install',
cwd => '/usr/share/drush',
require => Drush::Git[$git_repo],
notify => File['symlink drush'],
}
file { 'symlink drush':
ensure => link,
path => '/usr/bin/drush',
target => '/usr/share/drush/drush',
require => Composer::Exec['drush'],
notify => Exec['first drush run'],
}
# Needed to download a Pear library
exec { 'first drush run':
command => 'drush cache-clear drush',
refreshonly => true,
require => File['symlink drush'],
}
}

View File

@@ -0,0 +1,33 @@
class drush (
$api = $drush::params::api,
$dist = $drush::params::dist,
$ensure = $drush::params::ensure
) inherits drush::params {
include drush::params
package { 'drush':
ensure => $ensure,
}
case $operatingsystem {
/^(Debian|Ubuntu)$/: {
include drush::apt
Package['drush'] { require => Exec['drush_update_apt'] }
}
}
if $dist {
Package['drush'] { require => Class['drush::apt'] }
if $api == 4 { $backports = 'squeeze' }
else { $backports = '' }
class {'drush::apt':
dist => $dist,
backports => $backports,
}
}
}

View File

@@ -0,0 +1,26 @@
define drush::make (
$makefile,
$make_path = false,
$options = $drush::params::options,
$site_path = $drush::params::site_path,
$drush_user = $drush::params::drush_user,
$drush_home = $drush::params::drush_home,
$log = $drush::params::log
) {
if $make_path { $real_make_path = $make_path }
else { $real_make_path = $name }
$arguments = "${makefile} ${real_make_path}"
drush::run {"drush-make:${name}":
command => 'make',
creates => $make_path,
options => $options,
arguments => $arguments,
drush_user => $drush_user,
drush_home => $drush_home,
log => $log,
timeout => 0,
}
}

View File

@@ -0,0 +1,35 @@
class drush::params {
case $::operatingsystem {
'centos', 'redhat': {
$php_cli_package = 'php-cli'
}
'ubuntu', 'debian': {
$php_cli_package = 'php5-cli'
}
default: {
fail('The puppet-drush module only supports RHEL and Debian systems')
}
}
$drush_user = 'root'
$drush_home = '/root'
$site_alias = '@none'
$options = ''
$arguments = ''
$api = 5
$dist = false
$ensure = 'present'
$site_path = false
$log = false
$creates = false
$paths = [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/' ]
if defined(Class['drush::git::drush']) {
$installed = Class['drush::git::drush']
}
else {
$installed = Class['drush']
}
}

View File

@@ -0,0 +1,57 @@
define drush::run (
$command = false,
$site_alias = $drush::params::site_alias,
$options = $drush::params::options,
$arguments = $drush::params::arguments,
$site_path = $drush::params::site_path,
$drush_user = $drush::params::drush_user,
$drush_home = $drush::params::drush_home,
$log = $drush::params::log,
$installed = $drush::params::installed,
$creates = $drush::params::creates,
$paths = $drush::params::paths,
$timeout = false,
$unless = false,
$onlyif = false,
$refreshonly = false
) {
if $log { $log_output = " >> ${log} 2>&1" }
if $command { $real_command = $command }
else { $real_command = $name}
exec {"drush-run:${name}":
command => "drush ${site_alias} --yes ${options} ${real_command} ${arguments} ${log_output}",
user => $drush_user,
group => $drush_user,
path => $paths,
environment => "HOME=${drush_home}",
require => $installed,
}
if $site_path {
Exec["drush-run:${name}"] { cwd => $site_path }
}
if $creates {
Exec["drush-run:${name}"] { creates => $creates }
}
if $timeout {
Exec["drush-run:${name}"] { timeout => $timeout }
}
if $unless {
Exec["drush-run:${name}"] { unless => $unless }
}
if $onlyif {
Exec["drush-run:${name}"] { onlyif => $onlyif }
}
if $refreshonly {
Exec["drush-run:${name}"] { refreshonly => $refreshonly }
}
}

View File

@@ -0,0 +1,22 @@
define drush::status (
$site_alias = $drush::params::site_alias,
$options = $drush::params::options,
$arguments = $drush::params::arguments,
$site_path = $drush::params::site_path,
$drush_user = $drush::params::drush_user,
$drush_home = $drush::params::drush_home,
$log = $drush::params::log
) {
drush::run {"drush-status:${name}":
command => 'core-status',
site_alias => $site_alias,
options => $options,
arguments => $arguments,
site_path => $site_path,
drush_user => $drush_user,
drush_home => $drush_home,
log => $log,
}
}

View File

@@ -0,0 +1,11 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
config.vm.box = "Debian 6.0.7 x64"
config.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/debian-607-x64-vbox4210.box"
config.vm.provision :shell,
:path => "./tests/.ci/vagrant_test.sh"
end

View File

@@ -0,0 +1,78 @@
#!/bin/bash
echo "Creating test environment..."
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ -e $SCRIPT_DIR/.module ]
then
MODULE=`cat $SCRIPT_DIR/.module`
else
echo "ERROR: The test script expects the name of the module to be in a file"
echo " called '.module', in the same directory as the test script."
echo $SCRIPT_DIR
exit 1
fi
cd $SCRIPT_DIR
cd ../..
if [ -e manifests/init.pp ]
then
MODULE_DIR=`pwd`
else
echo "ERROR: The test script expects to be in <module_dir>/tests/.ci/, but"
echo " cannot find the module's 'init.pp', from its current location."
echo $SCRIPT_DIR
exit 1
fi
rm -rf /tmp/$MODULE
cp $MODULE_DIR /tmp/$MODULE -r
cd /tmp/$MODULE
wget http://ansi-color.googlecode.com/svn/tags/0.6/ansi-color/color >> /dev/null 2>&1
mv ./color /usr/local/bin
chmod a+x /usr/local/bin/color
echo "Scanning for tests in '$MODULE' module..."
FILES=`find /tmp/$MODULE/tests -name *.pp`
COUNT=${#FILES[@]}
PASSED=0
FAILED=0
TOTAL=0
echo "Running tests..."
for f in $FILES
do
NAME=`basename $f`
echo "Running '$NAME' test..."
OUTPUT=`puppet apply --noop --modulepath=/tmp/ --color=ansi $f 2>&1`
STATUS=$?
if [ $STATUS -ne 0 ]
then
color red
echo "///////////////////////////////////////////////////////"
echo
echo " ERROR in '$NAME' test."
echo " Output from failed test:"
echo
echo $OUTPUT
echo
echo "///////////////////////////////////////////////////////"
color off
let FAILED++
let TOTAL++
else
color green
echo "'$NAME' test passed."
color off
let PASSED++
let TOTAL++
fi
done
echo "Total tests run: $TOTAL"
color green
echo "Tests passed: $PASSED"
color red
echo "Tests failed: $FAILED"
color off
rm -rf /tmp/$MODULE
rm /usr/local/bin/color
exit $FAILED

View File

@@ -0,0 +1,5 @@
#!/bin/bash
cd /vagrant
chmod a+x tests/.ci/test.sh
./tests/.ci/test.sh

View File

@@ -0,0 +1,4 @@
class { 'drush::apt' :
dist => 'squeeze',
backports => 'squeeze',
}

View File

@@ -0,0 +1 @@
include drush::defaults

View File

@@ -0,0 +1,3 @@
include drush
drush::dis { 'devel': }

View File

@@ -0,0 +1,2 @@
include drush
drush::dl { 'token': }

View File

@@ -0,0 +1,2 @@
include drush
drush::en { 'views': }

View File

@@ -0,0 +1,4 @@
include drush
drush::git { 'git://git.drupal.org:project/provision.git' :
path => '/var/aegir/.drush',
}

View File

@@ -0,0 +1 @@
include drush::git::drush

View File

@@ -0,0 +1 @@
include drush

View File

@@ -0,0 +1,4 @@
include drush
drush::make { '/var/aegir/platforms/drupal7' :
makefile => '/var/aegir/makefiles/drupal7.make',
}

View File

@@ -0,0 +1,2 @@
include drush
drush::run { '@hostmaster hosting-dispatch' : }

View File

@@ -0,0 +1,2 @@
include drush
drush::status { '@none' : }