2 # You can have redis on a different box
3 RAILS_ENV: 'production'
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_GC_HEAP_INIT_SLOTS: 800000
11 DISCOURSE_DB_SOCKET: /var/run/postgresql
17 # SSH key is required for remote access into the container
20 home: /var/www/discourse
24 # see: https://www.imagemagick.org/discourse-server/viewtopic.php?f=4&t=29588
26 filename: /usr/local/etc/ImageMagick-6/policy.xml
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" />
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
44 path: /etc/runit/1.d/copy-env
49 conf=/var/www/discourse/config/discourse.conf
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
55 path: /etc/runit/1.d/ensure-web-nginx-read
59 mkdir -p /var/log/nginx
60 chgrp -R www-data /var/log/nginx
61 chgrp www-data /var/log/nginx
64 path: /etc/service/unicorn/run
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
76 path: /etc/service/nginx/run
84 path: /etc/runit/3.d/01-nginx
91 path: /etc/runit/3.d/02-unicorn
103 - git remote set-branches --add origin master
105 - git fetch origin $version
106 - git checkout $version
108 - mkdir -p tmp/sockets
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
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"
124 filename: /etc/nginx/nginx.conf
125 from: pid /run/nginx.pid;
129 filename: "/etc/nginx/conf.d/discourse.conf"
130 from: /upstream[^\}]+\}/m
131 to: "upstream discourse {
132 server 127.0.0.1:3000;
136 filename: "/etc/nginx/conf.d/discourse.conf"
137 from: /server_name.+$/
141 filename: "/etc/nginx/conf.d/discourse.conf"
142 from: /client_max_body_size.+$/
143 to: client_max_body_size $upload_size ;
146 cmd: echo "done configuring web"
153 # ensure we are on latest bundler
155 - chown -R discourse $home
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'
166 path: /usr/local/bin/discourse
170 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/discourse "$@")
173 path: /usr/local/bin/rails
177 # If they requested a console, load pry instead
178 if [ "$*" == "c" -o "$*" == "console" ]
180 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec pry -r ./config/environment)
182 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/rails "$@")
186 path: /usr/local/bin/rake
190 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec bin/rake "$@")
193 path: /etc/update-motd.d/10-web
198 echo Use: rails, rake or discourse to execute commands in production
202 path: /etc/logrotate.d/rails
204 /shared/log/rails/*.log
219 path: /etc/logrotate.d/nginx
221 /var/log/nginx/*.log {
228 create 0640 www-data www-data
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
241 path: /etc/runit/1.d/00-ensure-links
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
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
255 if [[ ! -d /shared/log/rails ]]; then
256 mkdir -p /shared/log/rails
257 chown -R discourse:www-data /shared/log/rails
259 if [[ ! -d /shared/uploads ]]; then
260 mkdir -p /shared/uploads
261 chown -R discourse:www-data /shared/uploads
263 if [[ ! -d /shared/backups ]]; then
264 mkdir -p /shared/backups
265 chown -R discourse:www-data /shared/backups
268 # change login directory to Discourse home
270 path: /root/.bash_profile