fix default
[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 - 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 - "mkdir -p /var/nginx/cache"
91
92 - replace:
93 filename: /etc/nginx/nginx.conf
94 from: pid /run/nginx.pid;
95 to: daemon off;
96
97 - replace:
98 filename: "/etc/nginx/conf.d/discourse.conf"
99 from: /upstream[^\}]+\}/m
100 to: "upstream discourse {
101 server 127.0.0.1:3000;
102 }"
103
104 - replace:
105 filename: "/etc/nginx/conf.d/discourse.conf"
106 from: /server_name.+$/
107 to: server_name _ ;
108
109 - replace:
110 filename: "/etc/nginx/conf.d/discourse.conf"
111 from: /client_max_body_size.+$/
112 to: client_max_body_size $upload_size ;
113
114 - exec:
115 cmd: echo "done configuring web"
116 hook: web_config
117
118 - exec:
119 cd: $home
120 hook: web
121 cmd:
122 # ensure we are on latest bundler
123 - gem update bundler
124 - chown -R discourse $home
125 - sudo -E -u discourse bundle install --deployment --verbose --without test --without development
126 - sudo -E -u discourse bundle exec rake db:migrate
127 - sudo -E -u discourse bundle exec rake assets:precompile
128
129 - file:
130 path: /usr/local/bin/discourse
131 chmod: +x
132 contents: |
133 #!/bin/bash
134 (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec script/discourse "$@")
135
136 - file:
137 path: /usr/local/bin/rails
138 chmod: +x
139 contents: |
140 #!/bin/bash
141 # If they requested a console, load pry instead
142 if [ "$@" == "c" -o "$@" == "console" ]
143 then
144 (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec pry -r ./config/environment)
145 else
146 (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec script/rails "$@")
147 fi
148
149 - file:
150 path: /usr/local/bin/rake
151 chmod: +x
152 contents: |
153 #!/bin/bash
154 (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec bin/rake "$@")
155
156 - file:
157 path: /etc/update-motd.d/10-web
158 chmod: +x
159 contents: |
160 #!/bin/bash
161 echo
162 echo Use: rails, rake or discourse to execute commands in production
163 echo
164