| 1 | env: |
| 2 | # You can have redis on a different box |
| 3 | RAILS_ENV: 'production' |
| 4 | UNICORN_WORKERS: 3 |
| 5 | UNICORN_SIDEKIQS: 1 |
| 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 |
| 10 | |
| 11 | DISCOURSE_DB_SOCKET: /var/run/postgresql |
| 12 | DISCOURSE_DB_HOST: |
| 13 | DISCOURSE_DB_PORT: |
| 14 | |
| 15 | |
| 16 | params: |
| 17 | # SSH key is required for remote access into the container |
| 18 | version: tests-passed |
| 19 | |
| 20 | home: /var/www/discourse |
| 21 | upload_size: 10m |
| 22 | |
| 23 | run: |
| 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 | - file: |
| 26 | path: /etc/runit/1.d/copy-env |
| 27 | chmod: "+x" |
| 28 | contents: | |
| 29 | #!/bin/bash |
| 30 | env > ~/boot_env |
| 31 | conf=/var/www/discourse/config/discourse.conf |
| 32 | |
| 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 |
| 35 | |
| 36 | - file: |
| 37 | path: /etc/runit/1.d/ensure-web-nginx-read |
| 38 | chmod: "+x" |
| 39 | contents: | |
| 40 | #!/bin/bash |
| 41 | chgrp -R www-data /var/log/nginx |
| 42 | chgrp www-data /var/log/nginx |
| 43 | |
| 44 | - file: |
| 45 | path: /etc/service/unicorn/run |
| 46 | chmod: "+x" |
| 47 | contents: | |
| 48 | #!/bin/bash |
| 49 | exec 2>&1 |
| 50 | # redis |
| 51 | # postgres |
| 52 | cd $home |
| 53 | chown -R discourse:www-data /shared/log/rails |
| 54 | 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 |
| 55 | |
| 56 | - file: |
| 57 | path: /etc/service/nginx/run |
| 58 | chmod: "+x" |
| 59 | contents: | |
| 60 | #!/bin/sh |
| 61 | exec 2>&1 |
| 62 | mkdir -p /var/log/nginx |
| 63 | exec /usr/sbin/nginx |
| 64 | |
| 65 | - file: |
| 66 | path: /etc/runit/3.d/01-nginx |
| 67 | chmod: "+x" |
| 68 | contents: | |
| 69 | #!/bin/bash |
| 70 | sv stop nginx |
| 71 | |
| 72 | - file: |
| 73 | path: /etc/runit/3.d/02-unicorn |
| 74 | chmod: "+x" |
| 75 | contents: | |
| 76 | #!/bin/bash |
| 77 | sv stop unicorn |
| 78 | |
| 79 | - exec: |
| 80 | cd: $home |
| 81 | hook: code |
| 82 | cmd: |
| 83 | - git reset --hard |
| 84 | - git clean -f |
| 85 | - git remote set-branches --add origin master |
| 86 | - git pull |
| 87 | - git fetch origin $version |
| 88 | - git checkout $version |
| 89 | - mkdir -p tmp/pids |
| 90 | - mkdir -p tmp/sockets |
| 91 | - touch tmp/.gitkeep |
| 92 | - mkdir -p /shared/log/rails |
| 93 | - bash -c "touch -a /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log" |
| 94 | - bash -c "ln -s /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log $home/log" |
| 95 | - bash -c "mkdir -p /shared/{uploads,backups}" |
| 96 | - bash -c "ln -s /shared/{uploads,backups} $home/public" |
| 97 | - chown -R discourse:www-data /shared/log/rails /shared/uploads /shared/backups |
| 98 | |
| 99 | - exec: |
| 100 | cmd: |
| 101 | - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf" |
| 102 | - "rm /etc/nginx/sites-enabled/default" |
| 103 | - "mkdir -p /var/nginx/cache" |
| 104 | |
| 105 | - replace: |
| 106 | filename: /etc/nginx/nginx.conf |
| 107 | from: pid /run/nginx.pid; |
| 108 | to: daemon off; |
| 109 | |
| 110 | - replace: |
| 111 | filename: "/etc/nginx/conf.d/discourse.conf" |
| 112 | from: /upstream[^\}]+\}/m |
| 113 | to: "upstream discourse { |
| 114 | server 127.0.0.1:3000; |
| 115 | }" |
| 116 | |
| 117 | - replace: |
| 118 | filename: "/etc/nginx/conf.d/discourse.conf" |
| 119 | from: /server_name.+$/ |
| 120 | to: server_name _ ; |
| 121 | |
| 122 | - replace: |
| 123 | filename: "/etc/nginx/conf.d/discourse.conf" |
| 124 | from: /client_max_body_size.+$/ |
| 125 | to: client_max_body_size $upload_size ; |
| 126 | |
| 127 | - exec: |
| 128 | cmd: echo "done configuring web" |
| 129 | hook: web_config |
| 130 | |
| 131 | - exec: |
| 132 | cd: $home |
| 133 | hook: web |
| 134 | cmd: |
| 135 | # ensure we are on latest bundler |
| 136 | - gem update bundler |
| 137 | - chown -R discourse $home |
| 138 | |
| 139 | - exec: |
| 140 | cd: $home |
| 141 | hook: bundle_exec |
| 142 | cmd: |
| 143 | - su discourse -c 'bundle install --deployment --verbose --without test --without development' |
| 144 | - su discourse -c 'bundle exec rake db:migrate' |
| 145 | - su discourse -c 'bundle exec rake assets:precompile' |
| 146 | |
| 147 | - file: |
| 148 | path: /usr/local/bin/discourse |
| 149 | chmod: +x |
| 150 | contents: | |
| 151 | #!/bin/bash |
| 152 | (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/discourse "$@") |
| 153 | |
| 154 | - file: |
| 155 | path: /usr/local/bin/rails |
| 156 | chmod: +x |
| 157 | contents: | |
| 158 | #!/bin/bash |
| 159 | # If they requested a console, load pry instead |
| 160 | if [ "$*" == "c" -o "$*" == "console" ] |
| 161 | then |
| 162 | (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec pry -r ./config/environment) |
| 163 | else |
| 164 | (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/rails "$@") |
| 165 | fi |
| 166 | |
| 167 | - file: |
| 168 | path: /usr/local/bin/rake |
| 169 | chmod: +x |
| 170 | contents: | |
| 171 | #!/bin/bash |
| 172 | (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec bin/rake "$@") |
| 173 | |
| 174 | - file: |
| 175 | path: /etc/update-motd.d/10-web |
| 176 | chmod: +x |
| 177 | contents: | |
| 178 | #!/bin/bash |
| 179 | echo |
| 180 | echo Use: rails, rake or discourse to execute commands in production |
| 181 | echo |
| 182 | |
| 183 | - file: |
| 184 | path: /etc/logrotate.d/rails |
| 185 | contents: | |
| 186 | /shared/log/rails/*.log |
| 187 | { |
| 188 | rotate 14 |
| 189 | dateext |
| 190 | daily |
| 191 | missingok |
| 192 | notifempty |
| 193 | delaycompress |
| 194 | compress |
| 195 | postrotate |
| 196 | sv 1 unicorn |
| 197 | endscript |
| 198 | } |
| 199 | |
| 200 | - file: |
| 201 | path: /etc/logrotate.d/nginx |
| 202 | contents: | |
| 203 | /var/log/nginx/*.log { |
| 204 | daily |
| 205 | missingok |
| 206 | rotate 14 |
| 207 | compress |
| 208 | delaycompress |
| 209 | notifempty |
| 210 | create 0640 www-data www-data |
| 211 | sharedscripts |
| 212 | postrotate |
| 213 | sv 1 nginx |
| 214 | endscript |
| 215 | } |
| 216 | |
| 217 | # move state out of the container this fancy is done to support rapid rebuilds of containers, |
| 218 | # we store anacron and logrotate state outside the container to ensure its maintained across builds |
| 219 | # later move this snipped into an intialization script |
| 220 | # we also ensure all the symlinks we need to /shared are in place in the correct structure |
| 221 | # this allows us to bootstrap on one machine and then run on another |
| 222 | - file: |
| 223 | path: /etc/runit/1.d/00-ensure-links |
| 224 | chmod: +x |
| 225 | contents: | |
| 226 | #!/bin/bash |
| 227 | if [[ ! -L /var/lib/logrotate ]]; then |
| 228 | rm -fr /var/lib/logrotate |
| 229 | mkdir -p /shared/state/logrotate |
| 230 | ln -s /shared/state/logrotate /var/lib/logrotate |
| 231 | fi |
| 232 | if [[ ! -L /var/spool/anacron ]]; then |
| 233 | rm -fr /var/spool/anacron |
| 234 | mkdir -p /shared/state/anacron-spool |
| 235 | ln -s /shared/state/anacron-spool /var/spool/anacron |
| 236 | fi |
| 237 | if [[ ! -d /shared/log/rails ]]; then |
| 238 | mkdir -p /shared/log/rails |
| 239 | chown -R discourse:www-data /shared/log/rails |
| 240 | fi |
| 241 | if [[ ! -d /shared/uploads ]]; then |
| 242 | mkdir -p /shared/uploads |
| 243 | chown -R discourse:www-data /shared/uploads |
| 244 | fi |
| 245 | if [[ ! -d /shared/backups ]]; then |
| 246 | mkdir -p /shared/backups |
| 247 | chown -R discourse:www-data /shared/backups |
| 248 | fi |