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_HEAP_MIN_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 - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_SMTP_ADDRESS"] == "smtp.example.com"; puts "Aborting! Mail is not configured!"; exit 1; end'
25 - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_HOSTNAME"] == "discourse.example.com"; puts "Aborting! Domain is not configured!"; exit 1; end'
27 path: /etc/runit/1.d/copy-env
32 conf=/var/www/discourse/config/discourse.conf
34 # find DISCOURSE_ env vars, strip the leader, lowercase the key
35 /usr/local/bin/ruby -e 'ENV.each{|k,v| puts "#{$1.downcase} = #{v}" if k =~ /^DISCOURSE_(.*)/}' > $conf
38 path: /etc/runit/1.d/ensure-web-nginx-read
42 mkdir -p /var/log/nginx
43 chgrp -R www-data /var/log/nginx
44 chgrp www-data /var/log/nginx
47 path: /etc/service/unicorn/run
55 chown -R discourse:www-data /shared/log/rails
56 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
59 path: /etc/service/nginx/run
67 path: /etc/runit/3.d/01-nginx
74 path: /etc/runit/3.d/02-unicorn
86 - git remote set-branches --add origin master
88 - git fetch origin $version
89 - git checkout $version
91 - mkdir -p tmp/sockets
93 - mkdir -p /shared/log/rails
94 - bash -c "touch -a /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log"
95 - bash -c "ln -s /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log $home/log"
96 - bash -c "mkdir -p /shared/{uploads,backups}"
97 - bash -c "ln -s /shared/{uploads,backups} $home/public"
98 - chown -R discourse:www-data /shared/log/rails /shared/uploads /shared/backups
102 - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
103 - "rm /etc/nginx/sites-enabled/default"
104 - "mkdir -p /var/nginx/cache"
107 filename: /etc/nginx/nginx.conf
108 from: pid /run/nginx.pid;
112 filename: "/etc/nginx/conf.d/discourse.conf"
113 from: /upstream[^\}]+\}/m
114 to: "upstream discourse {
115 server 127.0.0.1:3000;
119 filename: "/etc/nginx/conf.d/discourse.conf"
120 from: /server_name.+$/
124 filename: "/etc/nginx/conf.d/discourse.conf"
125 from: /client_max_body_size.+$/
126 to: client_max_body_size $upload_size ;
129 cmd: echo "done configuring web"
136 # ensure we are on latest bundler
138 - chown -R discourse $home
144 - su discourse -c 'bundle install --deployment --verbose --without test --without development'
145 - su discourse -c 'bundle exec rake db:migrate'
146 - su discourse -c 'bundle exec rake assets:precompile'
149 path: /usr/local/bin/discourse
153 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/discourse "$@")
156 path: /usr/local/bin/rails
160 # If they requested a console, load pry instead
161 if [ "$*" == "c" -o "$*" == "console" ]
163 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec pry -r ./config/environment)
165 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/rails "$@")
169 path: /usr/local/bin/rake
173 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec bin/rake "$@")
176 path: /etc/update-motd.d/10-web
181 echo Use: rails, rake or discourse to execute commands in production
185 path: /etc/logrotate.d/rails
187 /shared/log/rails/*.log
202 path: /etc/logrotate.d/nginx
204 /var/log/nginx/*.log {
211 create 0640 www-data www-data
218 # move state out of the container this fancy is done to support rapid rebuilds of containers,
219 # we store anacron and logrotate state outside the container to ensure its maintained across builds
220 # later move this snipped into an intialization script
221 # we also ensure all the symlinks we need to /shared are in place in the correct structure
222 # this allows us to bootstrap on one machine and then run on another
224 path: /etc/runit/1.d/00-ensure-links
228 if [[ ! -L /var/lib/logrotate ]]; then
229 rm -fr /var/lib/logrotate
230 mkdir -p /shared/state/logrotate
231 ln -s /shared/state/logrotate /var/lib/logrotate
233 if [[ ! -L /var/spool/anacron ]]; then
234 rm -fr /var/spool/anacron
235 mkdir -p /shared/state/anacron-spool
236 ln -s /shared/state/anacron-spool /var/spool/anacron
238 if [[ ! -d /shared/log/rails ]]; then
239 mkdir -p /shared/log/rails
240 chown -R discourse:www-data /shared/log/rails
242 if [[ ! -d /shared/uploads ]]; then
243 mkdir -p /shared/uploads
244 chown -R discourse:www-data /shared/uploads
246 if [[ ! -d /shared/backups ]]; then
247 mkdir -p /shared/backups
248 chown -R discourse:www-data /shared/backups
251 # change login directory to Discourse home
253 path: /root/.bash_profile