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'
26 path: /etc/runit/1.d/copy-env
31 conf=/var/www/discourse/config/discourse.conf
33 # find DISCOURSE_ env vars, strip the leader, lowercase the key
34 /usr/local/bin/ruby -e 'ENV.each{|k,v| puts "#{$1.downcase} = #{v}" if k =~ /^DISCOURSE_(.*)/}' > $conf
37 path: /etc/service/unicorn/run
45 chown -R discourse:www-data /shared/log/rails
46 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
49 path: /etc/service/nginx/run
54 mkdir -p /var/log/nginx
58 path: /etc/runit/3.d/01-nginx
65 path: /etc/runit/3.d/02-unicorn
77 - git remote set-branches --add origin master
79 - git fetch origin $version
80 - git checkout $version
82 - mkdir -p tmp/sockets
84 - mkdir -p /shared/log/rails
85 - bash -c "touch -a /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log"
86 - bash -c "ln -s /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log $home/log"
87 - bash -c "mkdir -p /shared/{uploads,backups}"
88 - bash -c "ln -s /shared/{uploads,backups} $home/public"
89 - chown -R discourse:www-data /shared/log/rails /shared/uploads /shared/backups
93 - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
94 - "rm /etc/nginx/sites-enabled/default"
95 - "mkdir -p /var/nginx/cache"
98 filename: /etc/nginx/nginx.conf
99 from: pid /run/nginx.pid;
103 filename: "/etc/nginx/conf.d/discourse.conf"
104 from: /upstream[^\}]+\}/m
105 to: "upstream discourse {
106 server 127.0.0.1:3000;
110 filename: "/etc/nginx/conf.d/discourse.conf"
111 from: /server_name.+$/
115 filename: "/etc/nginx/conf.d/discourse.conf"
116 from: /client_max_body_size.+$/
117 to: client_max_body_size $upload_size ;
120 cmd: echo "done configuring web"
127 # ensure we are on latest bundler
129 - chown -R discourse $home
135 - su discourse -c 'bundle install --deployment --verbose --without test --without development'
136 - su discourse -c 'bundle exec rake db:migrate'
137 - su discourse -c 'bundle exec rake assets:precompile'
140 path: /usr/local/bin/discourse
144 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/discourse "$@")
147 path: /usr/local/bin/rails
151 # If they requested a console, load pry instead
152 if [ "$@" == "c" -o "$@" == "console" ]
154 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec pry -r ./config/environment)
156 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/rails "$@")
160 path: /usr/local/bin/rake
164 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec bin/rake "$@")
167 path: /etc/update-motd.d/10-web
172 echo Use: rails, rake or discourse to execute commands in production
176 path: /etc/logrotate.d/rails
178 /shared/log/rails/*.log
193 filename: "/etc/logrotate.d/nginx"
198 filename: "/etc/logrotate.d/nginx"
202 # move state out of the container this fancy is done to support rapid rebuilds of containers,
203 # we store anacron and logrotate state outside the container to ensure its maintained across builds
204 # later move this snipped into an intialization script
205 # we also ensure all the symlinks we need to /shared are in place in the correct structure
206 # this allows us to bootstrap on one machine and then run on another
208 path: /etc/runit/1.d/00-ensure-links
212 if [[ ! -L /var/lib/logrotate ]]; then
213 rm -fr /var/lib/logrotate
214 mkdir -p /shared/state/logrotate
215 ln -s /shared/state/logrotate /var/lib/logrotate
217 if [[ ! -L /var/spool/anacron ]]; then
218 rm -fr /var/spool/anacron
219 mkdir -p /shared/state/anacron-spool
220 ln -s /shared/state/anacron-spool /var/spool/anacron
222 if [[ ! -d /shared/log/rails ]]; then
223 mkdir -p /shared/log/rails
224 chown -R discourse:www-data /shared/log/rails
226 if [[ ! -d /shared/uploads ]]; then
227 mkdir -p /shared/uploads
228 chown -R discourse:www-data /shared/uploads
230 if [[ ! -d /shared/backups ]]; then
231 mkdir -p /shared/backups
232 chown -R discourse:www-data /shared/backups