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