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