Puppet Class: phragile

Defined in:
modules/phragile/manifests/init.pp

Overview

Parameters:

  • install_dir (Any) (defaults to: '/var/lib/phragile/phragile')
  • debug (Any) (defaults to: false)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'modules/phragile/manifests/init.pp', line 17

class phragile(
    $install_dir = '/var/lib/phragile/phragile',
    $debug = false,
) {

    requires_realm('labs')
    if os_version('debian == jessie') {
        $php_module = 'php5'
    } else {
        $php_module = 'php'
    }

    class { '::httpd':
        modules => ['rewrite', $php_module],
    }

    require_package(
        "${php_module}-cli",
        "${php_module}-curl",
        "${php_module}-mysql",
        "${php_module}-mcrypt",
    )

    group { 'phragile':
        ensure => present,
    }

    $phragile_home = '/var/lib/phragile'

    user { 'phragile':
        ensure     => present,
        home       => $phragile_home,
        shell      => '/bin/bash',
        managehome => true,
        system     => true,
    }

    git::clone { 'phragile':
        ensure    => latest,
        directory => $install_dir,
        owner     => 'phragile',
        group     => 'phragile',
        origin    => 'https://github.com/wmde/phragile.git',
    }

    exec { 'mcrypt':
        command => "/usr/sbin/${php_module}enmod mcrypt",
        unless  => '/usr/bin/php -m | /bin/grep -q mcrypt',
        require => [Package["${php_module}-mcrypt"], Package["${php_module}-cli"]],
    }

    exec { 'php_mysql':
        command => "/usr/sbin/${php_module}enmod mysql",
        unless  => '/usr/bin/php -m | /bin/grep -q mysql',
        require => [Package["${php_module}-mysql"], Package["${php_module}-cli"]],
    }

    $composer_dir = "${phragile_home}/composer"
    $composer     = "${composer_dir}/vendor/bin/composer"

    git::clone { 'composer':
        ensure             => 'latest',
        directory          => $composer_dir,
        origin             => 'https://gerrit.wikimedia.org/r/p/integration/composer.git',
        owner              => 'phragile',
        group              => 'phragile',
        recurse_submodules => true,
    }

    exec { 'composer_install':
        environment => "HOME=${phragile_home}",
        cwd         => $install_dir,
        command     => "${composer} install",
        user        => 'phragile',
        require     => [Git::Clone['phragile'], Git::Clone['composer'], Package["${php_module}-mcrypt"], Package["${php_module}-cli"]],
    }

    file { "${install_dir}/.env":
        content => template('phragile/env.erb'),
        require => Git::Clone['phragile'],
        replace => false,
        owner   => 'phragile',
        group   => 'phragile',

    }

    exec { 'update_phragile_app_key':
        command => template('phragile/update_app_key.erb'),
        cwd     => $install_dir,
        user    => 'phragile',
        unless  => "/bin/grep -q ^APP_KEY ${install_dir}/.env",
        require => Exec['composer_install'],
    }

    httpd::conf { 'apache_conf':
        ensure  => present,
        content => template('phragile/apache.conf.erb'),
    }

    file { "${install_dir}/storage":
        ensure  => directory,
        owner   => 'www-data',
        group   => 'www-data',
        mode    => '0775',
        recurse => true,
        require => Git::Clone['phragile'],
    }

    exec { '/usr/bin/php artisan migrate':
        cwd     => $install_dir,
        user    => 'phragile',
        unless  => "/bin/grep -q 'DB_USERNAME=$' ${install_dir}/.env",
        require => Exec['composer_install'],
    }

    cron { 'daily_snapshots':
        ensure  => present,
        command => "/usr/bin/php ${install_dir}/artisan snapshots:create 2>&1 | logger -t phragile-snapshots",
        user    => 'phragile',
        hour    => '2',
        minute  => '0',
        require => Exec['composer_install'],
    }
}