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