| 1 | env: |
| 2 | # You can have redis on a different box |
| 3 | RAILS_ENV: 'production' |
| 4 | UNICORN_WORKERS: 3 |
| 5 | # slightly less aggressive than "recommendation" but works fine with oobgc |
| 6 | RUBY_GC_MALLOC_LIMIT: 40000000 |
| 7 | # this ensures we have enough heap space to handle a big pile of small reqs |
| 8 | RUBY_HEAP_MIN_SLOTS: 800000 |
| 9 | |
| 10 | DISCOURSE_DB_SOCKET: /var/run/postgresql |
| 11 | DISCOURSE_DB_HOST: |
| 12 | DISCOURSE_DB_PORT: |
| 13 | |
| 14 | |
| 15 | params: |
| 16 | # SSH key is required for remote access into the container |
| 17 | version: HEAD |
| 18 | |
| 19 | home: /var/www/discourse |
| 20 | |
| 21 | run: |
| 22 | - file: |
| 23 | path: /etc/service/copy_env/run |
| 24 | chmod: "+x" |
| 25 | contents: | |
| 26 | #!/bin/bash |
| 27 | env > ~/boot_env |
| 28 | conf=/var/www/discourse/config/discourse.conf |
| 29 | sudo -u discourse echo > $conf |
| 30 | |
| 31 | for x in `env | /usr/bin/awk -F= '{if($1 ~ /DISCOURSE_/) print $1}'` |
| 32 | do |
| 33 | c=${x,,} |
| 34 | c=${c:10} |
| 35 | echo "$c"=${!x} >> $conf |
| 36 | done |
| 37 | # I dunno there may be a cleaner way to handle this |
| 38 | exec sleep 2147483647 |
| 39 | |
| 40 | - file: |
| 41 | path: /etc/service/unicorn/run |
| 42 | chmod: "+x" |
| 43 | contents: | |
| 44 | #!/bin/bash |
| 45 | exec 2>&1 |
| 46 | # redis |
| 47 | # postgres |
| 48 | sv start copy_env || exit 1 |
| 49 | cd $home |
| 50 | exec sudo -E -u discourse LD_PRELOAD=/usr/lib/libjemalloc.so.1 bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb |
| 51 | |
| 52 | - file: |
| 53 | path: /etc/service/sidekiq/run |
| 54 | chmod: "+x" |
| 55 | contents: | |
| 56 | #!/bin/bash |
| 57 | exec 2>&1 |
| 58 | # redis |
| 59 | # postgres |
| 60 | sv start copy_env || exit 1 |
| 61 | cd $home |
| 62 | exec sudo -E -u discourse LD_PRELOAD=/usr/lib/libjemalloc.so.1 bundle exec sidekiq |
| 63 | |
| 64 | - file: |
| 65 | path: /etc/service/nginx/run |
| 66 | chmod: "+x" |
| 67 | contents: | |
| 68 | #!/bin/sh |
| 69 | exec 2>&1 |
| 70 | exec /usr/sbin/nginx |
| 71 | |
| 72 | - exec: |
| 73 | cd: $home |
| 74 | hook: code |
| 75 | cmd: |
| 76 | - git reset --hard |
| 77 | - git clean -f |
| 78 | - git pull |
| 79 | - git checkout $version |
| 80 | - mkdir -p tmp/pids |
| 81 | - mkdir -p tmp/sockets |
| 82 | - mkdir -p /shared/log/rails |
| 83 | - mkdir -p /shared/uploads |
| 84 | - mkdir -p /shared/backups |
| 85 | - touch tmp/.gitkeep |
| 86 | - rm -r log |
| 87 | - ln -s /shared/log/rails $home/log |
| 88 | - ln -s /shared/uploads $home/public/uploads |
| 89 | - ln -s /shared/backups $home/public/backups |
| 90 | - chown -R discourse:www-data /shared/log/rails |
| 91 | - chown -R discourse:www-data /shared/uploads |
| 92 | - chown -R discourse:www-data /shared/backups |
| 93 | |
| 94 | - exec: |
| 95 | cmd: |
| 96 | - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf" |
| 97 | - "rm /etc/nginx/sites-enabled/default" |
| 98 | |
| 99 | - replace: |
| 100 | filename: /etc/nginx/nginx.conf |
| 101 | from: pid /run/nginx.pid; |
| 102 | to: daemon off; |
| 103 | |
| 104 | - replace: |
| 105 | filename: "/etc/nginx/conf.d/discourse.conf" |
| 106 | from: /upstream[^\}]+\}/m |
| 107 | to: "upstream discourse { |
| 108 | server 127.0.0.1:3000; |
| 109 | }" |
| 110 | |
| 111 | - replace: |
| 112 | filename: "/etc/nginx/conf.d/discourse.conf" |
| 113 | from: /server_name.+$/ |
| 114 | to: server_name _ ; |
| 115 | |
| 116 | - exec: |
| 117 | cmd: echo "done configuring web" |
| 118 | hook: web_config |
| 119 | |
| 120 | - exec: |
| 121 | cd: $home |
| 122 | hook: web |
| 123 | cmd: |
| 124 | # ensure we are on latest bundler |
| 125 | - gem update bundler |
| 126 | - mkdir -p /shared/vendor_bundle |
| 127 | - cp -fr /shared/vendor_bundle/* vendor/bundle || echo "can not copy" |
| 128 | - chown -R discourse $home |
| 129 | - sudo -E -u discourse bundle install --deployment --verbose --without test --without development |
| 130 | - cp -fr vendor/bundle/* /shared/vendor_bundle |
| 131 | - sudo -E -u discourse bundle exec rake db:migrate |
| 132 | - sudo -E -u discourse bundle exec rake assets:precompile |
| 133 | |
| 134 | - file: |
| 135 | path: /usr/local/bin/discourse |
| 136 | chmod: +x |
| 137 | contents: | |
| 138 | #!/bin/bash |
| 139 | (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec script/discourse "$@") |
| 140 | |
| 141 | - file: |
| 142 | path: /usr/local/bin/rails |
| 143 | chmod: +x |
| 144 | contents: | |
| 145 | #!/bin/bash |
| 146 | (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec script/rails "$@") |
| 147 | |
| 148 | - file: |
| 149 | path: /usr/local/bin/rake |
| 150 | chmod: +x |
| 151 | contents: | |
| 152 | #!/bin/bash |
| 153 | (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec bin/rake "$@") |
| 154 | |
| 155 | - file: |
| 156 | path: /etc/update-motd.d/10-web |
| 157 | chmod: +x |
| 158 | contents: | |
| 159 | #!/bin/bash |
| 160 | echo |
| 161 | echo Use: rails, rake or discourse to execute commands in production |
| 162 | echo |
| 163 | |