Merge pull request #127 from kewubenduben/patch-1
[discourse_docker.git] / templates / web.template.yml
CommitLineData
9fb5f2d3 1env:
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
16params:
17 # SSH key is required for remote access into the container
b56a2bd7 18 version: tests-passed
9fb5f2d3
SS
19
20 home: /var/www/discourse
fb7c9779 21 upload_size: 3m
9fb5f2d3 22
9fb5f2d3 23run:
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'
87f8d0b3 25 - file:
089518ef 26 path: /etc/runit/1.d/copy-env
87f8d0b3
SS
27 chmod: "+x"
28 contents: |
29 #!/bin/bash
c4498636 30 env > ~/boot_env
87f8d0b3 31 conf=/var/www/discourse/config/discourse.conf
87f8d0b3 32
1cb802ad 33 # find DISCOURSE_ env vars, strip the leader, lowercase the key
797864e6 34 /usr/local/bin/ruby -e 'ENV.each{|k,v| puts "#{$1.downcase} = #{v}" if k =~ /^DISCOURSE_(.*)/}' > $conf
1cb802ad 35
9fb5f2d3
SS
36 - file:
37 path: /etc/service/unicorn/run
38 chmod: "+x"
39 contents: |
40 #!/bin/bash
41 exec 2>&1
9fb5f2d3
SS
42 # redis
43 # postgres
44 cd $home
6d00b2fa 45 chown -R discourse:www-data /shared/log/rails
56e5e6c2 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
9fb5f2d3 47
9fb5f2d3
SS
48 - file:
49 path: /etc/service/nginx/run
50 chmod: "+x"
51 contents: |
52 #!/bin/sh
53 exec 2>&1
4695d446 54 mkdir -p /var/log/nginx
9fb5f2d3
SS
55 exec /usr/sbin/nginx
56
074f2b6a
S
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
9fb5f2d3
SS
71 - exec:
72 cd: $home
73 hook: code
74 cmd:
75 - git reset --hard
76 - git clean -f
36c6b609 77 - git remote set-branches --add origin master
d9c1b419
S
78 - git pull
79 - git fetch origin $version
9fb5f2d3 80 - git checkout $version
9fb5f2d3
SS
81 - mkdir -p tmp/pids
82 - mkdir -p tmp/sockets
b150cad1 83 - touch tmp/.gitkeep
e56a65f6 84 - mkdir -p /shared/log/rails
b6227eb0 85 - bash -c "touch -a /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log"
e56a65f6
MB
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
c4498636 90
9fb5f2d3
SS
91 - exec:
92 cmd:
93 - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
94 - "rm /etc/nginx/sites-enabled/default"
69c891fd 95 - "mkdir -p /var/nginx/cache"
9fb5f2d3
SS
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
6e23c775 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
9e8e16a8
SS
119 - exec:
120 cmd: echo "done configuring web"
121 hook: web_config
122
9fb5f2d3
SS
123 - exec:
124 cd: $home
62418f96 125 hook: web
9fb5f2d3 126 cmd:
e64b0a0b
S
127 # ensure we are on latest bundler
128 - gem update bundler
9fb5f2d3 129 - chown -R discourse $home
70710fa0
EG
130
131 - exec:
132 cd: $home
133 hook: bundle_exec
134 cmd:
e56a65f6
MB
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'
9fb5f2d3 138
553a4fc9
S
139 - file:
140 path: /usr/local/bin/discourse
141 chmod: +x
142 contents: |
143 #!/bin/bash
8a02b91e 144 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/discourse "$@")
553a4fc9
S
145
146 - file:
147 path: /usr/local/bin/rails
148 chmod: +x
149 contents: |
150 #!/bin/bash
cbfcacda
KY
151 # If they requested a console, load pry instead
152 if [ "$@" == "c" -o "$@" == "console" ]
153 then
8a02b91e 154 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec pry -r ./config/environment)
cbfcacda 155 else
8a02b91e 156 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec script/rails "$@")
cbfcacda 157 fi
553a4fc9
S
158
159 - file:
160 path: /usr/local/bin/rake
161 chmod: +x
162 contents: |
163 #!/bin/bash
8a02b91e 164 (cd /var/www/discourse && RAILS_ENV=production sudo -H -E -u discourse bundle exec bin/rake "$@")
553a4fc9
S
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
be82e068
S
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 }
55737024
S
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
25a7de18
S
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
be55cb66
S
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