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