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'
26 - exec: chown -R discourse /home/discourse
28 path: /etc/runit/1.d/copy-env
33 conf=/var/www/discourse/config/discourse.conf
35 # find DISCOURSE_ env vars, strip the leader, lowercase the key
36 /usr/local/bin/ruby -e 'ENV.each{|k,v| puts "#{$1.downcase} = #{v}" if k =~ /^DISCOURSE_(.*)/}' > $conf
39 path: /etc/runit/1.d/ensure-web-nginx-read
43 mkdir -p /var/log/nginx
44 chgrp -R www-data /var/log/nginx
45 chgrp www-data /var/log/nginx
48 path: /etc/service/unicorn/run
56 chown -R discourse:www-data /shared/log/rails
57 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
60 path: /etc/service/nginx/run
68 path: /etc/runit/3.d/01-nginx
75 path: /etc/runit/3.d/02-unicorn
87 - git remote set-branches --add origin master
89 - git fetch origin $version
90 - git checkout $version
92 - mkdir -p tmp/sockets
94 - mkdir -p /shared/log/rails
95 - bash -c "touch -a /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log"
96 - bash -c "ln -s /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log $home/log"
97 - bash -c "mkdir -p /shared/{uploads,backups}"
98 - bash -c "ln -s /shared/{uploads,backups} $home/public"
99 - chown -R discourse:www-data /shared/log/rails /shared/uploads /shared/backups
103 - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
104 - "rm /etc/nginx/sites-enabled/default"
105 - "mkdir -p /var/nginx/cache"
108 filename: /etc/nginx/nginx.conf
109 from: pid /run/nginx.pid;
113 filename: "/etc/nginx/conf.d/discourse.conf"
114 from: /upstream[^\}]+\}/m
115 to: "upstream discourse {
116 server 127.0.0.1:3000;
120 filename: "/etc/nginx/conf.d/discourse.conf"
121 from: /server_name.+$/
125 filename: "/etc/nginx/conf.d/discourse.conf"
126 from: /client_max_body_size.+$/
127 to: client_max_body_size $upload_size ;
130 cmd: echo "done configuring web"
137 # ensure we are on latest bundler
139 - chown -R discourse $home
145 - su discourse -c 'bundle install --deployment --verbose --without test --without development'
146 - su discourse -c 'bundle exec rake db:migrate'
147 - su discourse -c 'bundle exec rake assets:precompile'
150 path: /usr/local/bin/discourse
154 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/discourse "$@")
157 path: /usr/local/bin/rails
161 # If they requested a console, load pry instead
162 if [ "$*" == "c" -o "$*" == "console" ]
164 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec pry -r ./config/environment)
166 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/rails "$@")
170 path: /usr/local/bin/rake
174 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec bin/rake "$@")
177 path: /etc/update-motd.d/10-web
182 echo Use: rails, rake or discourse to execute commands in production
186 path: /etc/logrotate.d/rails
188 /shared/log/rails/*.log
203 path: /etc/logrotate.d/nginx
205 /var/log/nginx/*.log {
212 create 0640 www-data www-data
219 # move state out of the container this fancy is done to support rapid rebuilds of containers,
220 # we store anacron and logrotate state outside the container to ensure its maintained across builds
221 # later move this snipped into an intialization script
222 # we also ensure all the symlinks we need to /shared are in place in the correct structure
223 # this allows us to bootstrap on one machine and then run on another
225 path: /etc/runit/1.d/00-ensure-links
229 if [[ ! -L /var/lib/logrotate ]]; then
230 rm -fr /var/lib/logrotate
231 mkdir -p /shared/state/logrotate
232 ln -s /shared/state/logrotate /var/lib/logrotate
234 if [[ ! -L /var/spool/anacron ]]; then
235 rm -fr /var/spool/anacron
236 mkdir -p /shared/state/anacron-spool
237 ln -s /shared/state/anacron-spool /var/spool/anacron
239 if [[ ! -d /shared/log/rails ]]; then
240 mkdir -p /shared/log/rails
241 chown -R discourse:www-data /shared/log/rails
243 if [[ ! -d /shared/uploads ]]; then
244 mkdir -p /shared/uploads
245 chown -R discourse:www-data /shared/uploads
247 if [[ ! -d /shared/backups ]]; then
248 mkdir -p /shared/backups
249 chown -R discourse:www-data /shared/backups
252 # change login directory to Discourse home
254 path: /root/.bash_profile