Commit | Line | Data |
---|---|---|
9fb5f2d3 | 1 | env: |
9fb5f2d3 | 2 | # You can have redis on a different box |
9fb5f2d3 SS |
3 | RAILS_ENV: 'production' |
4 | UNICORN_WORKERS: 3 | |
42b06eef | 5 | UNICORN_SIDEKIQS: 1 |
9fb5f2d3 SS |
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 | ||
9be8f5b9 | 11 | DISCOURSE_DB_SOCKET: /var/run/postgresql |
c148f4c9 SS |
12 | DISCOURSE_DB_HOST: |
13 | DISCOURSE_DB_PORT: | |
38000fc6 SS |
14 | |
15 | ||
9fb5f2d3 SS |
16 | params: |
17 | # SSH key is required for remote access into the container | |
b56a2bd7 | 18 | version: tests-passed |
9fb5f2d3 SS |
19 | |
20 | home: /var/www/discourse | |
44c59d37 | 21 | upload_size: 10m |
9fb5f2d3 | 22 | |
9fb5f2d3 | 23 | run: |
b7f9f4c7 | 24 | - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_SMTP_ADDRESS"] == "smtp.example.com"; puts "Aborting! Mail is not configured!"; exit 1; end' |
28aa70d0 | 25 | - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_HOSTNAME"] == "discourse.example.com"; puts "Aborting! Domain is not configured!"; exit 1; end' |
87f8d0b3 | 26 | - file: |
089518ef | 27 | path: /etc/runit/1.d/copy-env |
87f8d0b3 SS |
28 | chmod: "+x" |
29 | contents: | | |
30 | #!/bin/bash | |
c4498636 | 31 | env > ~/boot_env |
87f8d0b3 | 32 | conf=/var/www/discourse/config/discourse.conf |
87f8d0b3 | 33 | |
1cb802ad | 34 | # find DISCOURSE_ env vars, strip the leader, lowercase the key |
797864e6 | 35 | /usr/local/bin/ruby -e 'ENV.each{|k,v| puts "#{$1.downcase} = #{v}" if k =~ /^DISCOURSE_(.*)/}' > $conf |
1cb802ad | 36 | |
b3d252a0 | 37 | - file: |
4316c5e5 S |
38 | path: /etc/runit/1.d/ensure-web-nginx-read |
39 | chmod: "+x" | |
40 | contents: | | |
b3d252a0 S |
41 | #!/bin/bash |
42 | chgrp -R www-data /var/log/nginx | |
43 | chgrp www-data /var/log/nginx | |
4316c5e5 | 44 | |
9fb5f2d3 SS |
45 | - file: |
46 | path: /etc/service/unicorn/run | |
47 | chmod: "+x" | |
48 | contents: | | |
49 | #!/bin/bash | |
50 | exec 2>&1 | |
9fb5f2d3 SS |
51 | # redis |
52 | # postgres | |
53 | cd $home | |
6d00b2fa | 54 | chown -R discourse:www-data /shared/log/rails |
56e5e6c2 | 55 | 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 |
9fb5f2d3 | 56 | |
9fb5f2d3 SS |
57 | - file: |
58 | path: /etc/service/nginx/run | |
59 | chmod: "+x" | |
60 | contents: | | |
61 | #!/bin/sh | |
62 | exec 2>&1 | |
4695d446 | 63 | mkdir -p /var/log/nginx |
9fb5f2d3 SS |
64 | exec /usr/sbin/nginx |
65 | ||
074f2b6a S |
66 | - file: |
67 | path: /etc/runit/3.d/01-nginx | |
68 | chmod: "+x" | |
69 | contents: | | |
70 | #!/bin/bash | |
71 | sv stop nginx | |
72 | ||
73 | - file: | |
74 | path: /etc/runit/3.d/02-unicorn | |
75 | chmod: "+x" | |
76 | contents: | | |
77 | #!/bin/bash | |
78 | sv stop unicorn | |
79 | ||
9fb5f2d3 SS |
80 | - exec: |
81 | cd: $home | |
82 | hook: code | |
83 | cmd: | |
84 | - git reset --hard | |
85 | - git clean -f | |
36c6b609 | 86 | - git remote set-branches --add origin master |
d9c1b419 S |
87 | - git pull |
88 | - git fetch origin $version | |
9fb5f2d3 | 89 | - git checkout $version |
9fb5f2d3 SS |
90 | - mkdir -p tmp/pids |
91 | - mkdir -p tmp/sockets | |
b150cad1 | 92 | - touch tmp/.gitkeep |
e56a65f6 | 93 | - mkdir -p /shared/log/rails |
b6227eb0 | 94 | - bash -c "touch -a /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log" |
e56a65f6 MB |
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 | |
c4498636 | 99 | |
9fb5f2d3 SS |
100 | - exec: |
101 | cmd: | |
102 | - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf" | |
103 | - "rm /etc/nginx/sites-enabled/default" | |
69c891fd | 104 | - "mkdir -p /var/nginx/cache" |
9fb5f2d3 SS |
105 | |
106 | - replace: | |
107 | filename: /etc/nginx/nginx.conf | |
108 | from: pid /run/nginx.pid; | |
109 | to: daemon off; | |
110 | ||
111 | - replace: | |
112 | filename: "/etc/nginx/conf.d/discourse.conf" | |
113 | from: /upstream[^\}]+\}/m | |
114 | to: "upstream discourse { | |
115 | server 127.0.0.1:3000; | |
116 | }" | |
117 | ||
118 | - replace: | |
119 | filename: "/etc/nginx/conf.d/discourse.conf" | |
120 | from: /server_name.+$/ | |
121 | to: server_name _ ; | |
122 | ||
6e23c775 | 123 | - replace: |
124 | filename: "/etc/nginx/conf.d/discourse.conf" | |
125 | from: /client_max_body_size.+$/ | |
126 | to: client_max_body_size $upload_size ; | |
127 | ||
9e8e16a8 SS |
128 | - exec: |
129 | cmd: echo "done configuring web" | |
130 | hook: web_config | |
131 | ||
9fb5f2d3 SS |
132 | - exec: |
133 | cd: $home | |
62418f96 | 134 | hook: web |
9fb5f2d3 | 135 | cmd: |
e64b0a0b S |
136 | # ensure we are on latest bundler |
137 | - gem update bundler | |
9fb5f2d3 | 138 | - chown -R discourse $home |
70710fa0 EG |
139 | |
140 | - exec: | |
141 | cd: $home | |
142 | hook: bundle_exec | |
143 | cmd: | |
e56a65f6 MB |
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' | |
9fb5f2d3 | 147 | |
553a4fc9 S |
148 | - file: |
149 | path: /usr/local/bin/discourse | |
150 | chmod: +x | |
151 | contents: | | |
152 | #!/bin/bash | |
8a02b91e | 153 | (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/discourse "$@") |
553a4fc9 S |
154 | |
155 | - file: | |
156 | path: /usr/local/bin/rails | |
157 | chmod: +x | |
158 | contents: | | |
159 | #!/bin/bash | |
cbfcacda | 160 | # If they requested a console, load pry instead |
d16335a6 | 161 | if [ "$*" == "c" -o "$*" == "console" ] |
cbfcacda | 162 | then |
8a02b91e | 163 | (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec pry -r ./config/environment) |
cbfcacda | 164 | else |
8a02b91e | 165 | (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/rails "$@") |
cbfcacda | 166 | fi |
553a4fc9 S |
167 | |
168 | - file: | |
169 | path: /usr/local/bin/rake | |
170 | chmod: +x | |
171 | contents: | | |
172 | #!/bin/bash | |
8a02b91e | 173 | (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec bin/rake "$@") |
553a4fc9 S |
174 | |
175 | - file: | |
176 | path: /etc/update-motd.d/10-web | |
177 | chmod: +x | |
178 | contents: | | |
179 | #!/bin/bash | |
180 | echo | |
181 | echo Use: rails, rake or discourse to execute commands in production | |
182 | echo | |
183 | ||
be82e068 S |
184 | - file: |
185 | path: /etc/logrotate.d/rails | |
186 | contents: | | |
187 | /shared/log/rails/*.log | |
188 | { | |
189 | rotate 14 | |
190 | dateext | |
191 | daily | |
192 | missingok | |
193 | notifempty | |
194 | delaycompress | |
195 | compress | |
196 | postrotate | |
197 | sv 1 unicorn | |
198 | endscript | |
199 | } | |
55737024 | 200 | |
5d256035 S |
201 | - file: |
202 | path: /etc/logrotate.d/nginx | |
203 | contents: | | |
204 | /var/log/nginx/*.log { | |
205 | daily | |
206 | missingok | |
207 | rotate 14 | |
208 | compress | |
209 | delaycompress | |
210 | notifempty | |
b3d252a0 | 211 | create 0640 www-data www-data |
5d256035 S |
212 | sharedscripts |
213 | postrotate | |
214 | sv 1 nginx | |
215 | endscript | |
216 | } | |
55737024 | 217 | |
25a7de18 S |
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 | |
be55cb66 S |
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 | |
223 | - file: | |
224 | path: /etc/runit/1.d/00-ensure-links | |
225 | chmod: +x | |
226 | contents: | | |
227 | #!/bin/bash | |
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 | |
232 | fi | |
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 | |
237 | fi | |
238 | if [[ ! -d /shared/log/rails ]]; then | |
239 | mkdir -p /shared/log/rails | |
240 | chown -R discourse:www-data /shared/log/rails | |
241 | fi | |
242 | if [[ ! -d /shared/uploads ]]; then | |
243 | mkdir -p /shared/uploads | |
244 | chown -R discourse:www-data /shared/uploads | |
245 | fi | |
246 | if [[ ! -d /shared/backups ]]; then | |
247 | mkdir -p /shared/backups | |
248 | chown -R discourse:www-data /shared/backups | |
249 | fi |