Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(install): add initial install for composer projects #85

Draft
wants to merge 23 commits into
base: 6.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fe6d344
feat(install): add initial install for composer projects
minorOffense Nov 3, 2021
5cd139e
refactor(distro): remove deprecated install methods
minorOffense Nov 3, 2021
f9429b8
refactor(install): remove install profiles
minorOffense Nov 3, 2021
2dbb8e4
refactor(install): remove install profiles
minorOffense Nov 3, 2021
df8f4c2
Delete drush.make.erb
minorOffense Nov 3, 2021
cbf6427
Update htaccess-public.erb
minorOffense Nov 3, 2021
9ef7d8a
Update htaccess-private.erb
minorOffense Nov 3, 2021
8035a05
Update distro.pp
minorOffense Nov 12, 2021
759c486
Update distro.pp
minorOffense Nov 12, 2021
5eea23b
Update init.pp
minorOffense Nov 12, 2021
80c8a1f
Merge branch '6.x' into composer-initial
minorOffense Nov 12, 2021
d385811
feat(composer): run as non-root
minorOffense Nov 12, 2021
03afcb7
feat(composer): run as non-root
minorOffense Nov 12, 2021
a2bdd70
feat(composer): run as non-root
minorOffense Nov 12, 2021
93b261d
refactor(puppet): use stdlib ensure_resources
minorOffense Dec 2, 2021
4afdfe9
fix(type): ensure integer comparison
minorOffense Dec 2, 2021
7c3c0e0
feat(dotenv): manage a distro wide env file
minorOffense Dec 18, 2021
c2a6270
feat(vars): add site specific env vars
minorOffense Dec 18, 2021
67b4e90
Merge branch '6.x' into composer-initial
minorOffense Dec 18, 2021
44d639f
fix(ownership): use web_user
minorOffense Jan 19, 2022
70d35e1
feat(settings): populate default settings
minorOffense Feb 8, 2022
b8ca379
fix(composer): require the PHP class first
minorOffense Feb 9, 2022
244f1da
fix(composer): require the PHP class first
minorOffense Feb 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 81 additions & 28 deletions manifests/distro.pp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Defines a drupalsi::distro resource
define drupalsi::distro (
$distribution = 'drupal',
$api_version = 7,
$distro_root = '/var/www/html',
$dotenv = {},
$api_version = 8,
$distro_root = '/var/www/html/drupal',
$distro_docroot = 'web',
$distro_build_type = 'get',
$distro_build_location = 'https://updates.drupal.org/release-history',
$distro_build_type = 'composer',
$distro_build_location = 'https://updates.drupal.org/release-history', # deprecated.
$distro_build_args = {},
$omit_files = {}
)
{

include drush
$omit_files = {}, #deprecated
$owner = 'apache',
) {
include ::drush

if $::osfamily == 'RedHat' {
$web_user = 'apache'
Expand All @@ -30,31 +30,84 @@
if ($distro_build_type == 'composer' or Integer($api_version) >= 8) {
# Do nothing for now.
# @todo run composer install or just leave it be?
exec {"composer-install-drupal-${buildname}":
command => "composer create-project drupal/recommended-project ${distro_root} --remove-vcs",
path => ['/usr/local/bin', '/usr/bin'],
creates => $distro_root,
user => $web_user,
environment => ['HOME=/var/www'],
require => Class['::php'],
}

exec {"create-${buildname}-sites.php":
creates => "${distro_root}/${distro_docroot}/sites/sites.php",
command => "/bin/cp ${distro_root}/${distro_docroot}/sites/example.sites.php ${distro_root}/${distro_docroot}/sites/sites.php"
exec {"composer-require-drush-${buildname}":
command => 'composer require drush/drush',
cwd => $distro_root,
path => ['/usr/local/bin', '/usr/bin'],
subscribe => Exec["composer-install-drupal-${buildname}"],
refreshonly => true,
user => $web_user,
environment => ['HOME=/var/www'],
}
}
elsif ($distro_build_type == 'git') {
include ::git
if has_key($distro_build_args, 'git_branch') {
$branch = join([ '-b ', '"', $distro_build_args['git_branch'], '"'])
} else {
$branch = ''
}

concat {"${distro_root}/.env":
ensure_newline => true,
replace => false,
backup => false,
show_diff => false,
group => $web_user, # @todo use def modififier collector to fix this to webserver user.
# @todo change to use vcsrepo puppet module.
exec {"git-clone-${buildname}":
command => "git clone ${branch} ${distro_build_location} ${distro_root}/${name}",
creates => $distro_root,
path => ['/usr/bin', '/usr/sbin'],
require => Class['git'],
onlyif => "test ! -d ${distro_root}",
timeout => 1800,
}

concat {"${distro_root}/${distro_docroot}/sites.php":
ensure => 'present',
path => "${distro_root}/${distro_docroot}/sites/sites.php",
mode => '0640',
ensure_newline => true,
replace => false,
backup => false,
show_diff => true,
group => $web_user, # @todo use def modififier collector to fix this to webserver user.
require => Exec["create-${buildname}-sites.php"],
$buildaction = "Exec[git-clone-${buildname}]"

# Ensure the file is there even if it's blank.
file {"${distro_root}/sites/sites.php":
ensure => 'present',
require => Exec["git-clone-${buildname}"],
mode => '0644',
}
}

exec {"create-${buildname}-sites.php":
creates => "${distro_root}/${distro_docroot}/sites/sites.php",
command => "/bin/cp ${distro_root}/${distro_docroot}/sites/example.sites.php ${distro_root}/${distro_docroot}/sites/sites.php"
}

# Add an env file.
concat {"${distro_root}/.env":
ensure_newline => true,
replace => false,
backup => false,
show_diff => false,
group => $web_user, # @todo use def modififier collector to fix this to webserver user.
}

# Add require env varialbes.
concat::fragment {"${distro_root}-envvars":
target => "${distro_root}/.env",
content => dotenv($dotenv),
order => '01'
}

concat {"${distro_root}/${distro_docroot}/sites.php":
ensure => 'present',
path => "${distro_root}/${distro_docroot}/sites/sites.php",
mode => '0640',
ensure_newline => true,
replace => false,
backup => false,
show_diff => true,
group => $web_user, # @todo use def modififier collector to fix this to webserver user.
require => Exec["create-${buildname}-sites.php"],
}
}

2 changes: 1 addition & 1 deletion manifests/distros.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Generate Drupal distro instances.
class drupalsi::distros {
$distros = lookup('drupalsi::distros', {default_value => {}})
create_resources(drupalsi::distro, $distros)
ensure_resources(drupalsi::distro, $distros)
}
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
include ::drupalsi::distros

# Assume jq is available. If other modules want to fix deps go for it.
ensure_packages('jq', {'ensure' => 'present'})
ensure_packages('jq')

# Add the script to set the Drupal directory permissions.
file {'drupal-fix-permissions-script':
Expand Down
35 changes: 25 additions & 10 deletions manifests/site.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
String $tmp_dir = '',
Hash $cron_schedule = {},
Hash $site_aliases = {},
Hash $dotenv = {},
Boolean $auto_alias = true,
Variant[Array[String], String] $local_settings = [],
Array[String] $domain_names = [],
Expand All @@ -30,11 +31,10 @@
include ::stdlib

$distros = lookup('drupalsi::distros')
$distro_root = $distros[$distro]['distro_root']

# Build the site root based on the distro information if siteroot is not specified.
if (empty($siteroot)) {

$distro_root = $distros[$distro]['distro_root']
$distro_docroot = empty($distros[$distro]['distro_docroot']) ? {
true => 'web',
false => $distros[$distro]['distro_docroot']
Expand Down Expand Up @@ -132,6 +132,20 @@
group => $webserver_user # @todo use def modififier collector to fix this to webserver user.
}

# Populate the settings.php file with the default values.
concat::fragment {"drupalsi-${name}-default-settings-php":
target => "${site_root}/sites/${sitessubdir}/settings.php",
source => "${site_root}/sites/${sitessubdir}/default.settings.php",
order => '0'
}

# Add reference to settings.local.php
concat::fragment {"drupalsi-${name}-settings-require}":
target => "${site_root}/sites/${sitessubdir}/settings.php",
content => "if (file_exists(__DIR__ . '/settings.local.php')) {include_once __DIR__ . '/settings.local.php';}",
order => '100',
}

concat {"${site_root}/sites/${sitessubdir}/settings.local.php":
ensure => 'present',
path => "${site_root}/sites/${sitessubdir}/settings.local.php",
Expand All @@ -143,18 +157,19 @@
group => $webserver_user # @todo use def modififier collector to fix this to webserver user.
}

concat::fragment {"drupalsi-${name}-settings-require}":
target => "${site_root}/sites/${sitessubdir}/settings.php",
content => "if (file_exists(__DIR__ . '/settings.local.php')) {include_once __DIR__ . '/settings.local.php';}",
order => '100',
}

# Add entries into sites.php
$site_alias_defaults = {
'directory' => $sitessubdir,
'target' => "${site_root}/sites/sites.php",
}

# Add require env varialbes to the distro env file.
concat::fragment {"${name}-envvars":
target => "${distro_root}/.env",
content => dotenv($dotenv),
order => '05'
}

# Create the sites.php entries.
$domain_names.each |$domain_name| {
validate_domain_name($domain_name)
Expand All @@ -176,7 +191,7 @@
}
}

create_resources(drupalsi::site::site_alias, $site_alias, $site_alias_defaults)
create_resources(drupalsi::site::setting, $trusted_host)
ensure_resources(drupalsi::site::site_alias, $site_alias, $site_alias_defaults)
ensure_resources(drupalsi::site::setting, $trusted_host)
}
}
2 changes: 1 addition & 1 deletion manifests/sites.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Generate Drupal sites.
class drupalsi::sites {
$sites = lookup('drupalsi::sites', {default_value => {}})
create_resources(drupalsi::site, $sites)
ensure_resources(drupalsi::site, $sites)
}
44 changes: 5 additions & 39 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "coldfrontlabs-drupalsi",
"version": "0.5.5",
"version": "6.1.0",
"author": "coldfrontlabs",
"summary": "Define Drupal sites, installation profiles and distributions to be installed.",
"license": "GPL, Version 2.0",
"license": "GPL Version 2.0",
"source": "https://github.com/coldfrontlabs/coldfrontlabs-drupalsi",
"project_page": "https://github.com/coldfrontlabs/coldfrontlabs-drupalsi",
"issues_url": "https://github.com/coldfrontlabs/coldfrontlabs-drupalsi/issues",
Expand All @@ -17,42 +17,8 @@
"version_requirement": ">= 0.4.3"
},
{
"name": "maestrodev/wget",
"version_requirement": ">= 1.7.0"
},
{
"name": "stahnma/epel",
"version_requirement": ">= 1.3.1"
}
],
"operatingsystem_support": [
{
"operatingsystem": "CentOS",
"operatingsystemrelease": ["7"]
},
{
"operatingsystem": "OracleLinux",
"operatingsystemrelease": ["7"]
},
{
"operatingsystem": "RedHat",
"operatingsystemrelease": ["8"]
},
{
"operatingsystem": "Scientific",
"operatingsystemrelease": ["7"]
},
{
"operatingsystem": "Debian",
"operatingsystemrelease": ["9"]
},
{
"operatingsystem": "Ubuntu",
"operatingsystemrelease": ["18.04"]
},
{
"operatingsystem": "windows",
"operatingsystemrelease": ["2019", "10"]
"name": "spy/dotenv",
"version_requirement": ">= 1.0.1"
}
],
"requirements": [
Expand All @@ -64,4 +30,4 @@
"pdk-version": "1.17.0",
"template-url": "pdk-default#1.17.0",
"template-ref": "tags/1.17.0-0-gd3a4319"
}
}
4 changes: 0 additions & 4 deletions templates/drush.make.erb

This file was deleted.

10 changes: 10 additions & 0 deletions templates/htaccess-private.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
<IfModule mod_php5.c>
php_flag engine off
</IfModule>

# If we know how to do it safely, disable the PHP engine entirely.
<IfModule mod_php7.c>
php_flag engine off
</IfModule>

# If we know how to do it safely, disable the PHP engine entirely.
<IfModule mod_php8.c>
php_flag engine off
</IfModule>
10 changes: 10 additions & 0 deletions templates/htaccess-public.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
<IfModule mod_php5.c>
php_flag engine off
</IfModule>

# If we know how to do it safely, disable the PHP engine entirely.
<IfModule mod_php7.c>
php_flag engine off
</IfModule>

# If we know how to do it safely, disable the PHP engine entirely.
<IfModule mod_php8.c>
php_flag engine off
</IfModule>