OLD | NEW |
1 class rietveld( | 1 class rietveld( |
2 $domain, | 2 $domain, |
3 $certificate, | 3 $certificate, |
4 $private_key, | 4 $private_key, |
5 $is_default = false, | 5 $is_default = false, |
6 $secret_key = hiera('rietveld::secret_key', ''), | 6 $secret_key = hiera('rietveld::secret_key', ''), |
7 $fixtures = hiera('rietveld::fixtures', {}), | 7 $admins = hiera('rietveld::admins', []), |
8 $database = hiera('rietveld::database', { | 8 $oauth2_client_id = hiera('rietveld::oauth2_client_id', ''), |
9 'engine' => 'sqlite3', | 9 $oauth2_client_secret = hiera('rietveld::oauth2_client_secret', ''), |
10 'name' => 'dev.db', | |
11 }), | |
12 ) { | 10 ) { |
13 | 11 |
14 include nginx | 12 include nginx |
15 $django_home = '/home/rietveld/django-gae2django' | 13 $rietveld_home = '/opt/rietveld' |
16 $rietveld_home = "${django_home}/examples/rietveld" | |
17 | 14 |
18 Exec { | 15 Exec { |
19 path => '/usr/bin:/usr/sbin:/bin:/usr/local/bin', | 16 path => '/usr/bin:/usr/sbin:/bin:/usr/local/bin', |
20 } | 17 } |
21 | 18 |
22 nginx::hostconfig {$domain: | 19 nginx::hostconfig {$domain: |
23 source => 'puppet:///modules/rietveld/site.conf', | 20 source => 'puppet:///modules/rietveld/site.conf', |
24 is_default => $is_default, | 21 is_default => $is_default, |
25 certificate => $certificate, | 22 certificate => $certificate, |
26 private_key => $private_key, | 23 private_key => $private_key, |
27 log => 'access_log_codereview' | 24 log => 'access_log_codereview' |
28 } | 25 } |
29 | 26 |
30 package {['python-django', 'make', 'patch', 'gunicorn']: ensure => present} | 27 package {['wget', 'unzip', 'git', 'make', 'patch', 'subversion']: ensure => pr
esent} |
31 | 28 |
32 user {'rietveld': | 29 user {'rietveld': |
33 ensure => present, | 30 ensure => present, |
34 comment => 'User of the rietveld installation', | 31 comment => 'User of the rietveld installation', |
35 home => '/home/rietveld', | 32 home => '/home/rietveld', |
36 managehome => true | 33 managehome => true |
37 } | 34 } |
38 | 35 |
39 exec {'get_rietveld': | 36 exec {'download_appengine': |
40 command => "hg clone https://hg.adblockplus.org/gae2django/ ${django_home}/"
, | 37 # TODO: We cannot rely on this URL to stay fixed |
41 require => Package['mercurial'], | 38 command => 'wget -O /home/rietveld/google_appengine.zip https://storage.goog
leapis.com/appengine-sdks/featured/google_appengine_1.9.21.zip', |
42 user => rietveld, | 39 user => 'root', |
43 onlyif => "test ! -d ${django_home}", | 40 creates => '/home/rietveld/google_appengine.zip', |
| 41 require => [User['rietveld'], Package['wget']], |
44 } | 42 } |
45 | 43 |
46 file {"${rietveld_home}/Makefile": | 44 exec {'install_appengine': |
47 ensure => file, | 45 command => 'unzip /home/rietveld/google_appengine.zip -d /opt', |
48 owner => rietveld, | 46 user => 'root', |
49 require => Exec['get_rietveld'], | 47 creates => '/opt/google_appengine', |
50 source => 'puppet:///modules/rietveld/Makefile', | 48 require => [Exec['download_appengine'], Package['unzip']], |
51 } | 49 } |
52 | 50 |
53 file {"${rietveld_home}/settings.py": | 51 exec {'get_rietveld': |
54 ensure => file, | 52 command => "git clone https://github.com/rietveld-codereview/rietveld.git $r
ietveld_home && cd $rietveld_home && git reset --HARD 87257f5", |
55 owner => rietveld, | 53 user => 'root', |
56 require => Exec['get_rietveld'], | 54 require => Package['git'], |
57 content => template('rietveld/settings.py.erb'), | 55 creates => $rietveld_home, |
58 } | 56 } |
59 | 57 |
60 exec {'install_rietveld': | 58 exec {'setup_rietveld': |
61 command => "make all", | 59 command => 'make update_revision mapreduce', |
62 cwd => "${rietveld_home}", | 60 cwd => $rietveld_home, |
63 user => rietveld, | 61 user => root, |
64 require => [ | 62 require => [Exec['get_rietveld'], Package['make', 'patch', 'subversion']], |
65 File["${rietveld_home}/Makefile"], | 63 creates => "${rietveld_home}/mapreduce", |
66 File["${rietveld_home}/settings.py"]], | |
67 onlyif => "test ! -e ${$rietveld_home}/gae2django", | |
68 } | 64 } |
69 | 65 |
70 file {'/etc/init/rietveld.conf': | 66 file {'/opt/wrappers': |
| 67 ensure => directory, |
| 68 owner => 'root', |
| 69 } |
| 70 |
| 71 file {'wrapper.py': |
| 72 path => '/opt/wrappers/wrapper.py', |
71 ensure => file, | 73 ensure => file, |
72 owner => root, | 74 owner => 'root', |
73 source => 'puppet:///modules/rietveld/rietveld.conf', | 75 mode => '0755', |
| 76 source => 'puppet:///modules/rietveld/wrapper.py', |
74 notify => Service['rietveld'], | 77 notify => Service['rietveld'], |
75 } | 78 } |
76 | 79 |
77 file {'/etc/init.d/rietveld': | 80 file {'dev_appserver.py': |
| 81 path => '/opt/wrappers/dev_appserver.py', |
78 ensure => link, | 82 ensure => link, |
79 target => '/lib/init/upstart-job', | 83 require => File['wrapper.py'], |
80 require => [File['/etc/init/rietveld.conf'], Exec['install_rietveld']] | 84 target => '/opt/wrappers/wrapper.py', |
81 } | 85 } |
82 | 86 |
83 service {'rietveld': | 87 file {'_python_runtime.py': |
84 ensure => running, | 88 path => '/opt/wrappers/_python_runtime.py', |
85 hasstatus => false, | 89 ensure => link, |
86 require => [Package['gunicorn'], File['/etc/init.d/rietveld']] | 90 require => File['wrapper.py'], |
| 91 target => '/opt/wrappers/wrapper.py', |
87 } | 92 } |
88 | 93 |
89 file {"${rietveld_home}/fixtures": | 94 file {'/var/lib/rietveld': |
90 ensure => directory, | 95 ensure => directory, |
91 owner => 'rietveld', | 96 owner => 'rietveld', |
92 mode => 0750, | |
93 require => Exec['install_rietveld'], | |
94 } | 97 } |
95 | 98 |
96 define fixture( | 99 file {'config.ini': |
97 $ensure = present, | 100 path => '/var/lib/rietveld/config.ini', |
98 $source = undef, | 101 ensure => file, |
99 $content = undef, | 102 owner => 'root', |
100 ) { | 103 content => template('rietveld/config.ini.erb'), |
101 | 104 notify => Service['rietveld'], |
102 # Note that $script will return EXIT_SUCCESS when the .type is | |
103 # not recognized - although no action is done then. Thus we enforce | |
104 # JSON here, which is the default for command "dumpdata" anyway: | |
105 $script = "${rietveld::rietveld_home}/manage.py" | |
106 $destination = "${rietveld::rietveld_home}/fixtures/$name.json" | |
107 | |
108 exec {$destination: | |
109 command => shellquote($script, 'loaddata', $destination), | |
110 cwd => $rietveld::rietveld_home, | |
111 refreshonly => true, | |
112 user => 'rietveld', | |
113 } | |
114 | |
115 file {$destination: | |
116 ensure => $ensure, | |
117 content => $content, | |
118 source => $source, | |
119 owner => 'rietveld', | |
120 mode => 0640, | |
121 notify => $ensure ? { | |
122 present => Exec[$destination], | |
123 default => [], | |
124 } | |
125 } | |
126 } | 105 } |
127 | 106 |
128 create_resources(rietveld::fixture, $fixtures) | 107 customservice {'rietveld': |
| 108 command => "/opt/wrappers/dev_appserver.py \ |
| 109 --enable_sendmail --skip_sdk_update_check |
| 110 --port 8080 ${rietveld_home}", |
| 111 user => 'rietveld', |
| 112 require => [ |
| 113 Exec['install_appengine', 'setup_rietveld'], |
| 114 File['dev_appserver.py', '_python_runtime.py', 'config.ini'], |
| 115 ], |
| 116 } |
129 } | 117 } |
OLD | NEW |