From 69501778bf6712cffb007c6cc58b16d6b576cfe6 Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Mon, 16 Jun 2014 10:01:37 -0300 Subject: [PATCH 01/18] Update some stuff --- manifests/app/wordpress/v1.pp | 2 +- manifests/environments/environment_apache.pp | 12 +++++++++--- manifests/environments/environment_nginx.pp | 13 ++++++------- manifests/params.pp | 8 ++++---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/manifests/app/wordpress/v1.pp b/manifests/app/wordpress/v1.pp index ae1097b..7a5470c 100644 --- a/manifests/app/wordpress/v1.pp +++ b/manifests/app/wordpress/v1.pp @@ -52,7 +52,7 @@ owner => "${user_name}", group => "${user_name}", replace => false, - require => puppi::netinstall["netinstall_wordpress_${user_name}_${name}"], + require => Puppi::Netinstall["netinstall_wordpress_${user_name}_${name}"], } } diff --git a/manifests/environments/environment_apache.pp b/manifests/environments/environment_apache.pp index c4bb419..597097c 100644 --- a/manifests/environments/environment_apache.pp +++ b/manifests/environments/environment_apache.pp @@ -1,23 +1,29 @@ class deploy_php::environments::environment_apache ( ) { apache::module { "${deploy_php::apache_module}": - install_package => true, + install_package => true, } + $restart_service = $::operatingsystem ? { + /(?i:Debian|Ubuntu|Mint)/ => 'apache2', + default => 'httpd', + } + + if $deploy_php::apache_module == "suphp" { file {"/etc/suphp/suphp.conf": content => template ("${deploy_php::template_suphp_conf}"), ensure => present, require => Package["ApacheModule_${deploy_php::apache_module}"], - notify => Service["apache2"], + notify => Service["${restart_service}"], } file {"/etc/apache2/mods-available/suphp.conf": content => template ("${deploy_php::template_suphp_mod}"), ensure => present, require => Package["ApacheModule_${deploy_php::apache_module}"], - notify => Service["apache2"], + notify => Service["${restart_service}"], } } diff --git a/manifests/environments/environment_nginx.pp b/manifests/environments/environment_nginx.pp index 3bbb3f4..265cd4f 100644 --- a/manifests/environments/environment_nginx.pp +++ b/manifests/environments/environment_nginx.pp @@ -1,12 +1,11 @@ class deploy_php::environments::environment_nginx { - package { [ "libpcre3", - "php5-common", - "libmysqlclient-dev", - "libmysqlclient18", - "php5-mcrypt"]: - + package { [ "libpcre3", + "php5-common", + "libmysqlclient-dev", + "libmysqlclient18", + "php5-mcrypt"]: ensure => installed, - } + } } diff --git a/manifests/params.pp b/manifests/params.pp index c759b7d..6be5074 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -4,19 +4,19 @@ # class deploy_php::params { - $webserver_name = "nginx" + $webserver_name = "nginx" $dir_path_webserver = "/home/vhosts" $apache_module = "suphp" $template_php_ini = "deploy_php/php.ini.erb" $template_suphp_conf = "deploy_php/suphp/suphp.conf" $template_suphp_mod = "deploy_php/suphp/suphp.conf-module" - file { "${dir_path_webserver}": - ensure => directory, + file { "${dir_path_webserver}": + ensure => directory, } file { ["/root/puppet/","/root/puppet/wordpress"]: - ensure => directory, + ensure => directory, } package { [ 'php5-mysql', From b0e5b068c9574a356d443ef528aabd380761ee56 Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Tue, 24 Jun 2014 15:36:18 -0300 Subject: [PATCH 02/18] Puppet-lint passed --- manifests/apache.pp | 124 ++++++++------- manifests/app/wordpress/v1.pp | 59 +++---- manifests/environments/environment_apache.pp | 27 ++-- manifests/environments/environment_nginx.pp | 13 +- manifests/init.pp | 30 ++-- manifests/nginx.pp | 152 +++++++++---------- manifests/params.pp | 34 ++--- spec/classes/init_spec.rb | 128 ---------------- 8 files changed, 215 insertions(+), 352 deletions(-) diff --git a/manifests/apache.pp b/manifests/apache.pp index 92255e7..da362c9 100755 --- a/manifests/apache.pp +++ b/manifests/apache.pp @@ -1,36 +1,37 @@ +# Define deploy_php::apache +# define deploy_php::apache ( $createdb = true, $mysql_password = '', - $mysql_database_name = "${name}", - $mysql_user = "${name}", + $mysql_database_name = $name, + $mysql_user = $name, $mysql_grantfilepath = '/root/puppet/mysql', $system_create_user = true, $system_user_homedir_mode = '0711', $system_user_uid = '', $system_user_tag = 'vhosts', - $system_username = "${name}", + $system_username = $name, $system_username_password = absent, $webserver_aliases = '', $webserver_documentroot = "/home/vhosts/${name}/public_html/", $webserver_create_documentroot = true, $webserver_template = 'virtualhost.conf.erb', - $webserver_template_path = "deploy_php/apache", - $application = '' - ) { + $webserver_template_path = 'deploy_php/apache', + $application = '' +) { $bool_system_create_user=any2bool($system_create_user) - $real_mysql_database_name = replacedot("${mysql_database_name}") - + $real_mysql_database_name = replacedot($mysql_database_name) if strlength($mysql_user) > 16 { - $real_mysql_user = changelength(replacedot("${mysql_user}"), '15') + $real_mysql_user = changelength(replacedot($mysql_user), '15') } else { - $real_mysql_user = replacedot($mysql_user) + $real_mysql_user = replacedot($mysql_user) } if strlength($system_username) > 32 { - $real_system_username_length = changelength($system_username, '31') + $real_system_username_length = changelength($system_username, '31') } else { - $real_system_username_length = $system_username + $real_system_username_length = $system_username } $real_system_user_uid = $system_user_uid ? { @@ -39,80 +40,77 @@ } $real_mysql_password = $mysql_password ? { - '' => "${name}", + '' => $name, default => $mysql_password, } $real_system_username = $bool_system_create_user ? { false => $real_system_username_length ? { - "$name" => 'www-data', - default => "${real_system_username_length}", + $name => 'www-data', + default => $real_system_username_length, }, - default => "${real_system_username_length}", + default => $real_system_username_length, } $real_webserver_template_path = $webserver_template ? { - "virtualhost.conf.erb" => "deploy_php/apache", - default => "hosts/$fqdn/apache", + 'virtualhost.conf.erb' => 'deploy_php/apache', + default => "hosts/${::fqdn}/apache", } if $system_create_user == true { - user::managed { "${real_system_username}": - name_comment => "${name}", + user::managed { $real_system_username: + name_comment => $name, homedir => "/home/vhosts/${name}", managehome => true, - password => "${system_username_password}", + password => $system_username_password, password_crypted => false, - uid => "${real_system_user_uid}", - homedir_mode => "${system_user_homedir_mode}", - tag => "${system_user_tag}", - password_salt => "65941380", - require => File["${deploy_php::dir_path_webserver}"], + uid => $real_system_user_uid, + homedir_mode => $system_user_homedir_mode, + tag => $system_user_tag, + password_salt => '65941380', + require => File[$deploy_php::dir_path_webserver], } - apache::virtualhost { "${name}": - aliases => "www.${name} $webserver_aliases", - documentroot => "$webserver_documentroot", - require => User["${real_system_username}"], - owner => "${real_system_username}", - groupowner => "${real_system_username}", - templatepath => "${real_webserver_template_path}", - templatefile => "${webserver_template}", - create_docroot => "${webserver_create_documentroot}", - } - } else { - apache::virtualhost { "${name}": - aliases => "www.${name} $webserver_aliases", - documentroot => "$webserver_documentroot", - templatepath => "${webserver_template_path}", - templatefile => "${webserver_template}", - owner => "${real_system_username}", - groupowner => "${real_system_username}", - create_docroot => "${webserver_create_documentroot}", - } + apache::virtualhost { $name: + aliases => "www.${name} ${webserver_aliases}", + documentroot => $webserver_documentroot, + require => User[$real_system_username], + owner => $real_system_username, + groupowner => $real_system_username, + templatepath => $real_webserver_template_path, + templatefile => $webserver_template, + create_docroot => $webserver_create_documentroot, + } +} else { + apache::virtualhost { $name: + aliases => "www.${name} ${webserver_aliases}", + documentroot => $webserver_documentroot, + templatepath => $webserver_template_path, + templatefile => $webserver_template, + owner => $real_system_username, + groupowner => $real_system_username, + create_docroot => $webserver_create_documentroot, } - +} if $createdb == true { - require mysql - - mysql::grant { "${real_mysql_database_name}": - mysql_db => "${real_mysql_database_name}", - mysql_user => "${real_mysql_user}", - mysql_password => "${real_mysql_password}", + mysql::grant { $real_mysql_database_name: + mysql_db => $real_mysql_database_name, + mysql_user => $real_mysql_user, + mysql_password => $real_mysql_password, mysql_privileges => 'ALL', mysql_host => 'localhost', - mysql_grant_filepath => "${mysql_grantfilepath}", + mysql_grant_filepath => $mysql_grantfilepath, } } - if $application == 'wordpress' { - deploy_php::app::wordpress::v1 { "${real_system_username}": - db => "${real_mysql_database_name}", - db_user => "${real_mysql_user}", - db_pass => "${real_mysql_password}", - db_host => 'localhost', - require => User::Managed["${real_system_username}"] - } - } + if $application == 'wordpress' { + deploy_php::app::wordpress::v1 { $real_system_username: + db => $real_mysql_database_name, + db_user => $real_mysql_user, + db_pass => $real_mysql_password, + db_host => 'localhost', + require => User::Managed[$real_system_username] + } + } } diff --git a/manifests/app/wordpress/v1.pp b/manifests/app/wordpress/v1.pp index 7a5470c..93a2681 100644 --- a/manifests/app/wordpress/v1.pp +++ b/manifests/app/wordpress/v1.pp @@ -1,3 +1,5 @@ +#Define deploy_php::app::wordpress::v1 +# define deploy_php::app::wordpress::v1 ( $db, $db_user, @@ -7,50 +9,51 @@ $complete_path = "/home/vhosts/${name}/public_html/", $directory = "/root/puppet/wordpress/${name}", $which_server = 'nginx', - $groups = $title ) { + $groups = $title +) { - $auth_key = sha1("auth_key$name") - $secure_auth_key = sha1("secure_auth_key$name") - $logged_in_key = sha1("logged_in_key$name") - $nonce_key = sha1("nonce_key$name") - $auth_salt = sha1("auth_salt$name") - $secure_auth_salt = sha1("secure_auth_salt$name") - $logged_in_salt = sha1("logged_in_salt$name") - $nonce_salt = sha1("nonce_salt$name") + $auth_key = sha1("auth_key${name}") + $secure_auth_key = sha1("secure_auth_key${name}") + $logged_in_key = sha1("logged_in_key${name}") + $nonce_key = sha1("nonce_key${name}") + $auth_salt = sha1("auth_salt${name}") + $secure_auth_salt = sha1("secure_auth_salt${name}") + $logged_in_salt = sha1("logged_in_salt${name}") + $nonce_salt = sha1("nonce_salt${name}") if $which_server == 'apache2' { $groups = 'www-data' file { "${complete_path}.htaccess": - ensure => "file", - group => "${groups}", - mode => "0755", + ensure => 'file', + group => $groups, + mode => '0755', } } - - file { "${directory}": - ensure => directory, - owner => "root", - group => "root", + + file { $directory: + ensure => directory, + owner => 'root', + group => 'root', } puppi::netinstall { "netinstall_wordpress_${user_name}_${name}": - url => "http://wordpress.org/latest.tar.gz", + url => 'http://wordpress.org/latest.tar.gz', extract_command => 'tar --strip-components 1 -zxf', destination_dir => "${directory}/install", - extracted_dir => ".", - owner => "${user_name}", - group => "${user_name}", - preextract_command => "", + extracted_dir => '.', + owner => $user_name, + group => $user_name, + preextract_command => '', postextract_command => "[ -d ${complete_path} ] || mkdir ${complete_path} && mv ${directory}/install/* ${complete_path}", - work_dir => "${directory}", - require => File["${directory}"], - } + work_dir => $directory, + require => File[$directory], + } file { "${complete_path}wp-config.php": content => template('deploy_php/wordpress/wp-config.php.erb'), - mode => "0755", - owner => "${user_name}", - group => "${user_name}", + mode => '0755', + owner => $user_name, + group => $user_name, replace => false, require => Puppi::Netinstall["netinstall_wordpress_${user_name}_${name}"], } diff --git a/manifests/environments/environment_apache.pp b/manifests/environments/environment_apache.pp index 597097c..dc51411 100644 --- a/manifests/environments/environment_apache.pp +++ b/manifests/environments/environment_apache.pp @@ -1,29 +1,30 @@ +#Class deploy_php::environments::environment_apache +# class deploy_php::environments::environment_apache ( ) { - apache::module { "${deploy_php::apache_module}": - install_package => true, + apache::module { $deploy_php::apache_module: + install_package => true, } - $restart_service = $::operatingsystem ? { - /(?i:Debian|Ubuntu|Mint)/ => 'apache2', - default => 'httpd', + $restart_service = $::operatingsystem ? { + /(?i:Debian|Ubuntu|Mint)/ => 'apache2', + default => 'httpd', } + if $deploy_php::apache_module == 'suphp' { - if $deploy_php::apache_module == "suphp" { - - file {"/etc/suphp/suphp.conf": - content => template ("${deploy_php::template_suphp_conf}"), + file {'/etc/suphp/suphp.conf': ensure => present, + content => template ($deploy_php::template_suphp_conf), require => Package["ApacheModule_${deploy_php::apache_module}"], - notify => Service["${restart_service}"], + notify => Service[$restart_service], } - file {"/etc/apache2/mods-available/suphp.conf": - content => template ("${deploy_php::template_suphp_mod}"), + file {'/etc/apache2/mods-available/suphp.conf': ensure => present, + content => template ($deploy_php::template_suphp_mod), require => Package["ApacheModule_${deploy_php::apache_module}"], - notify => Service["${restart_service}"], + notify => Service[$restart_service], } } diff --git a/manifests/environments/environment_nginx.pp b/manifests/environments/environment_nginx.pp index 265cd4f..36187c9 100644 --- a/manifests/environments/environment_nginx.pp +++ b/manifests/environments/environment_nginx.pp @@ -1,11 +1,8 @@ +#Class deploy_php::environments::environment_nginx +# class deploy_php::environments::environment_nginx { - package { [ "libpcre3", - "php5-common", - "libmysqlclient-dev", - "libmysqlclient18", - "php5-mcrypt"]: - ensure => installed, - } - + package { ['libpcre3','php5-common','libmysqlclient-dev','libmysqlclient18','php5-mcrypt']: + ensure => installed, + } } diff --git a/manifests/init.pp b/manifests/init.pp index 2015fc4..3676d3e 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -10,23 +10,21 @@ # on the stdmod parameters used # class deploy_php ( - - $webserver_name = params_lookup('webserver_name'), - $apache_module = params_lookup ('apache_module'), - $template_php_ini = params_lookup('template_php_ini'), - $template_suphp_conf = params_lookup('template_suphp_conf'), - $template_suphp_mod = params_lookup('template_suphp_mod') - - - ) inherits deploy_php::params { + $webserver_name = params_lookup('webserver_name'), + $apache_module = params_lookup ('apache_module'), + $template_php_ini = params_lookup('template_php_ini'), + $template_suphp_conf = params_lookup('template_suphp_conf'), + $template_suphp_mod = params_lookup('template_suphp_mod') +) inherits deploy_php::params { include $deploy_php::webserver_name - if $deploy_php::webserver_name == 'nginx' { - include php5fpm - } else { - if $deploy_php::apache_module == 'suphp' or $deploy_php::apache_module == 'php5' { - include deploy_php::environments::environment_apache - } - } + if $deploy_php::webserver_name == 'nginx' { + include php5fpm + } else { + if $deploy_php::apache_module == 'suphp' or $deploy_php::apache_module == 'php5' { + include deploy_php::environments::environment_apache + } + } + } diff --git a/manifests/nginx.pp b/manifests/nginx.pp index 0a77bd4..f00e2e2 100755 --- a/manifests/nginx.pp +++ b/manifests/nginx.pp @@ -1,9 +1,11 @@ +#Define deploy_php::nginx +# define deploy_php::nginx ( $createdb = true, $mysql_password = '', $mysql_grantfilepath = '/root/puppet/mysql', - $mysql_database_name = "${name}", - $mysql_user = "${name}", + $mysql_database_name = $name, + $mysql_user = $name, $php_display_errors = 'off', $php_log_errors = 'off', $php_max_execution_time = '0', @@ -14,13 +16,13 @@ $php_pm_max_spare_servers = '35', $php_pm_min_spare_servers = '5', $php_pm_start_servers = '20', - $php_process_manager = "static", + $php_process_manager = 'static', $php_request_slowlog_timeout = '0', $system_create_user = true, $system_user_homedir_mode = '0711', $system_user_uid = '', $system_user_tag = 'vhosts', - $system_username = "${name}", + $system_username = $name, $system_username_password = absent, $webserver_aliases = '', $webserver_documentroot = "/home/vhosts/${name}/public_html/", @@ -32,22 +34,22 @@ $webserver_redirect_www = true, $webserver_site_priority = '50', $webserver_template = 'deploy_php/nginx/vhost.conf.erb', - $application = '' - ) { + $application = '' +) { - $bool_system_create_user = any2bool($system_create_user) - $real_mysql_database_name = replacedot("${mysql_database_name}") + $bool_system_create_user = any2bool($system_create_user) + $real_mysql_database_name = replacedot($mysql_database_name) if strlength($mysql_user) > 16 { - $real_mysql_user = changelength(replacedot("${mysql_user}"), '15') + $real_mysql_user = changelength(replacedot($mysql_user), '15') } else { - $real_mysql_user = replacedot($mysql_user) + $real_mysql_user = replacedot($mysql_user) } if strlength($system_username) > 32 { - $real_system_username_length = changelength($system_username, '31') + $real_system_username_length = changelength($system_username, '31') } else { - $real_system_username_length = $system_username + $real_system_username_length = $system_username } $real_system_user_uid = $system_user_uid ? { @@ -56,104 +58,102 @@ } $real_mysql_password = $mysql_password ? { - '' => "${name}", + '' => $name, default => $mysql_password, } $real_system_username = $bool_system_create_user ? { false => $real_system_username_length ? { - "$name" => 'www-data', - default => "${real_system_username_length}", + $name => 'www-data', + default => $real_system_username_length, }, - default => "${real_system_username_length}", + default => $real_system_username_length, } if $system_create_user == true { - user::managed { "${real_system_username}": - name_comment => "${name}", + user::managed { $real_system_username: + name_comment => $name, homedir => "/home/vhosts/${name}", managehome => true, - password => "${system_username_password}", + password => $system_username_password, password_crypted => false, - uid => "${real_system_user_uid}", - homedir_mode => "${system_user_homedir_mode}", - tag => "${system_user_tag}", - password_salt => "65941380", - require => File["${deploy_php::dir_path_webserver}"], + uid => $real_system_user_uid, + homedir_mode => $system_user_homedir_mode, + tag => $system_user_tag, + password_salt => '65941380', + require => File[$deploy_php::dir_path_webserver], } - nginx::vhost { "${name}": - template => "${webserver_template}", - docroot => "$webserver_documentroot", - require => User["${real_system_username}"], - serveraliases => "${webserver_aliases}", - owner => "${real_system_username}", - groupowner => "${real_system_username}", - create_docroot => "${webserver_create_documentroot}", - port => "${webserver_port}", - priority => "${webserver_site_priority}", + nginx::vhost { $name: + template => $webserver_template, + docroot => $webserver_documentroot, + require => User[$real_system_username], + serveraliases => $webserver_aliases, + owner => $real_system_username, + groupowner => $real_system_username, + create_docroot => $webserver_create_documentroot, + port => $webserver_port, + priority => $webserver_site_priority, } } else { - nginx::vhost { "${name}": - template => "${webserver_template}", - docroot => "$webserver_documentroot", - serveraliases => "${$webserver_aliases}", - owner => "${real_system_username}", - groupowner => "${real_system_username}", - create_docroot => "${webserver_create_documentroot}", - port => "${webserver_port}", - priority => "${webserver_site_priority}", + nginx::vhost { $name: + template => $webserver_template, + docroot => $webserver_documentroot, + serveraliases => $webserver_aliases, + owner => $real_system_username, + groupowner => $real_system_username, + create_docroot => $webserver_create_documentroot, + port => $webserver_port, + priority => $webserver_site_priority, } } if $webserver_php == true { - require deploy_php::environments::environment_nginx - - php5fpm::config { "${name}": + require deploy_php::environments::environment_nginx + php5fpm::config { $name: ensure => present, - owner => "${real_system_username}", - content => "${$webserver_phpfpm_template}", - display_errors => "${php_display_errors}", - log_errors => "${php_log_errors}", - memory_limit => "${php_memory_limit}", - max_execution_time => "${php_max_execution_time}", - process_manager => "${php_process_manager}", - pm_max_children => "${php_pm_max_children}", - pm_max_requests => "${php_pm_max_requests}", - pm_start_servers => "${php_pm_start_servers}", - pm_min_spare_servers => "${php_pm_min_spare_servers}", - pm_max_spare_servers => "${php_pm_max_spare_servers}", - request_slowlog_timeout => "${php_request_slowlog_timeout}", + owner => $real_system_username, + content => $webserver_phpfpm_template, + display_errors => $php_display_errors, + log_errors => $php_log_errors, + memory_limit => $php_memory_limit, + max_execution_time => $php_max_execution_time, + process_manager => $php_process_manager, + pm_max_children => $php_pm_max_children, + pm_max_requests => $php_pm_max_requests, + pm_start_servers => $php_pm_start_servers, + pm_min_spare_servers => $php_pm_min_spare_servers, + pm_max_spare_servers => $php_pm_max_spare_servers, + request_slowlog_timeout => $php_request_slowlog_timeout, } } if $createdb == true { require mysql - - mysql::grant { "${real_mysql_database_name}": - mysql_db => "${real_mysql_database_name}", - mysql_user => "${real_mysql_user}", - mysql_password => "${real_mysql_password}", + mysql::grant { $real_mysql_database_name: + mysql_db => $real_mysql_database_name, + mysql_user => $real_mysql_user, + mysql_password => $real_mysql_password, mysql_privileges => 'ALL', mysql_host => 'localhost', - mysql_grant_filepath => "${mysql_grantfilepath}", + mysql_grant_filepath => $mysql_grantfilepath, + } + } + + if $application == 'wordpress' { + deploy_php::app::wordpress::v1 { $real_system_username: + db => $real_mysql_database_name, + db_user => $real_mysql_user, + db_pass => $real_mysql_password, + db_host => 'localhost', + require => User::Managed [$real_system_username] } - } - - if $application == 'wordpress' { - deploy_php::app::wordpress::v1 { "${real_system_username}": - db => "${real_mysql_database_name}", - db_user => "${real_mysql_user}", - db_pass => "${real_mysql_password}", - db_host => 'localhost', - require => User::Managed ["${real_system_username}"] - } - } + } } diff --git a/manifests/params.pp b/manifests/params.pp index 6be5074..b5785dd 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -4,29 +4,23 @@ # class deploy_php::params { - $webserver_name = "nginx" - $dir_path_webserver = "/home/vhosts" - $apache_module = "suphp" - $template_php_ini = "deploy_php/php.ini.erb" - $template_suphp_conf = "deploy_php/suphp/suphp.conf" - $template_suphp_mod = "deploy_php/suphp/suphp.conf-module" - - file { "${dir_path_webserver}": - ensure => directory, - } - - file { ["/root/puppet/","/root/puppet/wordpress"]: - ensure => directory, - } + $webserver_name = 'nginx' + $dir_path_webserver = '/home/vhosts' + $apache_module = 'suphp' + $template_php_ini = 'deploy_php/php.ini.erb' + $template_suphp_conf = 'deploy_php/suphp/suphp.conf' + $template_suphp_mod = 'deploy_php/suphp/suphp.conf-module' - package { [ 'php5-mysql', - 'php5-curl', - 'php5-cli', - 'php5-gd', - ]: - ensure => installed, + file { $dir_path_webserver: + ensure => directory, } + file { ['/root/puppet/','/root/puppet/wordpress']: + ensure => directory, + } + package { ['php5-mysql','php5-curl','php5-cli','php5-gd']: + ensure => installed, + } } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 463f27a..5ffb32a 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -2,133 +2,5 @@ describe 'deploy_php' do - context 'Supported OS - ' do - ['Debian', 'RedHat'].each do |osfamily| - describe "#{osfamily} standard installation" do - let(:params) {{ }} - let(:facts) {{ - :osfamily => osfamily, - }} - it { should contain_package('deploy_php').with_ensure('present') } - it { should contain_service('deploy_php').with_ensure('running') } - end - - describe "#{osfamily} installation of a specific package version" do - let(:params) { { - :package_ensure => '1.0.42', - } } - let(:facts) {{ - :osfamily => osfamily, - }} - it { should contain_package('deploy_php').with_ensure('1.0.42') } - end - - describe "#{osfamily} removal of package installation" do - let(:params) { { - :package_ensure => 'absent', - } } - let(:facts) {{ - :osfamily => osfamily, - }} - it 'should remove Package[deploy_php]' do should contain_package('deploy_php').with_ensure('absent') end - it 'should stop Service[deploy_php]' do should contain_service('deploy_php').with_ensure('stopped') end - it 'should not manage at boot Service[deploy_php]' do should contain_service('deploy_php').with_enable(nil) end - it 'should remove deploy_php configuration file' do should contain_file('deploy_php.conf').with_ensure('absent') end - end - - describe "#{osfamily} service disabling" do - let(:params) { { - :service_ensure => 'stopped', - :service_enable => false, - } } - let(:facts) {{ - :osfamily => osfamily, - }} - it 'should stop Service[deploy_php]' do should contain_service('deploy_php').with_ensure('stopped') end - it 'should not enable at boot Service[deploy_php]' do should contain_service('deploy_php').with_enable('false') end - end - - describe "#{osfamily} configuration via custom template" do - let(:params) { { - :config_file_template => 'deploy_php/spec.conf', - :config_file_options_hash => { 'opt_a' => 'value_a' }, - } } - let(:facts) {{ - :osfamily => osfamily, - }} - it { should contain_file('deploy_php.conf').with_content(/This is a template used only for rspec tests/) } - it 'should generate a template that uses custom options' do - should contain_file('deploy_php.conf').with_content(/value_a/) - end - end - - describe "#{osfamily} configuration via custom content" do - let(:params) { { - :config_file_content => 'my_content', - } } - let(:facts) {{ - :osfamily => osfamily, - }} - it { should contain_file('deploy_php.conf').with_content(/my_content/) } - end - - describe "#{osfamily} configuration via custom source file" do - let(:params) { { - :config_file_source => "puppet:///modules/deploy_php/spec.conf", - } } - let(:facts) {{ - :osfamily => osfamily, - }} - it { should contain_file('deploy_php.conf').with_source('puppet:///modules/deploy_php/spec.conf') } - end - - describe "#{osfamily} configuration via custom source dir" do - let(:params) { { - :config_dir_source => 'puppet:///modules/deploy_php/tests/', - :config_dir_purge => true - } } - let(:facts) {{ - :osfamily => osfamily, - }} - it { should contain_file('deploy_php.dir').with_source('puppet:///modules/deploy_php/tests/') } - it { should contain_file('deploy_php.dir').with_purge('true') } - it { should contain_file('deploy_php.dir').with_force('true') } - end - - describe "#{osfamily} service restart on config file change (default)" do - let(:facts) {{ - :osfamily => osfamily, - }} - it 'should automatically restart the service when files change' do - should contain_file('deploy_php.conf').with_notify('Service[deploy_php]') - end - end - - describe "#{osfamily} service restart disabling on config file change" do - let(:params) { { - :config_file_notify => '', - } } - let(:facts) {{ - :osfamily => osfamily, - }} - it 'should automatically restart the service when files change' do - should contain_file('deploy_php.conf').without_notify - end - end - - end - end - - context 'Unsupported OS - ' do - describe 'Not supported operating systems should throw and error' do - let(:facts) {{ - :osfamily => 'Solaris', - :operatingsystem => 'Nexenta', - }} - - it { expect { should }.to raise_error(Puppet::Error, /Nexenta not supported/) } - end - end - end From 0e583d9bed00e96d0ca21f8155e89d5ca76a993a Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Wed, 25 Jun 2014 14:31:44 -0300 Subject: [PATCH 03/18] Add some tests --- .fixtures.yml | 4 ++++ manifests/environments/environment_apache.pp | 4 ++-- manifests/init.pp | 14 +++++++------- .../environments_environment_apache_spec.rb | 7 +++++++ spec/classes/init_spec.rb | 15 ++++++++++++++- 5 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 spec/classes/environments_environment_apache_spec.rb diff --git a/.fixtures.yml b/.fixtures.yml index f00c56f..eb598e9 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -2,5 +2,9 @@ fixtures: repositories: stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git" stdmod: "git://github.com/stdmod/stdmod.git" + nginx: "https://github.com/netmanagers/puppet-nginx.git" + apache: "https://github.com/example42/puppet-apache" + php5fpm: "https://github.com/zertico/puppet-php5fpm.git" + puppi: "https://github.com/example42/puppi" symlinks: deploy_php: "#{source_dir}" diff --git a/manifests/environments/environment_apache.pp b/manifests/environments/environment_apache.pp index dc51411..75657f9 100644 --- a/manifests/environments/environment_apache.pp +++ b/manifests/environments/environment_apache.pp @@ -1,6 +1,6 @@ -#Class deploy_php::environments::environment_apache +#Class: deploy_php::environments::environment_apache # -class deploy_php::environments::environment_apache ( ) { +class deploy_php::environments::environment_apache () { apache::module { $deploy_php::apache_module: install_package => true, diff --git a/manifests/init.pp b/manifests/init.pp index 3676d3e..08ab6e4 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -10,20 +10,20 @@ # on the stdmod parameters used # class deploy_php ( - $webserver_name = params_lookup('webserver_name'), - $apache_module = params_lookup ('apache_module'), - $template_php_ini = params_lookup('template_php_ini'), - $template_suphp_conf = params_lookup('template_suphp_conf'), - $template_suphp_mod = params_lookup('template_suphp_mod') + $webserver_name = $deploy_php::webserver_name, + $apache_module = $deploy_php::apache_module, + $template_php_ini = $deploy_php::template_php_ini, + $template_suphp_conf = $deploy_php::template_suphp_conf, + $template_suphp_mod = $deploy_php::template_suphp_conf ) inherits deploy_php::params { - include $deploy_php::webserver_name + include $webserver_name if $deploy_php::webserver_name == 'nginx' { include php5fpm } else { if $deploy_php::apache_module == 'suphp' or $deploy_php::apache_module == 'php5' { - include deploy_php::environments::environment_apache + class { 'deploy_php::environments::environment_apache': } } } diff --git a/spec/classes/environments_environment_apache_spec.rb b/spec/classes/environments_environment_apache_spec.rb new file mode 100644 index 0000000..cc86a85 --- /dev/null +++ b/spec/classes/environments_environment_apache_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +describe 'deploy_php::environments::environment_apache' do +# it do should contain_file('/etc/suphp/suphp.conf') +# end +end + diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 5ffb32a..b97568f 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,6 +1,19 @@ require 'spec_helper' describe 'deploy_php' do - + context 'testing with nginx' do + let(:params) {{ :webserver_name => 'nginx' }} + it do should contain_class('nginx') + end + it do should contain_class('php5fpm') + end + end + context 'testing with apache and suphp' do + let(:params) {{:webserver_name => 'apache', :apache_module => 'su_php' }} + it do should contain_class('apache') + end +# it { should contain_class('deploy_php::environments::environment_apache') } + + end end From 3393e053acf324c9cb725ea047f634bb5718744b Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Wed, 25 Jun 2014 14:46:14 -0300 Subject: [PATCH 04/18] add joomla --- manifests/app/joomla/v1.pp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 manifests/app/joomla/v1.pp diff --git a/manifests/app/joomla/v1.pp b/manifests/app/joomla/v1.pp new file mode 100644 index 0000000..9dc57d1 --- /dev/null +++ b/manifests/app/joomla/v1.pp @@ -0,0 +1,26 @@ +#Define deploy_php::app::joomla::v1 +# +define deploy_php::app::joomla::v1 ( + $complete_path = "/home/vhosts/${name}/public_html/", + $directory = "/root/puppet/joomla/${name}", +){ + + file { $directory: + ensure => directory, + owner => 'root', + group => 'root', + } + + puppi::netinstall { "netinstall_joomla_${name}": + url => 'http://joomlacode.org/gf/download/frsrelease/19239/158104/Joomla_3.2.3-Stable-Full_Package.zip', + extract_command => 'unzip', + destination_dir => "${directory}/install", + extracted_dir => '.', + owner => $name, + group => $name, + preextract_command => '', + postextract_command => "[ -d ${complete_path} ] || mkdir ${complete_path} && mv ${directory}/install/* ${complete_path}", + work_dir => $directory, + require => File[$directory], + } +} From ea13640c07883f7c15fccc2266f645dcfe9d76ef Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Wed, 25 Jun 2014 15:26:02 -0300 Subject: [PATCH 05/18] Add cake to deploy_php --- manifests/framework/cake/v1.pp | 55 ++++ manifests/nginx.pp | 18 +- templates/framework/cake/core.php.erb | 385 ++++++++++++++++++++++ templates/framework/cake/database.php.erb | 85 +++++ templates/framework/cake/htaccess | 5 + 5 files changed, 547 insertions(+), 1 deletion(-) create mode 100644 manifests/framework/cake/v1.pp create mode 100644 templates/framework/cake/core.php.erb create mode 100644 templates/framework/cake/database.php.erb create mode 100644 templates/framework/cake/htaccess diff --git a/manifests/framework/cake/v1.pp b/manifests/framework/cake/v1.pp new file mode 100644 index 0000000..3403e62 --- /dev/null +++ b/manifests/framework/cake/v1.pp @@ -0,0 +1,55 @@ +#Define deploy_php::framework::cake::v1 +# +define deploy_php::framework::cake::v1 ( + $db_name = '', + $db_user = '', + $db_pass = '', + $directory = "/root/puppet/cake/${name}", + $complete_path = "/home/vhosts/${name}/public_html/", + $random = fqdn_rand(1000000,$name), +) { + + file { $directory: + ensure => directory, + owner => 'root', + group => 'root', + } + + puppi::netinstall { "netinstall_cake_${name}": + url => 'https://github.com/cakephp/cakephp/zipball/2.4.9', + extract_command => 'unzip', + destination_dir => "${directory}/install", + extracted_dir => '.', + owner => $name, + group => $name, + preextract_command => '', + postextract_command => "[ -d ${complete_path} ]||mkdir ${complete_path} &&mv ${directory}/install/cakephp-cakephp-06714e9/* ${complete_path}", + work_dir => $directory, + require => File[$directory], + } + + file { "${complete_path}app/Config/core.php": + ensure => present, + owner => $name, + group => $name, + content => template('deploy_php/framework/cake/core.php.erb'), + require => Puppi::Netinstall["netinstall_cake_${name}"], + } + + file { "${complete_path}app/Config/database.php": + ensure => present, + owner => $name, + group => $name, + content => template('deploy_php/framework/cake/database.php.erb'), + require => Puppi::Netinstall["netinstall_cake_${name}"], + } + + file { "${complete_path}.htaccess": + ensure => present, + owner => $name, + group => $name, + content => template('deploy_php/framework/cake/htaccess'), + require => Puppi::Netinstall["netinstall_cake_${name}"], + } + +} diff --git a/manifests/nginx.pp b/manifests/nginx.pp index f00e2e2..d80484d 100755 --- a/manifests/nginx.pp +++ b/manifests/nginx.pp @@ -34,7 +34,8 @@ $webserver_redirect_www = true, $webserver_site_priority = '50', $webserver_template = 'deploy_php/nginx/vhost.conf.erb', - $application = '' + $application = '', + $framework = '' ) { $bool_system_create_user = any2bool($system_create_user) @@ -156,4 +157,19 @@ } } + if $application == 'joomla' { + deploy_php::app::joomla::v1 { $real_system_username: + require => User::Managed[$real_system_username] + } + } + + if $framework == 'cake' { + deploy_php::app::cake::v1 { $real_system_username: + db_name => $real_mysql_database_name, + db_user => $real_mysql_user, + db_pass => $real_mysql_password, + require => User::Managed[$real_system_username] + } + } + } diff --git a/templates/framework/cake/core.php.erb b/templates/framework/cake/core.php.erb new file mode 100644 index 0000000..8bd1a3c --- /dev/null +++ b/templates/framework/cake/core.php.erb @@ -0,0 +1,385 @@ + 0 + * and log errors with CakeLog when debug = 0. + * + * Options: + * + * - `handler` - callback - The callback to handle errors. You can set this to any callable type, + * including anonymous functions. + * Make sure you add App::uses('MyHandler', 'Error'); when using a custom handler class + * - `level` - integer - The level of errors you are interested in capturing. + * - `trace` - boolean - Include stack traces for errors in log files. + * + * @see ErrorHandler for more information on error handling and configuration. + */ + Configure::write('Error', array( + 'handler' => 'ErrorHandler::handleError', + 'level' => E_ALL & ~E_DEPRECATED, + 'trace' => true + )); + +/** + * Configure the Exception handler used for uncaught exceptions. By default, + * ErrorHandler::handleException() is used. It will display a HTML page for the exception, and + * while debug > 0, framework errors like Missing Controller will be displayed. When debug = 0, + * framework errors will be coerced into generic HTTP errors. + * + * Options: + * + * - `handler` - callback - The callback to handle exceptions. You can set this to any callback type, + * including anonymous functions. + * Make sure you add App::uses('MyHandler', 'Error'); when using a custom handler class + * - `renderer` - string - The class responsible for rendering uncaught exceptions. If you choose a custom class you + * should place the file for that class in app/Lib/Error. This class needs to implement a render method. + * - `log` - boolean - Should Exceptions be logged? + * - `skipLog` - array - list of exceptions to skip for logging. Exceptions that + * extend one of the listed exceptions will also be skipped for logging. + * Example: `'skipLog' => array('NotFoundException', 'UnauthorizedException')` + * + * @see ErrorHandler for more information on exception handling and configuration. + */ + Configure::write('Exception', array( + 'handler' => 'ErrorHandler::handleException', + 'renderer' => 'ExceptionRenderer', + 'log' => true + )); + +/** + * Application wide charset encoding + */ + Configure::write('App.encoding', 'UTF-8'); + +/** + * To configure CakePHP *not* to use mod_rewrite and to + * use CakePHP pretty URLs, remove these .htaccess + * files: + * + * /.htaccess + * /app/.htaccess + * /app/webroot/.htaccess + * + * And uncomment the App.baseUrl below. But keep in mind + * that plugin assets such as images, CSS and JavaScript files + * will not work without URL rewriting! + * To work around this issue you should either symlink or copy + * the plugin assets into you app's webroot directory. This is + * recommended even when you are using mod_rewrite. Handling static + * assets through the Dispatcher is incredibly inefficient and + * included primarily as a development convenience - and + * thus not recommended for production applications. + */ + //Configure::write('App.baseUrl', env('SCRIPT_NAME')); + +/** + * To configure CakePHP to use a particular domain URL + * for any URL generation inside the application, set the following + * configuration variable to the http(s) address to your domain. This + * will override the automatic detection of full base URL and can be + * useful when generating links from the CLI (e.g. sending emails) + */ + //Configure::write('App.fullBaseUrl', 'http://example.com'); + +/** + * Web path to the public images directory under webroot. + * If not set defaults to 'img/' + */ + //Configure::write('App.imageBaseUrl', 'img/'); + +/** + * Web path to the CSS files directory under webroot. + * If not set defaults to 'css/' + */ + //Configure::write('App.cssBaseUrl', 'css/'); + +/** + * Web path to the js files directory under webroot. + * If not set defaults to 'js/' + */ + //Configure::write('App.jsBaseUrl', 'js/'); + +/** + * Uncomment the define below to use CakePHP prefix routes. + * + * The value of the define determines the names of the routes + * and their associated controller actions: + * + * Set to an array of prefixes you want to use in your application. Use for + * admin or other prefixed routes. + * + * Routing.prefixes = array('admin', 'manager'); + * + * Enables: + * `admin_index()` and `/admin/controller/index` + * `manager_index()` and `/manager/controller/index` + * + */ + //Configure::write('Routing.prefixes', array('admin')); + +/** + * Turn off all caching application-wide. + * + */ + //Configure::write('Cache.disable', true); + +/** + * Enable cache checking. + * + * If set to true, for view caching you must still use the controller + * public $cacheAction inside your controllers to define caching settings. + * You can either set it controller-wide by setting public $cacheAction = true, + * or in each action using $this->cacheAction = true. + * + */ + //Configure::write('Cache.check', true); + +/** + * Enable cache view prefixes. + * + * If set it will be prepended to the cache name for view file caching. This is + * helpful if you deploy the same application via multiple subdomains and languages, + * for instance. Each version can then have its own view cache namespace. + * Note: The final cache file name will then be `prefix_cachefilename`. + */ + //Configure::write('Cache.viewPrefix', 'prefix'); + +/** + * Session configuration. + * + * Contains an array of settings to use for session configuration. The defaults key is + * used to define a default preset to use for sessions, any settings declared here will override + * the settings of the default config. + * + * ## Options + * + * - `Session.cookie` - The name of the cookie to use. Defaults to 'CAKEPHP' + * - `Session.timeout` - The number of minutes you want sessions to live for. This timeout is handled by CakePHP + * - `Session.cookieTimeout` - The number of minutes you want session cookies to live for. + * - `Session.checkAgent` - Do you want the user agent to be checked when starting sessions? You might want to set the + * value to false, when dealing with older versions of IE, Chrome Frame or certain web-browsing devices and AJAX + * - `Session.defaults` - The default configuration set to use as a basis for your session. + * There are four builtins: php, cake, cache, database. + * - `Session.handler` - Can be used to enable a custom session handler. Expects an array of callables, + * that can be used with `session_save_handler`. Using this option will automatically add `session.save_handler` + * to the ini array. + * - `Session.autoRegenerate` - Enabling this setting, turns on automatic renewal of sessions, and + * sessionids that change frequently. See CakeSession::$requestCountdown. + * - `Session.ini` - An associative array of additional ini values to set. + * + * The built in defaults are: + * + * - 'php' - Uses settings defined in your php.ini. + * - 'cake' - Saves session files in CakePHP's /tmp directory. + * - 'database' - Uses CakePHP's database sessions. + * - 'cache' - Use the Cache class to save sessions. + * + * To define a custom session handler, save it at /app/Model/Datasource/Session/.php. + * Make sure the class implements `CakeSessionHandlerInterface` and set Session.handler to + * + * To use database sessions, run the app/Config/Schema/sessions.php schema using + * the cake shell command: cake schema create Sessions + * + */ + Configure::write('Session', array( + 'defaults' => 'php' + )); + +/** + * A random string used in security hashing methods. + */ + Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2gu<%= random %>VoUubWwvniR2G0FgaC9mi'); + +/** + * A random numeric string (digits only) used to encrypt/decrypt strings. + */ + Configure::write('Security.cipherSeed', '7685930965745<%= random %>3542496749683645'); + +/** + * Apply timestamps with the last modified time to static assets (js, css, images). + * Will append a query string parameter containing the time the file was modified. This is + * useful for invalidating browser caches. + * + * Set to `true` to apply timestamps when debug > 0. Set to 'force' to always enable + * timestamping regardless of debug value. + */ + //Configure::write('Asset.timestamp', true); + +/** + * Compress CSS output by removing comments, whitespace, repeating tags, etc. + * This requires a/var/cache directory to be writable by the web server for caching. + * and /vendors/csspp/csspp.php + * + * To use, prefix the CSS link URL with '/ccss/' instead of '/css/' or use HtmlHelper::css(). + */ + //Configure::write('Asset.filter.css', 'css.php'); + +/** + * Plug in your own custom JavaScript compressor by dropping a script in your webroot to handle the + * output, and setting the config below to the name of the script. + * + * To use, prefix your JavaScript link URLs with '/cjs/' instead of '/js/' or use JsHelper::link(). + */ + //Configure::write('Asset.filter.js', 'custom_javascript_output_filter.php'); + +/** + * The class name and database used in CakePHP's + * access control lists. + */ + Configure::write('Acl.classname', 'DbAcl'); + Configure::write('Acl.database', 'default'); + +/** + * Uncomment this line and correct your server timezone to fix + * any date & time related errors. + */ + //date_default_timezone_set('UTC'); + +/** + * `Config.timezone` is available in which you can set users' timezone string. + * If a method of CakeTime class is called with $timezone parameter as null and `Config.timezone` is set, + * then the value of `Config.timezone` will be used. This feature allows you to set users' timezone just + * once instead of passing it each time in function calls. + */ + //Configure::write('Config.timezone', 'Europe/Paris'); + +/** + * + * Cache Engine Configuration + * Default settings provided below + * + * File storage engine. + * + * Cache::config('default', array( + * 'engine' => 'File', //[required] + * 'duration' => 3600, //[optional] + * 'probability' => 100, //[optional] + * 'path' => CACHE, //[optional] use system tmp directory - remember to use absolute path + * 'prefix' => 'cake_', //[optional] prefix every cache file with this string + * 'lock' => false, //[optional] use file locking + * 'serialize' => true, //[optional] + * 'mask' => 0664, //[optional] + * )); + * + * APC (http://pecl.php.net/package/APC) + * + * Cache::config('default', array( + * 'engine' => 'Apc', //[required] + * 'duration' => 3600, //[optional] + * 'probability' => 100, //[optional] + * 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string + * )); + * + * Xcache (http://xcache.lighttpd.net/) + * + * Cache::config('default', array( + * 'engine' => 'Xcache', //[required] + * 'duration' => 3600, //[optional] + * 'probability' => 100, //[optional] + * 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string + * 'user' => 'user', //user from xcache.admin.user settings + * 'password' => 'password', //plaintext password (xcache.admin.pass) + * )); + * + * Memcache (http://www.danga.com/memcached/) + * + * Cache::config('default', array( + * 'engine' => 'Memcache', //[required] + * 'duration' => 3600, //[optional] + * 'probability' => 100, //[optional] + * 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string + * 'servers' => array( + * '127.0.0.1:11211' // localhost, default port 11211 + * ), //[optional] + * 'persistent' => true, // [optional] set this to false for non-persistent connections + * 'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory) + * )); + * + * Wincache (http://php.net/wincache) + * + * Cache::config('default', array( + * 'engine' => 'Wincache', //[required] + * 'duration' => 3600, //[optional] + * 'probability' => 100, //[optional] + * 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string + * )); + */ + +/** + * Configure the cache handlers that CakePHP will use for internal + * metadata like class maps, and model schema. + * + * By default File is used, but for improved performance you should use APC. + * + * Note: 'default' and other application caches should be configured in app/Config/bootstrap.php. + * Please check the comments in bootstrap.php for more info on the cache engines available + * and their settings. + */ +$engine = 'File'; + +// In development mode, caches should expire quickly. +$duration = '+999 days'; +if (Configure::read('debug') > 0) { + $duration = '+10 seconds'; +} + +// Prefix each application on the same server with a different string, to avoid Memcache and APC conflicts. +$prefix = 'myapp_'; + +/** + * Configure the cache used for general framework caching. Path information, + * object listings, and translation cache files are stored with this configuration. + */ +Cache::config('_cake_core_', array( + 'engine' => $engine, + 'prefix' => $prefix . 'cake_core_', + 'path' => CACHE . 'persistent' . DS, + 'serialize' => ($engine === 'File'), + 'duration' => $duration +)); + +/** + * Configure the cache for model and datasource caches. This cache configuration + * is used to store schema descriptions, and table listings in connections. + */ +Cache::config('_cake_model_', array( + 'engine' => $engine, + 'prefix' => $prefix . 'cake_model_', + 'path' => CACHE . 'models' . DS, + 'serialize' => ($engine === 'File'), + 'duration' => $duration +)); diff --git a/templates/framework/cake/database.php.erb b/templates/framework/cake/database.php.erb new file mode 100644 index 0000000..2610d39 --- /dev/null +++ b/templates/framework/cake/database.php.erb @@ -0,0 +1,85 @@ + The name of a supported datasource; valid options are as follows: + * Database/Mysql - MySQL 4 & 5, + * Database/Sqlite - SQLite (PHP5 only), + * Database/Postgres - PostgreSQL 7 and higher, + * Database/Sqlserver - Microsoft SQL Server 2005 and higher + * + * You can add custom database datasources (or override existing datasources) by adding the + * appropriate file to app/Model/Datasource/Database. Datasources should be named 'MyDatasource.php', + * + * + * persistent => true / false + * Determines whether or not the database should use a persistent connection + * + * host => + * the host you connect to the database. To add a socket or port number, use 'port' => # + * + * prefix => + * Uses the given prefix for all the tables in this database. This setting can be overridden + * on a per-table basis with the Model::$tablePrefix property. + * + * schema => + * For Postgres/Sqlserver specifies which schema you would like to use the tables in. + * Postgres defaults to 'public'. For Sqlserver, it defaults to empty and use + * the connected user's default schema (typically 'dbo'). + * + * encoding => + * For MySQL, Postgres specifies the character encoding to use when connecting to the + * database. Uses database default not specified. + * + * unix_socket => + * For MySQL to connect via socket specify the `unix_socket` parameter instead of `host` and `port` + * + * settings => + * Array of key/value pairs, on connection it executes SET statements for each pair + * For MySQL : http://dev.mysql.com/doc/refman/5.6/en/set-statement.html + * For Postgres : http://www.postgresql.org/docs/9.2/static/sql-set.html + * For Sql Server : http://msdn.microsoft.com/en-us/library/ms190356.aspx + */ +class DATABASE_CONFIG { + + public $default = array( + 'datasource' => 'Database/Mysql', + 'persistent' => false, + 'host' => 'localhost', + 'login' => '<%= db_user %>', + 'password' => '<%= db_pass %>', + 'database' => '<%= db_name %>', + 'prefix' => '', + //'encoding' => 'utf8', + ); + + public $test = array( + 'datasource' => 'Database/Mysql', + 'persistent' => false, + 'host' => 'localhost', + 'login' => 'user', + 'password' => 'password', + 'database' => 'test_database_name', + 'prefix' => '', + //'encoding' => 'utf8', + ); +} diff --git a/templates/framework/cake/htaccess b/templates/framework/cake/htaccess new file mode 100644 index 0000000..89df82d --- /dev/null +++ b/templates/framework/cake/htaccess @@ -0,0 +1,5 @@ + + RewriteEngine on + RewriteRule ^$ app/webroot/ [L] + RewriteRule (.*) app/webroot/$1 [L] + From 2d2addeccf8402dee6f2ba716780448d4e8fc435 Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Thu, 26 Jun 2014 16:07:16 -0300 Subject: [PATCH 06/18] Modify beaker tests, but it still needs some test --- .fixtures.yml | 8 ++--- Gemfile | 3 ++ Rakefile | 1 + manifests/apache.pp | 2 +- spec/acceptance/apache_spec.rb | 33 +++++++++++++++++++ spec/acceptance/class_spec.rb | 17 ++++++++++ spec/acceptance/nodesets/centos-64-x64.yml | 11 +++++++ spec/acceptance/nodesets/default.yml | 11 +++++++ .../nodesets/ubuntu-server-12042-x64.yml | 12 +++++++ spec/spec_helper_acceptance.rb | 30 +++++++++++++++++ 10 files changed, 123 insertions(+), 5 deletions(-) create mode 100644 spec/acceptance/apache_spec.rb create mode 100644 spec/acceptance/class_spec.rb create mode 100644 spec/acceptance/nodesets/centos-64-x64.yml create mode 100644 spec/acceptance/nodesets/default.yml create mode 100644 spec/acceptance/nodesets/ubuntu-server-12042-x64.yml create mode 100644 spec/spec_helper_acceptance.rb diff --git a/.fixtures.yml b/.fixtures.yml index eb598e9..d96e726 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -2,9 +2,9 @@ fixtures: repositories: stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git" stdmod: "git://github.com/stdmod/stdmod.git" - nginx: "https://github.com/netmanagers/puppet-nginx.git" - apache: "https://github.com/example42/puppet-apache" - php5fpm: "https://github.com/zertico/puppet-php5fpm.git" - puppi: "https://github.com/example42/puppi" + nginx: "git://github.com/netmanagers/puppet-nginx.git" + apache: "git://github.com/example42/puppet-apache.git" + php5fpm: "git://github.com/zertico/puppet-php5fpm.git" + puppi: "git://github.com/example42/puppi.git" symlinks: deploy_php: "#{source_dir}" diff --git a/Gemfile b/Gemfile index 8626707..8291afb 100644 --- a/Gemfile +++ b/Gemfile @@ -11,3 +11,6 @@ gem 'puppet-syntax' gem 'puppet', ENV['PUPPET_VERSION'] || '~> 3.3.0' gem 'vagrant-wrapper' gem 'puppet-blacksmith' +gem 'beaker' +gem 'beaker-rspec' + diff --git a/Rakefile b/Rakefile index f1afe7b..6b4b933 100644 --- a/Rakefile +++ b/Rakefile @@ -18,6 +18,7 @@ exclude_paths = [ PuppetLint.configuration.ignore_paths = exclude_paths PuppetSyntax.exclude_paths = exclude_paths + desc "Run syntax, lint, and spec tests." task :test => [ :syntax, diff --git a/manifests/apache.pp b/manifests/apache.pp index da362c9..f689168 100755 --- a/manifests/apache.pp +++ b/manifests/apache.pp @@ -68,7 +68,7 @@ homedir_mode => $system_user_homedir_mode, tag => $system_user_tag, password_salt => '65941380', - require => File[$deploy_php::dir_path_webserver], + require => File[$deploy_php::dir_path_webserver] } apache::virtualhost { $name: diff --git a/spec/acceptance/apache_spec.rb b/spec/acceptance/apache_spec.rb new file mode 100644 index 0000000..5c28b28 --- /dev/null +++ b/spec/acceptance/apache_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper_acceptance' + +describe 'deploy_apache define' do + describe 'running wordpress' do + it 'should install wordpress with no errors' do + pp = <<-EOS + class { 'deploy_php': + webserver_name => 'apache', + apache_module => 'suphp' + } + deploy_php::apache { 'example.com': + createdb => true, + mysql_database_name => 'm_example', + mysql_password => 'iyDPMHFBiwFX6', + mysql_user =>'m_example', + system_username_password => 'ycG/UabGX1SSc', + application => 'wordpress' + } + EOS + apply_manifest(pp, :catch_failures => true) + expect(apply_manifest(pp).exit_code).to eq(0) + end + describe 'created user and database' do + it 'should create a user' do + shell("cat /etc/passwd | grep example.com | sed -e 's/:.*//g'", :acceptable_exit_codes => 0) + end + + it 'should create a database' do + shell("ls /var/lib/mysql/ | grep m_example", :acceptable_exit_codes => 0) + end + end + end +end diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb new file mode 100644 index 0000000..f9e5ea9 --- /dev/null +++ b/spec/acceptance/class_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper_acceptance' + +describe 'deploy_php class' do + + context 'default parameters' do + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOS +# include deploy_php + EOS + + # Run it twice and test for idempotency + expect(apply_manifest(pp).exit_code).to_not eq(1) + expect(apply_manifest(pp).exit_code).to eq(0) + end + end +end diff --git a/spec/acceptance/nodesets/centos-64-x64.yml b/spec/acceptance/nodesets/centos-64-x64.yml new file mode 100644 index 0000000..d19aa69 --- /dev/null +++ b/spec/acceptance/nodesets/centos-64-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + centos-64-x64: + roles: + - master + platform: el-6-x86_64 + box : centos-64-x64-vbox4210-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box + hypervisor : vagrant +CONFIG: + log_level: verbose + type: foss diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml new file mode 100644 index 0000000..91bd268 --- /dev/null +++ b/spec/acceptance/nodesets/default.yml @@ -0,0 +1,11 @@ +HOSTS: + debian-70rc1-x64: + roles: + - master + platform: debian-7-amd64 + box: debian-70rc1-x64-vbox4210-nocm + box_url: http://puppet-vagrant-boxes.puppetlabs.com/debian-70rc1-x64-vbox4210-nocm.box + hypervisor: vagrant +CONFIG: + log_level: verbose + type: foss diff --git a/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml b/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml new file mode 100644 index 0000000..b392dab --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml @@ -0,0 +1,12 @@ +HOSTS: + ubuntu-server-12042-x64: + roles: + - master + platform: ubuntu-server-12.04-amd64 + box: ubuntu-server-12042-x64-vbox4210-nocm + box_url: http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box + hypervisor: vagrant + +CONFIG: + log_level: verbose + type: foss diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 0000000..7445971 --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,30 @@ +require 'beaker-rspec/spec_helper' +require 'beaker-rspec/helpers/serverspec' + +hosts.each do |host| + # Install Puppet + install_puppet + install_package host, 'git-core' +end + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + # Readable test descriptions + c.formatter = :documentation + + # Configure all nodes in nodeset + c.before :suite do + # Install module and dependencies + puppet_module_install(:source => proj_root, :module_name => 'deploy_php') + hosts.each do |host| + on host, puppet('module', 'install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] } + on host, 'git clone https://github.com/netmanagers/puppet-nginx.git /etc/puppet/modules/nginx' + on host, 'git clone https://github.com/example42/puppi.git /etc/puppet/modules/puppi' + on host, 'git clone git://github.com/zertico/puppet-php5fpm.git /etc/puppet/modules/php5fpm' + on host, 'git clone git://github.com/example42/puppet-apache.git /etc/puppet/modules/apache' + on host, 'git clone git://github.com/example42/puppet-mysql.git /etc/puppet/modules/mysql' + on host, 'git clone git://github.com/example42/puppet-user.git /etc/puppet/modules/user' + end + end +end From 804ca44acb86db7acc7ebefbffbfd72c8b095c2a Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Thu, 26 Jun 2014 18:11:22 -0300 Subject: [PATCH 07/18] Modified suphp template --- spec/acceptance/apache_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/acceptance/apache_spec.rb b/spec/acceptance/apache_spec.rb index 5c28b28..7e22d5c 100644 --- a/spec/acceptance/apache_spec.rb +++ b/spec/acceptance/apache_spec.rb @@ -6,7 +6,6 @@ pp = <<-EOS class { 'deploy_php': webserver_name => 'apache', - apache_module => 'suphp' } deploy_php::apache { 'example.com': createdb => true, From b8b7a2d0aeb7f21e305d7f991ae3e826c151be10 Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Fri, 27 Jun 2014 10:26:09 -0300 Subject: [PATCH 08/18] Fix tests with beaker --- manifests/init.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index 08ab6e4..9615acc 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -14,7 +14,7 @@ $apache_module = $deploy_php::apache_module, $template_php_ini = $deploy_php::template_php_ini, $template_suphp_conf = $deploy_php::template_suphp_conf, - $template_suphp_mod = $deploy_php::template_suphp_conf + $template_suphp_mod = $deploy_php::template_suphp_mod ) inherits deploy_php::params { include $webserver_name From 08c8769e75b2247b433a4173545125456e30ccd3 Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Fri, 27 Jun 2014 11:06:05 -0300 Subject: [PATCH 09/18] Add joomla to apache.pp --- manifests/apache.pp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/manifests/apache.pp b/manifests/apache.pp index f689168..90c4190 100755 --- a/manifests/apache.pp +++ b/manifests/apache.pp @@ -113,4 +113,10 @@ require => User::Managed[$real_system_username] } } + + if $application == 'joomla' { + deploy_php::app::joomla::v1 { $real_system_username: + require => User::Managed[$real_system_username] + } + } } From 854015143b2ac611fdbb89fdca5ec0276006455e Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Fri, 27 Jun 2014 11:15:15 -0300 Subject: [PATCH 10/18] Fix joomla feature --- manifests/params.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/params.pp b/manifests/params.pp index b5785dd..a292289 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -15,7 +15,7 @@ ensure => directory, } - file { ['/root/puppet/','/root/puppet/wordpress']: + file { ['/root/puppet/','/root/puppet/wordpress','/root/puppet/joomla']: ensure => directory, } From 7e2faecb100e6d55dc5474597dcb46f2dcfc4eb4 Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Fri, 27 Jun 2014 11:52:15 -0300 Subject: [PATCH 11/18] Fix cake deploy --- .nodeset.yml | 27 --------------------------- manifests/nginx.pp | 2 +- spec/spec_helper_system.rb | 17 ----------------- spec/system/basic_spec.rb | 13 ------------- 4 files changed, 1 insertion(+), 58 deletions(-) delete mode 100644 .nodeset.yml delete mode 100644 spec/spec_helper_system.rb delete mode 100644 spec/system/basic_spec.rb diff --git a/.nodeset.yml b/.nodeset.yml deleted file mode 100644 index b0031d0..0000000 --- a/.nodeset.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -default_set: 'ubuntu-server-12042-x64' -sets: - 'ubuntu-server-10044-x64': - nodes: - "main.foo.vm": - prefab: 'ubuntu-server-10044-x64' - 'ubuntu-server-12042-x64': - nodes: - "main.foo.vm": - prefab: 'ubuntu-server-12042-x64' - 'centos-59-x64': - nodes: - "main.foo.vm": - prefab: 'centos-59-x64' - 'centos-64-x64': - nodes: - "main.foo.vm": - prefab: 'centos-64-x64' - 'debian-607-x64': - nodes: - "main.foo.vm": - prefab: 'debian-607-x64' - 'debian-70rc1-x64': - nodes: - "main.foo.vm": - prefab: 'debian-70rc1-x64' diff --git a/manifests/nginx.pp b/manifests/nginx.pp index d80484d..8d511ce 100755 --- a/manifests/nginx.pp +++ b/manifests/nginx.pp @@ -164,7 +164,7 @@ } if $framework == 'cake' { - deploy_php::app::cake::v1 { $real_system_username: + deploy_php::app::framework::cake::v1 { $real_system_username: db_name => $real_mysql_database_name, db_user => $real_mysql_user, db_pass => $real_mysql_password, diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb deleted file mode 100644 index ad7c45d..0000000 --- a/spec/spec_helper_system.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'rspec-system/spec_helper' -require 'rspec-system-puppet/helpers' - -include RSpecSystemPuppet::Helpers - -RSpec.configure do |c| - proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) - c.tty = true - c.include RSpecSystemPuppet::Helpers - c.extend RSpecSystemPuppet::Helpers - - c.before :suite do - puppet_install - puppet_module_install(:source => proj_root, :module_name => 'deploy_php') - shell('puppet module install puppetlabs-stdlib') - end -end diff --git a/spec/system/basic_spec.rb b/spec/system/basic_spec.rb deleted file mode 100644 index 0002ea4..0000000 --- a/spec/system/basic_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'spec_helper_system' - -describe 'basic tests' do - it 'class should work without errors' do - pp = <<-EOS - class { 'deploy_php': } - EOS - - puppet_apply(pp) do |r| - r.exit_code.should == 2 - end - end -end From 113280697232f1fa0e359a44ac37a2925a833f85 Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Fri, 27 Jun 2014 11:55:37 -0300 Subject: [PATCH 12/18] Fix cake rules --- manifests/nginx.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/nginx.pp b/manifests/nginx.pp index 8d511ce..a79e431 100755 --- a/manifests/nginx.pp +++ b/manifests/nginx.pp @@ -164,7 +164,7 @@ } if $framework == 'cake' { - deploy_php::app::framework::cake::v1 { $real_system_username: + deploy_php::framework::cake::v1 { $real_system_username: db_name => $real_mysql_database_name, db_user => $real_mysql_user, db_pass => $real_mysql_password, From 31e38c0a147d1fdfa171ef37c3788c40faf6dfb2 Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Fri, 27 Jun 2014 11:59:17 -0300 Subject: [PATCH 13/18] Fix add cake folder --- manifests/params.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/params.pp b/manifests/params.pp index a292289..4fe8cd0 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -15,7 +15,7 @@ ensure => directory, } - file { ['/root/puppet/','/root/puppet/wordpress','/root/puppet/joomla']: + file { ['/root/puppet/','/root/puppet/wordpress','/root/puppet/joomla','/root/puppet/cake']: ensure => directory, } From ad5ccc966f5bec6de8fa7f3fcc5ea8b64cfbee44 Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Fri, 27 Jun 2014 16:33:09 -0300 Subject: [PATCH 14/18] Remove .htaccess from wordpress --- .rspec | 2 ++ manifests/app/wordpress/v1.pp | 11 +------- .../environments/environment_apache.rb | 17 ++++++++++++ spec/classes/init_spec.rb | 12 ++++++--- spec/defines/apache_spec.rb | 1 + spec/defines/app/joomla_spec.rb | 14 ++++++++++ spec/defines/app/wordpress_spec.rb | 27 +++++++++++++++++++ 7 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 .rspec create mode 100644 spec/classes/environments/environment_apache.rb create mode 100644 spec/defines/apache_spec.rb create mode 100644 spec/defines/app/joomla_spec.rb create mode 100644 spec/defines/app/wordpress_spec.rb diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..8c18f1a --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--format documentation +--color diff --git a/manifests/app/wordpress/v1.pp b/manifests/app/wordpress/v1.pp index 93a2681..9025414 100644 --- a/manifests/app/wordpress/v1.pp +++ b/manifests/app/wordpress/v1.pp @@ -8,7 +8,6 @@ $user_name = $title, $complete_path = "/home/vhosts/${name}/public_html/", $directory = "/root/puppet/wordpress/${name}", - $which_server = 'nginx', $groups = $title ) { @@ -21,15 +20,6 @@ $logged_in_salt = sha1("logged_in_salt${name}") $nonce_salt = sha1("nonce_salt${name}") - if $which_server == 'apache2' { - $groups = 'www-data' - file { "${complete_path}.htaccess": - ensure => 'file', - group => $groups, - mode => '0755', - } - } - file { $directory: ensure => directory, owner => 'root', @@ -50,6 +40,7 @@ } file { "${complete_path}wp-config.php": + ensure => present, content => template('deploy_php/wordpress/wp-config.php.erb'), mode => '0755', owner => $user_name, diff --git a/spec/classes/environments/environment_apache.rb b/spec/classes/environments/environment_apache.rb new file mode 100644 index 0000000..972711c --- /dev/null +++ b/spec/classes/environments/environment_apache.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe 'deploy_php::environments::environment_apache' do + context 'with suphp as main module' do + it do should contain_file('/etc/suphp/suphp.conf').with({ + 'ensure' => 'present', + 'notify' => 'Service[apache2]' + }) + end + it do should contain_file('/etc/apache/mods-available/suphp.php').with({ + 'ensure' => 'present', + 'notify' => 'Service[apache2]' + }) + end + end +end + diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index b97568f..40f4492 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -9,11 +9,17 @@ end end context 'testing with apache and suphp' do - let(:params) {{:webserver_name => 'apache', :apache_module => 'su_php' }} + let(:params) {{:webserver_name => 'apache' }} it do should contain_class('apache') end -# it { should contain_class('deploy_php::environments::environment_apache') } - + it { should contain_class("deploy_php::environments::environment_apache") } + end + context 'testing apache and php5' do + let(:params){{:webserver_name => 'apache',:apache_module => 'php5' }} + it do should contain_class('apache') + end + it do should contain_class("deploy_php::environments::environment_apache") + end end end diff --git a/spec/defines/apache_spec.rb b/spec/defines/apache_spec.rb new file mode 100644 index 0000000..f8ec369 --- /dev/null +++ b/spec/defines/apache_spec.rb @@ -0,0 +1 @@ +require 'spec_helper' diff --git a/spec/defines/app/joomla_spec.rb b/spec/defines/app/joomla_spec.rb new file mode 100644 index 0000000..95fd065 --- /dev/null +++ b/spec/defines/app/joomla_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' + +describe 'deploy_php::app::joomla::v1' do + let(:title){ 'example.com' } + + context 'installed in general(nginx/apache) environment' do + it do should contain_file('/root/puppet/joomla/example.com').with({ + 'ensure' => 'directory', + 'owner' => 'root', + 'group' => 'root', + }) + end + end +end diff --git a/spec/defines/app/wordpress_spec.rb b/spec/defines/app/wordpress_spec.rb new file mode 100644 index 0000000..2b321f4 --- /dev/null +++ b/spec/defines/app/wordpress_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe 'deploy_php::app::wordpress::v1' do + let(:title){ 'example.com' } + let(:params){{ + :db => 'm_example', + :db_user => 'm_example', + :db_pass => 'iyDPMHFBiwFX6', + :db_host => 'localhost', + }} + + context 'installed in general(nginx/apache) environment' do + it do should contain_file('/root/puppet/wordpress/example.com').with({ + 'ensure' => 'directory', + 'owner' => 'root', + 'group' => 'root', + })end + it do should contain_file('/home/vhosts/example.com/public_html/wp-config.php').with({ + 'ensure' => 'present', + 'owner' => 'example.com', + 'group' => 'example.com', + 'replace' => 'false', + 'mode' => '0755', + })end + + end +end From 1b2fea185a9cc140c9a447651421243b266488e2 Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Fri, 27 Jun 2014 18:30:34 -0300 Subject: [PATCH 15/18] Add more tests --- .../environments/environment_apache_spec.rb | 56 +++++++++++++++++++ spec/classes/init_spec.rb | 5 +- 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 spec/classes/environments/environment_apache_spec.rb diff --git a/spec/classes/environments/environment_apache_spec.rb b/spec/classes/environments/environment_apache_spec.rb new file mode 100644 index 0000000..6ae88de --- /dev/null +++ b/spec/classes/environments/environment_apache_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe "deploy_php::environments::environment_apache",:type => :class do + context 'apache and suphp' do + let :facts do + { + :osfamily => 'Debian', + :operatingsystem => 'Debian', + :operatingsystemrelease => '7.0', + :kernel => 'Linux', + } + end + + let :pre_condition do + "class { 'deploy_php': + webserver_name => 'apache', + apache_module => 'suphp' + }" + end + it { should contain_apache__module('suphp') } + it do should contain_file('/etc/suphp/suphp.conf').with({ + 'ensure' => 'present', + 'notify' => 'Service[apache2]' + }) + end + it do should contain_file("/etc/apache2/mods-available/suphp.conf").with({ + 'ensure' => 'present', + 'notify' => 'Service[apache2]' + }) + end + end + + context 'apache and mod_php' do + let :facts do + { + :osfamily => 'Debian', + :operatingsystem => 'Debian', + :operatingsystemrelease => '6.0', + :kernel => 'Linux', + } + end + + let :pre_condition do + " class { 'deploy_php': + webserver_name => 'apache', + apache_module => 'php5' + } + " + end + it { should contain_apache__module('php5') } + + end + + + +end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 40f4492..bfb1ceb 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -9,10 +9,11 @@ end end context 'testing with apache and suphp' do - let(:params) {{:webserver_name => 'apache' }} + let(:params) {{:webserver_name => 'apache',:apache_module => 'suphp' }} it do should contain_class('apache') end - it { should contain_class("deploy_php::environments::environment_apache") } + it do should contain_class("deploy_php::environments::environment_apache") + end end context 'testing apache and php5' do let(:params){{:webserver_name => 'apache',:apache_module => 'php5' }} From e8b57666af4941f6fd38e865dce21ff460a39440 Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Mon, 30 Jun 2014 10:10:36 -0300 Subject: [PATCH 16/18] Add more test --- spec/defines/apache_spec.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/spec/defines/apache_spec.rb b/spec/defines/apache_spec.rb index f8ec369..2d3d569 100644 --- a/spec/defines/apache_spec.rb +++ b/spec/defines/apache_spec.rb @@ -1 +1,37 @@ require 'spec_helper' +describe 'deploy_php::apache' do + let(:title) { 'example.com' } + context 'creates user,apache vhost and database' do + let :params do + { + :createdb => true, + :mysql_database_name => 'm_example', + :mysql_password => 'iyDPMHFBiwFX6', + :mysql_user => 'm_example', + :system_username_password => 'ycG/UabGX1SSc' + } + end + it { should contain_user__managed('example.com') } + it { should contain_apache__virtualhost('example.com') } + it { should contain_mysql__grant('m_example') } + end + context 'creates only user and apache vhost' do + let :params do + { + :createdb => false, + :system_username_password => 'ycG/UabGX1SSc' + } + it { should contain_user__managed('example.com') } + it { should contain_apache__virtualhost('example.com')} + end + end + context 'creates only apache vhost' do + let :params do + { + :createdb => false, + :system_create_user => false, + } + end + it { should contain_apache__virtualhost('example.com')} + end +end From 32dd453aea5cd45ae51152ad67e6a038d4acc23c Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Mon, 30 Jun 2014 13:14:14 -0300 Subject: [PATCH 17/18] Add all tests --- .fixtures.yml | 2 + manifests/app/wordpress/v1.pp | 2 +- .../environments/environment_apache.rb | 17 --------- .../environments/environment_apache_spec.rb | 2 +- .../environments_environment_apache_spec.rb | 7 ---- spec/classes/init_spec.rb | 6 +-- spec/defines/app/joomla_spec.rb | 1 + spec/defines/app/wordpress_spec.rb | 1 + spec/defines/nginx_spec.rb | 38 +++++++++++++++++++ 9 files changed, 47 insertions(+), 29 deletions(-) delete mode 100644 spec/classes/environments/environment_apache.rb delete mode 100644 spec/classes/environments_environment_apache_spec.rb create mode 100644 spec/defines/nginx_spec.rb diff --git a/.fixtures.yml b/.fixtures.yml index d96e726..7e8b098 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,6 +1,8 @@ fixtures: repositories: stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git" + mysql: "https://github.com/example42/puppet-mysql" + user: "https://github.com/example42/puppet-user" stdmod: "git://github.com/stdmod/stdmod.git" nginx: "git://github.com/netmanagers/puppet-nginx.git" apache: "git://github.com/example42/puppet-apache.git" diff --git a/manifests/app/wordpress/v1.pp b/manifests/app/wordpress/v1.pp index 9025414..b6e170c 100644 --- a/manifests/app/wordpress/v1.pp +++ b/manifests/app/wordpress/v1.pp @@ -26,7 +26,7 @@ group => 'root', } - puppi::netinstall { "netinstall_wordpress_${user_name}_${name}": + puppi::netinstall { "netinstall_wordpress_${user_name}": url => 'http://wordpress.org/latest.tar.gz', extract_command => 'tar --strip-components 1 -zxf', destination_dir => "${directory}/install", diff --git a/spec/classes/environments/environment_apache.rb b/spec/classes/environments/environment_apache.rb deleted file mode 100644 index 972711c..0000000 --- a/spec/classes/environments/environment_apache.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'spec_helper' - -describe 'deploy_php::environments::environment_apache' do - context 'with suphp as main module' do - it do should contain_file('/etc/suphp/suphp.conf').with({ - 'ensure' => 'present', - 'notify' => 'Service[apache2]' - }) - end - it do should contain_file('/etc/apache/mods-available/suphp.php').with({ - 'ensure' => 'present', - 'notify' => 'Service[apache2]' - }) - end - end -end - diff --git a/spec/classes/environments/environment_apache_spec.rb b/spec/classes/environments/environment_apache_spec.rb index 6ae88de..dcf83e1 100644 --- a/spec/classes/environments/environment_apache_spec.rb +++ b/spec/classes/environments/environment_apache_spec.rb @@ -35,7 +35,7 @@ { :osfamily => 'Debian', :operatingsystem => 'Debian', - :operatingsystemrelease => '6.0', + :operatingsystemrelease => '7.0', :kernel => 'Linux', } end diff --git a/spec/classes/environments_environment_apache_spec.rb b/spec/classes/environments_environment_apache_spec.rb deleted file mode 100644 index cc86a85..0000000 --- a/spec/classes/environments_environment_apache_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'spec_helper' - -describe 'deploy_php::environments::environment_apache' do -# it do should contain_file('/etc/suphp/suphp.conf') -# end -end - diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index bfb1ceb..268e0f2 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,21 +1,21 @@ require 'spec_helper' describe 'deploy_php' do - context 'testing with nginx' do + context 'creates nginx environment' do let(:params) {{ :webserver_name => 'nginx' }} it do should contain_class('nginx') end it do should contain_class('php5fpm') end end - context 'testing with apache and suphp' do + context 'creates apache and suphp environment' do let(:params) {{:webserver_name => 'apache',:apache_module => 'suphp' }} it do should contain_class('apache') end it do should contain_class("deploy_php::environments::environment_apache") end end - context 'testing apache and php5' do + context 'creates apache and php5 environment' do let(:params){{:webserver_name => 'apache',:apache_module => 'php5' }} it do should contain_class('apache') end diff --git a/spec/defines/app/joomla_spec.rb b/spec/defines/app/joomla_spec.rb index 95fd065..e7fbd50 100644 --- a/spec/defines/app/joomla_spec.rb +++ b/spec/defines/app/joomla_spec.rb @@ -10,5 +10,6 @@ 'group' => 'root', }) end + it { should contain_puppi__netinstall('netinstall_joomla_example.com')} end end diff --git a/spec/defines/app/wordpress_spec.rb b/spec/defines/app/wordpress_spec.rb index 2b321f4..c5895c2 100644 --- a/spec/defines/app/wordpress_spec.rb +++ b/spec/defines/app/wordpress_spec.rb @@ -15,6 +15,7 @@ 'owner' => 'root', 'group' => 'root', })end + it { should contain_puppi__netinstall('netinstall_wordpress_example.com')} it do should contain_file('/home/vhosts/example.com/public_html/wp-config.php').with({ 'ensure' => 'present', 'owner' => 'example.com', diff --git a/spec/defines/nginx_spec.rb b/spec/defines/nginx_spec.rb new file mode 100644 index 0000000..449ef95 --- /dev/null +++ b/spec/defines/nginx_spec.rb @@ -0,0 +1,38 @@ + require 'spec_helper' + +describe 'deploy_php::nginx' do + let(:title) { 'example.com' } + context 'creates user,nginx vhost and database' do + let :params do + { + :createdb => true, + :mysql_database_name => 'm_example', + :mysql_password => 'iyDPMHFBiwFX6', + :mysql_user => 'm_example', + :system_username_password => 'ycG/UabGX1SSc', + } + end + it { should contain_user__managed('example.com') } + it { should contain_nginx__vhost('example.com') } + it { should contain_mysql__grant('m_example') } + end + context 'creates only user and nginx vhost' do + let :params do + { + :createdb => false, + :system_username_password => 'ycG/UabGX1SSc' + } + end + it { should contain_user__managed('example.com') } + it { should contain_nginx__vhost('example.com') } + end + context 'creates only nginx vhost' do + let :params do + { + :createdb => false, + :system_create_user => false, + } + end + it { should contain_nginx__vhost('example.com') } + end +end From 0a6950a1c87a151526d454318eb0e1c7a9fb4479 Mon Sep 17 00:00:00 2001 From: Israel Ribeiro Date: Wed, 2 Jul 2014 15:39:00 -0300 Subject: [PATCH 18/18] Exposed url in wordpress and joomla --- manifests/app/joomla/v1.pp | 16 ++++++++++++---- manifests/app/wordpress/v1.pp | 15 +++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/manifests/app/joomla/v1.pp b/manifests/app/joomla/v1.pp index 9dc57d1..c83d3a7 100644 --- a/manifests/app/joomla/v1.pp +++ b/manifests/app/joomla/v1.pp @@ -1,10 +1,18 @@ #Define deploy_php::app::joomla::v1 # define deploy_php::app::joomla::v1 ( - $complete_path = "/home/vhosts/${name}/public_html/", - $directory = "/root/puppet/joomla/${name}", + $url = 'http://joomlacode.org/gf/download/frsrelease/19239/158104/Joomla_3.2.3-Stable-Full_Package.zip', + $complete_path = "/home/vhosts/${name}/public_html/", + $directory = "/root/puppet/joomla/${name}", + $typeOfCompression = 'zip' ){ + $real_typeOfCompression = $typeOfCompression ? { + 'zip' => 'unzip', + 'tar.gz' => 'tar --strip-components 1 -zxf' + } + + file { $directory: ensure => directory, owner => 'root', @@ -12,8 +20,8 @@ } puppi::netinstall { "netinstall_joomla_${name}": - url => 'http://joomlacode.org/gf/download/frsrelease/19239/158104/Joomla_3.2.3-Stable-Full_Package.zip', - extract_command => 'unzip', + url => $url, + extract_command => $real_typeOfCompression, destination_dir => "${directory}/install", extracted_dir => '.', owner => $name, diff --git a/manifests/app/wordpress/v1.pp b/manifests/app/wordpress/v1.pp index b6e170c..bfe6860 100644 --- a/manifests/app/wordpress/v1.pp +++ b/manifests/app/wordpress/v1.pp @@ -8,7 +8,9 @@ $user_name = $title, $complete_path = "/home/vhosts/${name}/public_html/", $directory = "/root/puppet/wordpress/${name}", - $groups = $title + $groups = $title, + $url = 'http://wordpress.org/latest.tar.gz', + $typeOfCompression = 'tar.gz' ) { $auth_key = sha1("auth_key${name}") @@ -20,6 +22,11 @@ $logged_in_salt = sha1("logged_in_salt${name}") $nonce_salt = sha1("nonce_salt${name}") + $real_typeOfCompression = $typeOfCompression ? { + 'zip' => 'unzip', + 'tar.gz' => 'tar --strip-components 1 -zxf' + } + file { $directory: ensure => directory, owner => 'root', @@ -27,8 +34,8 @@ } puppi::netinstall { "netinstall_wordpress_${user_name}": - url => 'http://wordpress.org/latest.tar.gz', - extract_command => 'tar --strip-components 1 -zxf', + url => $url, + extract_command => $real_typeOfCompression, destination_dir => "${directory}/install", extracted_dir => '.', owner => $user_name, @@ -46,7 +53,7 @@ owner => $user_name, group => $user_name, replace => false, - require => Puppi::Netinstall["netinstall_wordpress_${user_name}_${name}"], + require => Puppi::Netinstall["netinstall_wordpress_${user_name}"], } }