Update ImageMagick security patch for CVE-2016–3714 to latest recommendation
[discourse_docker.git] / templates / web.template.yml
1 env:
2 # You can have redis on a different box
3 RAILS_ENV: 'production'
4 UNICORN_WORKERS: 3
5 UNICORN_SIDEKIQS: 1
6 # slightly less aggressive than "recommendation" but works fine with oobgc
7 RUBY_GC_MALLOC_LIMIT: 40000000
8 # this ensures we have enough heap space to handle a big pile of small reqs
9 RUBY_HEAP_MIN_SLOTS: 800000
10
11 DISCOURSE_DB_SOCKET: /var/run/postgresql
12 DISCOURSE_DB_HOST:
13 DISCOURSE_DB_PORT:
14
15
16 params:
17 # SSH key is required for remote access into the container
18 version: tests-passed
19
20 home: /var/www/discourse
21 upload_size: 10m
22
23 run:
24 # see: https://www.imagemagick.org/discourse-server/viewtopic.php?f=4&t=29588
25 - replace:
26 filename: /usr/local/etc/ImageMagick-6/policy.xml
27 from: "<policymap>"
28 to: |
29 <policymap>
30 <policy domain="coder" rights="none" pattern="EPHEMERAL" />
31 <policy domain="coder" rights="none" pattern="URL" />
32 <policy domain="coder" rights="none" pattern="HTTPS" />
33 <policy domain="coder" rights="none" pattern="MVG" />
34 <policy domain="coder" rights="none" pattern="MSL" />
35 <policy domain="coder" rights="none" pattern="TEXT" />
36 <policy domain="coder" rights="none" pattern="SHOW" />
37 <policy domain="coder" rights="none" pattern="WIN" />
38 <policy domain="coder" rights="none" pattern="PLT" />
39
40 - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_SMTP_ADDRESS"] == "smtp.example.com"; puts "Aborting! Mail is not configured!"; exit 1; end'
41 - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_HOSTNAME"] == "discourse.example.com"; puts "Aborting! Domain is not configured!"; exit 1; end'
42 - exec: chown -R discourse /home/discourse
43 - file:
44 path: /etc/runit/1.d/copy-env
45 chmod: "+x"
46 contents: |
47 #!/bin/bash
48 env > ~/boot_env
49 conf=/var/www/discourse/config/discourse.conf
50
51 # find DISCOURSE_ env vars, strip the leader, lowercase the key
52 /usr/local/bin/ruby -e 'ENV.each{|k,v| puts "#{$1.downcase} = #{v}" if k =~ /^DISCOURSE_(.*)/}' > $conf
53
54 - file:
55 path: /etc/runit/1.d/ensure-web-nginx-read
56 chmod: "+x"
57 contents: |
58 #!/bin/bash
59 mkdir -p /var/log/nginx
60 chgrp -R www-data /var/log/nginx
61 chgrp www-data /var/log/nginx
62
63 - file:
64 path: /etc/service/unicorn/run
65 chmod: "+x"
66 contents: |
67 #!/bin/bash
68 exec 2>&1
69 # redis
70 # postgres
71 cd $home
72 chown -R discourse:www-data /shared/log/rails
73 LD_PRELOAD=/usr/lib/libjemalloc.so.1 HOME=/home/discourse USER=discourse exec chpst -u discourse:www-data -U discourse:www-data bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb
74
75 - file:
76 path: /etc/service/nginx/run
77 chmod: "+x"
78 contents: |
79 #!/bin/sh
80 exec 2>&1
81 exec /usr/sbin/nginx
82
83 - file:
84 path: /etc/runit/3.d/01-nginx
85 chmod: "+x"
86 contents: |
87 #!/bin/bash
88 sv stop nginx
89
90 - file:
91 path: /etc/runit/3.d/02-unicorn
92 chmod: "+x"
93 contents: |
94 #!/bin/bash
95 sv stop unicorn
96
97 - exec:
98 cd: $home
99 hook: code
100 cmd:
101 - git reset --hard
102 - git clean -f
103 - git remote set-branches --add origin master
104 - git pull
105 - git fetch origin $version
106 - git checkout $version
107 - mkdir -p tmp/pids
108 - mkdir -p tmp/sockets
109 - touch tmp/.gitkeep
110 - mkdir -p /shared/log/rails
111 - bash -c "touch -a /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log"
112 - bash -c "ln -s /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log $home/log"
113 - bash -c "mkdir -p /shared/{uploads,backups}"
114 - bash -c "ln -s /shared/{uploads,backups} $home/public"
115 - chown -R discourse:www-data /shared/log/rails /shared/uploads /shared/backups
116
117 - exec:
118 cmd:
119 - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
120 - "rm /etc/nginx/sites-enabled/default"
121 - "mkdir -p /var/nginx/cache"
122
123 - replace:
124 filename: /etc/nginx/nginx.conf
125 from: pid /run/nginx.pid;
126 to: daemon off;
127
128 - replace:
129 filename: "/etc/nginx/conf.d/discourse.conf"
130 from: /upstream[^\}]+\}/m
131 to: "upstream discourse {
132 server 127.0.0.1:3000;
133 }"
134
135 - replace:
136 filename: "/etc/nginx/conf.d/discourse.conf"
137 from: /server_name.+$/
138 to: server_name _ ;
139
140 - replace:
141 filename: "/etc/nginx/conf.d/discourse.conf"
142 from: /client_max_body_size.+$/
143 to: client_max_body_size $upload_size ;
144
145 - exec:
146 cmd: echo "done configuring web"
147 hook: web_config
148
149 - exec:
150 cd: $home
151 hook: web
152 cmd:
153 # ensure we are on latest bundler
154 - gem update bundler
155 - chown -R discourse $home
156
157 - exec:
158 cd: $home
159 hook: bundle_exec
160 cmd:
161 - su discourse -c 'bundle install --deployment --verbose --without test --without development'
162 - su discourse -c 'bundle exec rake db:migrate'
163 - su discourse -c 'bundle exec rake assets:precompile'
164
165 - file:
166 path: /usr/local/bin/discourse
167 chmod: +x
168 contents: |
169 #!/bin/bash
170 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/discourse "$@")
171
172 - file:
173 path: /usr/local/bin/rails
174 chmod: +x
175 contents: |
176 #!/bin/bash
177 # If they requested a console, load pry instead
178 if [ "$*" == "c" -o "$*" == "console" ]
179 then
180 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec pry -r ./config/environment)
181 else
182 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/rails "$@")
183 fi
184
185 - file:
186 path: /usr/local/bin/rake
187 chmod: +x
188 contents: |
189 #!/bin/bash
190 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec bin/rake "$@")
191
192 - file:
193 path: /etc/update-motd.d/10-web
194 chmod: +x
195 contents: |
196 #!/bin/bash
197 echo
198 echo Use: rails, rake or discourse to execute commands in production
199 echo
200
201 - file:
202 path: /etc/logrotate.d/rails
203 contents: |
204 /shared/log/rails/*.log
205 {
206 rotate 14
207 dateext
208 daily
209 missingok
210 notifempty
211 delaycompress
212 compress
213 postrotate
214 sv 1 unicorn
215 endscript
216 }
217
218 - file:
219 path: /etc/logrotate.d/nginx
220 contents: |
221 /var/log/nginx/*.log {
222 daily
223 missingok
224 rotate 14
225 compress
226 delaycompress
227 notifempty
228 create 0640 www-data www-data
229 sharedscripts
230 postrotate
231 sv 1 nginx
232 endscript
233 }
234
235 # move state out of the container this fancy is done to support rapid rebuilds of containers,
236 # we store anacron and logrotate state outside the container to ensure its maintained across builds
237 # later move this snipped into an intialization script
238 # we also ensure all the symlinks we need to /shared are in place in the correct structure
239 # this allows us to bootstrap on one machine and then run on another
240 - file:
241 path: /etc/runit/1.d/00-ensure-links
242 chmod: +x
243 contents: |
244 #!/bin/bash
245 if [[ ! -L /var/lib/logrotate ]]; then
246 rm -fr /var/lib/logrotate
247 mkdir -p /shared/state/logrotate
248 ln -s /shared/state/logrotate /var/lib/logrotate
249 fi
250 if [[ ! -L /var/spool/anacron ]]; then
251 rm -fr /var/spool/anacron
252 mkdir -p /shared/state/anacron-spool
253 ln -s /shared/state/anacron-spool /var/spool/anacron
254 fi
255 if [[ ! -d /shared/log/rails ]]; then
256 mkdir -p /shared/log/rails
257 chown -R discourse:www-data /shared/log/rails
258 fi
259 if [[ ! -d /shared/uploads ]]; then
260 mkdir -p /shared/uploads
261 chown -R discourse:www-data /shared/uploads
262 fi
263 if [[ ! -d /shared/backups ]]; then
264 mkdir -p /shared/backups
265 chown -R discourse:www-data /shared/backups
266 fi
267
268 # change login directory to Discourse home
269 - file:
270 path: /root/.bash_profile
271 chmod: 644
272 contents: |
273 cd $home