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 |
5819e899 S |
6 | # this gives us very good cache coverage, 96 -> 99 |
7 | # in practice it is 1-2% perf improvement | |
54e43936 | 8 | RUBY_GLOBAL_METHOD_CACHE_SIZE: 131072 |
5d1848f5 S |
9 | # stop heap doubling in size so aggressively, this conserves memory |
10 | RUBY_GC_HEAP_GROWTH_MAX_SLOTS: 40000 | |
11 | RUBY_GC_HEAP_INIT_SLOTS: 400000 | |
12 | RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR: 1.5 | |
9fb5f2d3 | 13 | |
9be8f5b9 | 14 | DISCOURSE_DB_SOCKET: /var/run/postgresql |
c148f4c9 SS |
15 | DISCOURSE_DB_HOST: |
16 | DISCOURSE_DB_PORT: | |
38000fc6 SS |
17 | |
18 | ||
9fb5f2d3 | 19 | params: |
b56a2bd7 | 20 | version: tests-passed |
9fb5f2d3 SS |
21 | |
22 | home: /var/www/discourse | |
44c59d37 | 23 | upload_size: 10m |
9fb5f2d3 | 24 | |
9fb5f2d3 | 25 | run: |
b1572a5e | 26 | - exec: thpoff echo "thpoff is installed!" |
b7f9f4c7 | 27 | - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_SMTP_ADDRESS"] == "smtp.example.com"; puts "Aborting! Mail is not configured!"; exit 1; end' |
28aa70d0 | 28 | - exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_HOSTNAME"] == "discourse.example.com"; puts "Aborting! Domain is not configured!"; exit 1; end' |
4a3ebfac | 29 | - exec: /usr/local/bin/ruby -e 'if (ENV["DISCOURSE_CDN_URL"] || "")[0..1] == "//"; puts "Aborting! CDN must have a protocol specified. Once fixed you should rebake your posts now to correct all posts."; exit 1; end' |
cc81fc95 | 30 | - exec: chown -R discourse /home/discourse |
573617ea S |
31 | # TODO: move to base image (anacron can not be fired up using rc.d) |
32 | - exec: rm -f /etc/cron.d/anacron | |
33 | - file: | |
34 | path: /etc/cron.d/anacron | |
35 | contents: | | |
36 | SHELL=/bin/sh | |
37 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
38 | ||
39 | 30 7 * * * root /usr/sbin/anacron -s >/dev/null | |
87f8d0b3 | 40 | - file: |
089518ef | 41 | path: /etc/runit/1.d/copy-env |
87f8d0b3 SS |
42 | chmod: "+x" |
43 | contents: | | |
44 | #!/bin/bash | |
c4498636 | 45 | env > ~/boot_env |
87f8d0b3 | 46 | conf=/var/www/discourse/config/discourse.conf |
87f8d0b3 | 47 | |
1cb802ad | 48 | # find DISCOURSE_ env vars, strip the leader, lowercase the key |
087e1101 | 49 | /usr/local/bin/ruby -e 'ENV.each{|k,v| puts "#{$1.downcase} = '\''#{v}'\''" if k =~ /^DISCOURSE_(.*)/}' > $conf |
8fc088ab | 50 | |
9fb5f2d3 SS |
51 | - file: |
52 | path: /etc/service/unicorn/run | |
53 | chmod: "+x" | |
54 | contents: | | |
55 | #!/bin/bash | |
56 | exec 2>&1 | |
9fb5f2d3 SS |
57 | # redis |
58 | # postgres | |
59 | cd $home | |
6d00b2fa | 60 | chown -R discourse:www-data /shared/log/rails |
1404e881 | 61 | LD_PRELOAD=$RUBY_ALLOCATOR HOME=/home/discourse USER=discourse exec thpoff chpst -u discourse:www-data -U discourse:www-data bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb |
9fb5f2d3 | 62 | |
9fb5f2d3 SS |
63 | - file: |
64 | path: /etc/service/nginx/run | |
65 | chmod: "+x" | |
66 | contents: | | |
67 | #!/bin/sh | |
68 | exec 2>&1 | |
69 | exec /usr/sbin/nginx | |
70 | ||
074f2b6a S |
71 | - file: |
72 | path: /etc/runit/3.d/01-nginx | |
73 | chmod: "+x" | |
74 | contents: | | |
75 | #!/bin/bash | |
76 | sv stop nginx | |
77 | ||
78 | - file: | |
79 | path: /etc/runit/3.d/02-unicorn | |
80 | chmod: "+x" | |
81 | contents: | | |
82 | #!/bin/bash | |
83 | sv stop unicorn | |
84 | ||
9fb5f2d3 SS |
85 | - exec: |
86 | cd: $home | |
87 | hook: code | |
88 | cmd: | |
89 | - git reset --hard | |
90 | - git clean -f | |
36c6b609 | 91 | - git remote set-branches --add origin master |
d9c1b419 S |
92 | - git pull |
93 | - git fetch origin $version | |
9fb5f2d3 | 94 | - git checkout $version |
9fb5f2d3 SS |
95 | - mkdir -p tmp/pids |
96 | - mkdir -p tmp/sockets | |
b150cad1 | 97 | - touch tmp/.gitkeep |
e56a65f6 | 98 | - mkdir -p /shared/log/rails |
024ebc40 DT |
99 | - bash -c "touch -a /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr,sidekiq}.log" |
100 | - bash -c "ln -s /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr,sidekiq}.log $home/log" | |
e56a65f6 MB |
101 | - bash -c "mkdir -p /shared/{uploads,backups}" |
102 | - bash -c "ln -s /shared/{uploads,backups} $home/public" | |
f390d78f GS |
103 | - bash -c "mkdir -p /shared/tmp/{backups,restores}" |
104 | - bash -c "ln -s /shared/tmp/{backups,restores} $home/tmp" | |
105 | - chown -R discourse:www-data /shared/log/rails /shared/uploads /shared/backups /shared/tmp | |
d587158a MB |
106 | # scrub broken symlinks from plugins that have been removed |
107 | - find public/plugins/ -maxdepth 1 -xtype l -delete | |
c4498636 | 108 | |
9fb5f2d3 SS |
109 | - exec: |
110 | cmd: | |
111 | - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf" | |
112 | - "rm /etc/nginx/sites-enabled/default" | |
69c891fd | 113 | - "mkdir -p /var/nginx/cache" |
9fb5f2d3 SS |
114 | |
115 | - replace: | |
116 | filename: /etc/nginx/nginx.conf | |
117 | from: pid /run/nginx.pid; | |
118 | to: daemon off; | |
119 | ||
120 | - replace: | |
121 | filename: "/etc/nginx/conf.d/discourse.conf" | |
122 | from: /upstream[^\}]+\}/m | |
123 | to: "upstream discourse { | |
124 | server 127.0.0.1:3000; | |
125 | }" | |
126 | ||
127 | - replace: | |
128 | filename: "/etc/nginx/conf.d/discourse.conf" | |
129 | from: /server_name.+$/ | |
130 | to: server_name _ ; | |
131 | ||
6e23c775 | 132 | - replace: |
133 | filename: "/etc/nginx/conf.d/discourse.conf" | |
134 | from: /client_max_body_size.+$/ | |
135 | to: client_max_body_size $upload_size ; | |
136 | ||
9e8e16a8 SS |
137 | - exec: |
138 | cmd: echo "done configuring web" | |
139 | hook: web_config | |
140 | ||
9fb5f2d3 SS |
141 | - exec: |
142 | cd: $home | |
62418f96 | 143 | hook: web |
9fb5f2d3 | 144 | cmd: |
e64b0a0b S |
145 | # ensure we are on latest bundler |
146 | - gem update bundler | |
aef8682f | 147 | - find $home ! -user discourse -exec chown discourse {} \+ |
70710fa0 EG |
148 | |
149 | - exec: | |
150 | cd: $home | |
151 | hook: bundle_exec | |
152 | cmd: | |
b8866fb9 | 153 | - su discourse -c 'bundle install --deployment --retry 3 --jobs 4 --verbose --without test development' |
8026a344 | 154 | |
0edf993a JW |
155 | # - exec: |
156 | # cd: $home | |
157 | # cmd: | |
158 | # - su discourse -c 'bundle exec rake plugin:pull_compatible_all' | |
159 | # raise_on_fail: false | |
160 | # | |
5716d28f SS |
161 | - exec: |
162 | cd: $home | |
163 | hook: db_migrate | |
164 | cmd: | |
e56a65f6 | 165 | - su discourse -c 'bundle exec rake db:migrate' |
5716d28f SS |
166 | - exec: |
167 | cd: $home | |
168 | hook: assets_precompile | |
169 | cmd: | |
e56a65f6 | 170 | - su discourse -c 'bundle exec rake assets:precompile' |
553a4fc9 S |
171 | - file: |
172 | path: /usr/local/bin/discourse | |
173 | chmod: +x | |
174 | contents: | | |
175 | #!/bin/bash | |
8a02b91e | 176 | (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/discourse "$@") |
553a4fc9 S |
177 | |
178 | - file: | |
179 | path: /usr/local/bin/rails | |
180 | chmod: +x | |
181 | contents: | | |
182 | #!/bin/bash | |
cbfcacda | 183 | # If they requested a console, load pry instead |
d16335a6 | 184 | if [ "$*" == "c" -o "$*" == "console" ] |
cbfcacda | 185 | then |
8a02b91e | 186 | (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec pry -r ./config/environment) |
cbfcacda | 187 | else |
8a02b91e | 188 | (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/rails "$@") |
cbfcacda | 189 | fi |
553a4fc9 S |
190 | |
191 | - file: | |
192 | path: /usr/local/bin/rake | |
193 | chmod: +x | |
194 | contents: | | |
195 | #!/bin/bash | |
8a02b91e | 196 | (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec bin/rake "$@") |
553a4fc9 | 197 | |
e9505520 S |
198 | - file: |
199 | path: /usr/local/bin/rbtrace | |
200 | chmod: +x | |
201 | contents: | | |
202 | #!/bin/bash | |
755fff35 | 203 | (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec rbtrace "$@") |
e9505520 S |
204 | |
205 | - file: | |
206 | path: /usr/local/bin/stackprof | |
207 | chmod: +x | |
208 | contents: | | |
209 | #!/bin/bash | |
755fff35 | 210 | (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec stackprof "$@") |
e9505520 | 211 | |
553a4fc9 S |
212 | - file: |
213 | path: /etc/update-motd.d/10-web | |
214 | chmod: +x | |
215 | contents: | | |
216 | #!/bin/bash | |
217 | echo | |
218 | echo Use: rails, rake or discourse to execute commands in production | |
219 | echo | |
220 | ||
be82e068 S |
221 | - file: |
222 | path: /etc/logrotate.d/rails | |
223 | contents: | | |
224 | /shared/log/rails/*.log | |
225 | { | |
bfe8ac94 | 226 | rotate 7 |
be82e068 S |
227 | dateext |
228 | daily | |
229 | missingok | |
be82e068 S |
230 | delaycompress |
231 | compress | |
232 | postrotate | |
233 | sv 1 unicorn | |
234 | endscript | |
235 | } | |
55737024 | 236 | |
5d256035 S |
237 | - file: |
238 | path: /etc/logrotate.d/nginx | |
239 | contents: | | |
240 | /var/log/nginx/*.log { | |
241 | daily | |
242 | missingok | |
bfe8ac94 | 243 | rotate 7 |
5d256035 S |
244 | compress |
245 | delaycompress | |
8fc088ab | 246 | create 0644 www-data www-data |
5d256035 S |
247 | sharedscripts |
248 | postrotate | |
249 | sv 1 nginx | |
250 | endscript | |
251 | } | |
55737024 | 252 | |
25a7de18 S |
253 | # move state out of the container this fancy is done to support rapid rebuilds of containers, |
254 | # we store anacron and logrotate state outside the container to ensure its maintained across builds | |
255 | # later move this snipped into an intialization script | |
be55cb66 S |
256 | # we also ensure all the symlinks we need to /shared are in place in the correct structure |
257 | # this allows us to bootstrap on one machine and then run on another | |
258 | - file: | |
259 | path: /etc/runit/1.d/00-ensure-links | |
260 | chmod: +x | |
261 | contents: | | |
262 | #!/bin/bash | |
263 | if [[ ! -L /var/lib/logrotate ]]; then | |
264 | rm -fr /var/lib/logrotate | |
265 | mkdir -p /shared/state/logrotate | |
266 | ln -s /shared/state/logrotate /var/lib/logrotate | |
267 | fi | |
268 | if [[ ! -L /var/spool/anacron ]]; then | |
269 | rm -fr /var/spool/anacron | |
270 | mkdir -p /shared/state/anacron-spool | |
271 | ln -s /shared/state/anacron-spool /var/spool/anacron | |
272 | fi | |
273 | if [[ ! -d /shared/log/rails ]]; then | |
274 | mkdir -p /shared/log/rails | |
275 | chown -R discourse:www-data /shared/log/rails | |
276 | fi | |
277 | if [[ ! -d /shared/uploads ]]; then | |
278 | mkdir -p /shared/uploads | |
279 | chown -R discourse:www-data /shared/uploads | |
280 | fi | |
281 | if [[ ! -d /shared/backups ]]; then | |
282 | mkdir -p /shared/backups | |
283 | chown -R discourse:www-data /shared/backups | |
284 | fi | |
0c456e8c | 285 | |
f390d78f GS |
286 | rm -rf /shared/tmp/{backups,restores} |
287 | mkdir -p /shared/tmp/{backups,restores} | |
288 | chown -R discourse:www-data /shared/tmp/{backups,restores} | |
289 | ||
0c456e8c EG |
290 | # change login directory to Discourse home |
291 | - file: | |
292 | path: /root/.bash_profile | |
293 | chmod: 644 | |
294 | contents: | | |
295 | cd $home |