Crash if SMTP is not configured
[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 - exec:
58 cd: $home
59 hook: code
60 cmd:
61 - git reset --hard
62 - git clean -f
63 - git remote set-branches --add origin master
64 - git pull
65 - git fetch origin $version
66 - git checkout $version
67 - mkdir -p tmp/pids
68 - mkdir -p tmp/sockets
69 - touch tmp/.gitkeep
70 - mkdir -p /shared/log/rails
71 - bash -c "touch /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log"
72 - bash -c "ln -s /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log $home/log"
73 - bash -c "mkdir -p /shared/{uploads,backups}"
74 - bash -c "ln -s /shared/{uploads,backups} $home/public"
75 - chown -R discourse:www-data /shared/log/rails /shared/uploads /shared/backups
76
77 - exec:
78 cmd:
79 - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
80 - "rm /etc/nginx/sites-enabled/default"
81 - "mkdir -p /var/nginx/cache"
82
83 - replace:
84 filename: /etc/nginx/nginx.conf
85 from: pid /run/nginx.pid;
86 to: daemon off;
87
88 - replace:
89 filename: "/etc/nginx/conf.d/discourse.conf"
90 from: /upstream[^\}]+\}/m
91 to: "upstream discourse {
92 server 127.0.0.1:3000;
93 }"
94
95 - replace:
96 filename: "/etc/nginx/conf.d/discourse.conf"
97 from: /server_name.+$/
98 to: server_name _ ;
99
100 - replace:
101 filename: "/etc/nginx/conf.d/discourse.conf"
102 from: /client_max_body_size.+$/
103 to: client_max_body_size $upload_size ;
104
105 - exec:
106 cmd: echo "done configuring web"
107 hook: web_config
108
109 - exec:
110 cd: $home
111 hook: web
112 cmd:
113 # ensure we are on latest bundler
114 - gem update bundler
115 - chown -R discourse $home
116 - su discourse -c 'bundle install --deployment --verbose --without test --without development'
117 - su discourse -c 'bundle exec rake db:migrate'
118 - su discourse -c 'bundle exec rake assets:precompile'
119
120 - file:
121 path: /usr/local/bin/discourse
122 chmod: +x
123 contents: |
124 #!/bin/bash
125 (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec script/discourse "$@")
126
127 - file:
128 path: /usr/local/bin/rails
129 chmod: +x
130 contents: |
131 #!/bin/bash
132 # If they requested a console, load pry instead
133 if [ "$@" == "c" -o "$@" == "console" ]
134 then
135 (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec pry -r ./config/environment)
136 else
137 (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec script/rails "$@")
138 fi
139
140 - file:
141 path: /usr/local/bin/rake
142 chmod: +x
143 contents: |
144 #!/bin/bash
145 (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec bin/rake "$@")
146
147 - file:
148 path: /etc/update-motd.d/10-web
149 chmod: +x
150 contents: |
151 #!/bin/bash
152 echo
153 echo Use: rails, rake or discourse to execute commands in production
154 echo
155
156 - file:
157 path: /etc/logrotate.d/rails
158 contents: |
159 /shared/log/rails/*.log
160 {
161 rotate 14
162 dateext
163 daily
164 missingok
165 notifempty
166 delaycompress
167 compress
168 postrotate
169 sv 1 unicorn
170 endscript
171 }