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
10 DISCOURSE_DB_SOCKET: /var/run/postgresql
16 # SSH key is required for remote access into the container
19 home: /var/www/discourse
23 # see: https://www.imagemagick.org/discourse-server/viewtopic.php?f=4&t=29588
25 filename: /usr/local/etc/ImageMagick-6/policy.xml
29 <policy domain="coder" rights="none" pattern="EPHEMERAL" />
30 <policy domain="coder" rights="none" pattern="URL" />
31 <policy domain="coder" rights="none" pattern="HTTPS" />
32 <policy domain="coder" rights="none" pattern="MVG" />
33 <policy domain="coder" rights="none" pattern="MSL" />
34 <policy domain="coder" rights="none" pattern="TEXT" />
35 <policy domain="coder" rights="none" pattern="SHOW" />
36 <policy domain="coder" rights="none" pattern="WIN" />
37 <policy domain="coder" rights="none" pattern="PLT" />
39 - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_SMTP_ADDRESS"] == "smtp.example.com"; puts "Aborting! Mail is not configured!"; exit 1; end'
40 - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_HOSTNAME"] == "discourse.example.com"; puts "Aborting! Domain is not configured!"; exit 1; end'
41 - exec: chown -R discourse /home/discourse
43 path: /etc/runit/1.d/copy-env
48 conf=/var/www/discourse/config/discourse.conf
50 # find DISCOURSE_ env vars, strip the leader, lowercase the key
51 /usr/local/bin/ruby -e 'ENV.each{|k,v| puts "#{$1.downcase} = #{v}" if k =~ /^DISCOURSE_(.*)/}' > $conf
54 path: /etc/runit/1.d/ensure-web-nginx-read
58 mkdir -p /var/log/nginx
59 chgrp -R www-data /var/log/nginx
60 chgrp www-data /var/log/nginx
63 path: /etc/service/unicorn/run
71 chown -R discourse:www-data /shared/log/rails
72 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
75 path: /etc/service/nginx/run
83 path: /etc/runit/3.d/01-nginx
90 path: /etc/runit/3.d/02-unicorn
102 - git remote set-branches --add origin master
104 - git fetch origin $version
105 - git checkout $version
107 - mkdir -p tmp/sockets
109 - mkdir -p /shared/log/rails
110 - bash -c "touch -a /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log"
111 - bash -c "ln -s /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log $home/log"
112 - bash -c "mkdir -p /shared/{uploads,backups}"
113 - bash -c "ln -s /shared/{uploads,backups} $home/public"
114 - chown -R discourse:www-data /shared/log/rails /shared/uploads /shared/backups
118 - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
119 - "rm /etc/nginx/sites-enabled/default"
120 - "mkdir -p /var/nginx/cache"
123 filename: /etc/nginx/nginx.conf
124 from: pid /run/nginx.pid;
128 filename: "/etc/nginx/conf.d/discourse.conf"
129 from: /upstream[^\}]+\}/m
130 to: "upstream discourse {
131 server 127.0.0.1:3000;
135 filename: "/etc/nginx/conf.d/discourse.conf"
136 from: /server_name.+$/
140 filename: "/etc/nginx/conf.d/discourse.conf"
141 from: /client_max_body_size.+$/
142 to: client_max_body_size $upload_size ;
145 cmd: echo "done configuring web"
152 # ensure we are on latest bundler
154 - chown -R discourse $home
160 - su discourse -c 'bundle install --deployment --verbose --without test --without development'
161 - su discourse -c 'bundle exec rake db:migrate'
162 - su discourse -c 'bundle exec rake assets:precompile'
165 path: /usr/local/bin/discourse
169 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/discourse "$@")
172 path: /usr/local/bin/rails
176 # If they requested a console, load pry instead
177 if [ "$*" == "c" -o "$*" == "console" ]
179 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec pry -r ./config/environment)
181 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/rails "$@")
185 path: /usr/local/bin/rake
189 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec bin/rake "$@")
192 path: /etc/update-motd.d/10-web
197 echo Use: rails, rake or discourse to execute commands in production
201 path: /etc/logrotate.d/rails
203 /shared/log/rails/*.log
218 path: /etc/logrotate.d/nginx
220 /var/log/nginx/*.log {
227 create 0640 www-data www-data
234 # move state out of the container this fancy is done to support rapid rebuilds of containers,
235 # we store anacron and logrotate state outside the container to ensure its maintained across builds
236 # later move this snipped into an intialization script
237 # we also ensure all the symlinks we need to /shared are in place in the correct structure
238 # this allows us to bootstrap on one machine and then run on another
240 path: /etc/runit/1.d/00-ensure-links
244 if [[ ! -L /var/lib/logrotate ]]; then
245 rm -fr /var/lib/logrotate
246 mkdir -p /shared/state/logrotate
247 ln -s /shared/state/logrotate /var/lib/logrotate
249 if [[ ! -L /var/spool/anacron ]]; then
250 rm -fr /var/spool/anacron
251 mkdir -p /shared/state/anacron-spool
252 ln -s /shared/state/anacron-spool /var/spool/anacron
254 if [[ ! -d /shared/log/rails ]]; then
255 mkdir -p /shared/log/rails
256 chown -R discourse:www-data /shared/log/rails
258 if [[ ! -d /shared/uploads ]]; then
259 mkdir -p /shared/uploads
260 chown -R discourse:www-data /shared/uploads
262 if [[ ! -d /shared/backups ]]; then
263 mkdir -p /shared/backups
264 chown -R discourse:www-data /shared/backups
267 # change login directory to Discourse home
269 path: /root/.bash_profile