2 # You can have redis on a different box
3 RAILS_ENV: 'production'
6 # this gives us very good cache coverage, 96 -> 99
7 # in practice it is 1-2% perf improvement
8 RUBY_GLOBAL_METHOD_CACHE_SIZE: 131072
9 # stop heap doubling in size so aggressively, this conserves memory
10 RUBY_GC_HEAP_GROWTH_MAX_SLOTS: 40000
11 RUBY_GC_HEAP_INIT_SLOTS: 400000
12 RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR: 1.5
14 DISCOURSE_DB_SOCKET: /var/run/postgresql
20 # SSH key is required for remote access into the container
23 home: /var/www/discourse
27 # see: https://www.imagemagick.org/discourse-server/viewtopic.php?f=4&t=29588
29 filename: /usr/local/etc/ImageMagick-6/policy.xml
33 <policy domain="coder" rights="none" pattern="EPHEMERAL" />
34 <policy domain="coder" rights="none" pattern="URL" />
35 <policy domain="coder" rights="none" pattern="HTTPS" />
36 <policy domain="coder" rights="none" pattern="MVG" />
37 <policy domain="coder" rights="none" pattern="MSL" />
38 <policy domain="coder" rights="none" pattern="TEXT" />
39 <policy domain="coder" rights="none" pattern="SHOW" />
40 <policy domain="coder" rights="none" pattern="WIN" />
41 <policy domain="coder" rights="none" pattern="PLT" />
43 - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_SMTP_ADDRESS"] == "smtp.example.com"; puts "Aborting! Mail is not configured!"; exit 1; end'
44 - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_HOSTNAME"] == "discourse.example.com"; puts "Aborting! Domain is not configured!"; exit 1; end'
45 - exec: chown -R discourse /home/discourse
46 # TODO: move to base image (anacron can not be fired up using rc.d)
47 - exec: rm -f /etc/cron.d/anacron
49 path: /etc/cron.d/anacron
52 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
54 30 7 * * * root /usr/sbin/anacron -s >/dev/null
56 path: /etc/runit/1.d/copy-env
61 conf=/var/www/discourse/config/discourse.conf
63 # find DISCOURSE_ env vars, strip the leader, lowercase the key
64 /usr/local/bin/ruby -e 'ENV.each{|k,v| puts "#{$1.downcase} = #{v}" if k =~ /^DISCOURSE_(.*)/}' > $conf
67 path: /etc/runit/1.d/enable-brotli
71 [ ! -z "$COMPRESS_BROTLI" ] && sed -i "s/. brotli/ brotli/" /etc/nginx/conf.d/discourse.conf || sed -i "s/. brotli/# brotli/" /etc/nginx/conf.d/discourse.conf
74 path: /etc/service/unicorn/run
82 chown -R discourse:www-data /shared/log/rails
83 LD_PRELOAD=$RUBY_ALLOCATOR 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
86 path: /etc/service/nginx/run
94 path: /etc/runit/3.d/01-nginx
101 path: /etc/runit/3.d/02-unicorn
113 - git remote set-branches --add origin master
115 - git fetch origin $version
116 - git checkout $version
118 - mkdir -p tmp/sockets
120 - mkdir -p /shared/log/rails
121 - bash -c "touch -a /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log"
122 - bash -c "ln -s /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log $home/log"
123 - bash -c "mkdir -p /shared/{uploads,backups}"
124 - bash -c "ln -s /shared/{uploads,backups} $home/public"
125 - chown -R discourse:www-data /shared/log/rails /shared/uploads /shared/backups
129 - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
130 - "rm /etc/nginx/sites-enabled/default"
131 - "mkdir -p /var/nginx/cache"
134 filename: /etc/nginx/nginx.conf
135 from: pid /run/nginx.pid;
139 filename: "/etc/nginx/conf.d/discourse.conf"
140 from: /upstream[^\}]+\}/m
141 to: "upstream discourse {
142 server 127.0.0.1:3000;
146 filename: "/etc/nginx/conf.d/discourse.conf"
147 from: /server_name.+$/
151 filename: "/etc/nginx/conf.d/discourse.conf"
152 from: /client_max_body_size.+$/
153 to: client_max_body_size $upload_size ;
156 cmd: echo "done configuring web"
163 # ensure we are on latest bundler
165 - chown -R discourse $home
171 - su discourse -c 'bundle install --deployment --verbose --without test --without development'
172 - su discourse -c 'bundle exec rake db:migrate'
173 - su discourse -c 'bundle exec rake assets:precompile'
176 path: /usr/local/bin/discourse
180 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/discourse "$@")
183 path: /usr/local/bin/rails
187 # If they requested a console, load pry instead
188 if [ "$*" == "c" -o "$*" == "console" ]
190 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec pry -r ./config/environment)
192 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/rails "$@")
196 path: /usr/local/bin/rake
200 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec bin/rake "$@")
203 path: /etc/update-motd.d/10-web
208 echo Use: rails, rake or discourse to execute commands in production
212 path: /etc/logrotate.d/rails
214 /shared/log/rails/*.log
229 path: /etc/logrotate.d/nginx
231 /var/log/nginx/*.log {
238 create 0640 www-data www-data
245 # move state out of the container this fancy is done to support rapid rebuilds of containers,
246 # we store anacron and logrotate state outside the container to ensure its maintained across builds
247 # later move this snipped into an intialization script
248 # we also ensure all the symlinks we need to /shared are in place in the correct structure
249 # this allows us to bootstrap on one machine and then run on another
251 path: /etc/runit/1.d/00-ensure-links
255 if [[ ! -L /var/lib/logrotate ]]; then
256 rm -fr /var/lib/logrotate
257 mkdir -p /shared/state/logrotate
258 ln -s /shared/state/logrotate /var/lib/logrotate
260 if [[ ! -L /var/spool/anacron ]]; then
261 rm -fr /var/spool/anacron
262 mkdir -p /shared/state/anacron-spool
263 ln -s /shared/state/anacron-spool /var/spool/anacron
265 if [[ ! -d /shared/log/rails ]]; then
266 mkdir -p /shared/log/rails
267 chown -R discourse:www-data /shared/log/rails
269 if [[ ! -d /shared/uploads ]]; then
270 mkdir -p /shared/uploads
271 chown -R discourse:www-data /shared/uploads
273 if [[ ! -d /shared/backups ]]; then
274 mkdir -p /shared/backups
275 chown -R discourse:www-data /shared/backups
278 # change login directory to Discourse home
280 path: /root/.bash_profile