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
22 home: /var/www/discourse
26 - exec: thpoff echo "thpoff is installed!"
27 - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_SMTP_ADDRESS"] == "smtp.example.com"; puts "Aborting! Mail is not configured!"; exit 1; end'
28 - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_HOSTNAME"] == "discourse.example.com"; puts "Aborting! Domain is not configured!"; exit 1; end'
29 - exec: /usr/local/bin/ruby -e 'if (ENV["DISCOURSE_CDN_URL"] || "")[0..1] == "//"; puts "Aborting! CDN must have a protocol specified. Once fixed you should rebake your posts now to correct all posts."; exit 1; end'
30 - exec: chown -R discourse /home/discourse
31 # TODO: move to base image (anacron can not be fired up using rc.d)
32 - exec: rm -f /etc/cron.d/anacron
34 path: /etc/cron.d/anacron
37 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
39 30 7 * * * root /usr/sbin/anacron -s >/dev/null
41 path: /etc/runit/1.d/copy-env
46 conf=/var/www/discourse/config/discourse.conf
48 # find DISCOURSE_ env vars, strip the leader, lowercase the key
49 /usr/local/bin/ruby -e 'ENV.each{|k,v| puts "#{$1.downcase} = '\''#{v}'\''" if k =~ /^DISCOURSE_(.*)/}' > $conf
52 path: /etc/service/unicorn/run
60 chown -R discourse:www-data /shared/log/rails
61 LD_PRELOAD=$RUBY_ALLOCATOR HOME=/home/discourse USER=discourse exec thpoff chpst -u discourse:www-data -U discourse:www-data bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb
64 path: /etc/service/nginx/run
72 path: /etc/runit/3.d/01-nginx
79 path: /etc/runit/3.d/02-unicorn
91 - git remote set-branches --add origin master
93 - git fetch origin $version
94 - git checkout $version
96 - chown discourse:www-data tmp
98 - mkdir -p tmp/sockets
100 - mkdir -p /shared/log/rails
101 - bash -c "touch -a /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr,sidekiq}.log"
102 - bash -c "ln -s /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr,sidekiq}.log $home/log"
103 - bash -c "mkdir -p /shared/{uploads,backups}"
104 - bash -c "ln -s /shared/{uploads,backups} $home/public"
105 - bash -c "mkdir -p /shared/tmp/{backups,restores}"
106 - bash -c "ln -s /shared/tmp/{backups,restores} $home/tmp"
107 - chown -R discourse:www-data /shared/log/rails /shared/uploads /shared/backups /shared/tmp
108 # scrub broken symlinks from plugins that have been removed
109 - find public/plugins/ -maxdepth 1 -xtype l -delete
113 - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
114 - "rm /etc/nginx/sites-enabled/default"
115 - "mkdir -p /var/nginx/cache"
118 filename: /etc/nginx/nginx.conf
119 from: pid /run/nginx.pid;
123 filename: "/etc/nginx/conf.d/discourse.conf"
124 from: /upstream[^\}]+\}/m
125 to: "upstream discourse {
126 server 127.0.0.1:3000;
130 filename: "/etc/nginx/conf.d/discourse.conf"
131 from: /server_name.+$/
135 filename: "/etc/nginx/conf.d/discourse.conf"
136 from: /client_max_body_size.+$/
137 to: client_max_body_size $upload_size ;
140 cmd: echo "done configuring web"
147 # ensure we are on latest bundler
149 - find $home ! -user discourse -exec chown discourse {} \+
155 - su discourse -c 'bundle install --deployment --retry 3 --jobs 4 --verbose --without test development'
160 - su discourse -c 'bundle exec rake plugin:pull_compatible_all'
167 - su discourse -c 'bundle exec rake db:migrate'
170 hook: assets_precompile
172 - su discourse -c 'bundle exec rake assets:precompile'
174 path: /usr/local/bin/discourse
178 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/discourse "$@")
181 path: /usr/local/bin/rails
185 # If they requested a console, load pry instead
186 if [ "$*" == "c" -o "$*" == "console" ]
188 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec pry -r ./config/environment)
190 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/rails "$@")
194 path: /usr/local/bin/rake
198 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec bin/rake "$@")
201 path: /usr/local/bin/rbtrace
205 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec rbtrace "$@")
208 path: /usr/local/bin/stackprof
212 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec stackprof "$@")
215 path: /etc/update-motd.d/10-web
220 echo Use: rails, rake or discourse to execute commands in production
224 path: /etc/logrotate.d/rails
226 /shared/log/rails/*.log
240 path: /etc/logrotate.d/nginx
242 /var/log/nginx/*.log {
248 create 0644 www-data www-data
255 # move state out of the container this fancy is done to support rapid rebuilds of containers,
256 # we store anacron and logrotate state outside the container to ensure its maintained across builds
257 # later move this snipped into an intialization script
258 # we also ensure all the symlinks we need to /shared are in place in the correct structure
259 # this allows us to bootstrap on one machine and then run on another
261 path: /etc/runit/1.d/00-ensure-links
265 if [[ ! -L /var/lib/logrotate ]]; then
266 rm -fr /var/lib/logrotate
267 mkdir -p /shared/state/logrotate
268 ln -s /shared/state/logrotate /var/lib/logrotate
270 if [[ ! -L /var/spool/anacron ]]; then
271 rm -fr /var/spool/anacron
272 mkdir -p /shared/state/anacron-spool
273 ln -s /shared/state/anacron-spool /var/spool/anacron
275 if [[ ! -d /shared/log/rails ]]; then
276 mkdir -p /shared/log/rails
277 chown -R discourse:www-data /shared/log/rails
279 if [[ ! -d /shared/uploads ]]; then
280 mkdir -p /shared/uploads
281 chown -R discourse:www-data /shared/uploads
283 if [[ ! -d /shared/backups ]]; then
284 mkdir -p /shared/backups
285 chown -R discourse:www-data /shared/backups
288 rm -rf /shared/tmp/{backups,restores}
289 mkdir -p /shared/tmp/{backups,restores}
290 chown -R discourse:www-data /shared/tmp/{backups,restores}
292 # change login directory to Discourse home
294 path: /root/.bash_profile