Merge pull request #64 from riking/configurable-upload-size
[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: 2m
22
23 run:
24 - file:
25 path: /etc/service/copy_env/run
26 chmod: "+x"
27 contents: |
28 #!/bin/bash
29 env > ~/boot_env
30 conf=/var/www/discourse/config/discourse.conf
31 sudo -u discourse echo > $conf
32
33 for x in `env | /usr/bin/awk -F= '{if($1 ~ /DISCOURSE_/) print $1}'`
34 do
35 c=${x,,}
36 c=${c:10}
37 echo "$c"=${!x} >> $conf
38 done
39 # I dunno there may be a cleaner way to handle this
40 exec sleep 2147483647
41
42 - file:
43 path: /etc/service/unicorn/run
44 chmod: "+x"
45 contents: |
46 #!/bin/bash
47 exec 2>&1
48 # redis
49 # postgres
50 sv start copy_env || exit 1
51 cd $home
52 exec sudo -E -u discourse LD_PRELOAD=/usr/lib/libjemalloc.so.1 bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb
53
54 - file:
55 path: /etc/service/nginx/run
56 chmod: "+x"
57 contents: |
58 #!/bin/sh
59 exec 2>&1
60 exec /usr/sbin/nginx
61
62 - exec:
63 cd: $home
64 hook: code
65 cmd:
66 - git reset --hard
67 - git clean -f
68 - git remote set-branches --add origin master
69 - git pull
70 - git fetch origin $version
71 - git checkout $version
72 - mkdir -p tmp/pids
73 - mkdir -p tmp/sockets
74 - mkdir -p /shared/log/rails
75 - mkdir -p /shared/uploads
76 - mkdir -p /shared/backups
77 - touch tmp/.gitkeep
78 - rm -r log
79 - ln -s /shared/log/rails $home/log
80 - ln -s /shared/uploads $home/public/uploads
81 - ln -s /shared/backups $home/public/backups
82 - chown -R discourse:www-data /shared/log/rails
83 - chown -R discourse:www-data /shared/uploads
84 - chown -R discourse:www-data /shared/backups
85
86 - exec:
87 cmd:
88 - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
89 - "rm /etc/nginx/sites-enabled/default"
90
91 - replace:
92 filename: /etc/nginx/nginx.conf
93 from: pid /run/nginx.pid;
94 to: daemon off;
95
96 - replace:
97 filename: "/etc/nginx/conf.d/discourse.conf"
98 from: /upstream[^\}]+\}/m
99 to: "upstream discourse {
100 server 127.0.0.1:3000;
101 }"
102
103 - replace:
104 filename: "/etc/nginx/conf.d/discourse.conf"
105 from: /server_name.+$/
106 to: server_name _ ;
107
108 - replace:
109 filename: "/etc/nginx/conf.d/discourse.conf"
110 from: /client_max_body_size.+$/
111 to: client_max_body_size $upload_size ;
112
113 - exec:
114 cmd: echo "done configuring web"
115 hook: web_config
116
117 - exec:
118 cd: $home
119 hook: web
120 cmd:
121 # ensure we are on latest bundler
122 - gem update bundler
123 - chown -R discourse $home
124 - sudo -E -u discourse bundle install --deployment --verbose --without test --without development
125 - sudo -E -u discourse bundle exec rake db:migrate
126 - sudo -E -u discourse bundle exec rake assets:precompile
127
128 - file:
129 path: /usr/local/bin/discourse
130 chmod: +x
131 contents: |
132 #!/bin/bash
133 (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec script/discourse "$@")
134
135 - file:
136 path: /usr/local/bin/rails
137 chmod: +x
138 contents: |
139 #!/bin/bash
140 # If they requested a console, load pry instead
141 if [ "$@" == "c" -o "$@" == "console" ]
142 then
143 (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec pry -r ./config/environment)
144 else
145 (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec script/rails "$@")
146 fi
147
148 - file:
149 path: /usr/local/bin/rake
150 chmod: +x
151 contents: |
152 #!/bin/bash
153 (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec bin/rake "$@")
154
155 - file:
156 path: /etc/update-motd.d/10-web
157 chmod: +x
158 contents: |
159 #!/bin/bash
160 echo
161 echo Use: rails, rake or discourse to execute commands in production
162 echo
163