Big cleanup of discourse docker environment
[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
fb7c9779 21 upload_size: 3m
9fb5f2d3 22
9fb5f2d3 23run:
87f8d0b3 24 - file:
089518ef 25 path: /etc/runit/1.d/copy-env
87f8d0b3
SS
26 chmod: "+x"
27 contents: |
28 #!/bin/bash
c4498636 29 env > ~/boot_env
87f8d0b3 30 conf=/var/www/discourse/config/discourse.conf
87f8d0b3 31
1cb802ad
MB
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
9fb5f2d3
SS
35 - file:
36 path: /etc/service/unicorn/run
37 chmod: "+x"
38 contents: |
39 #!/bin/bash
40 exec 2>&1
9fb5f2d3
SS
41 # redis
42 # postgres
43 cd $home
6d00b2fa 44 chown -R discourse:www-data /shared/log/rails
e56a65f6 45 LD_PRELOAD=/usr/lib/libjemalloc.so.1 exec su discourse -c 'bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb'
9fb5f2d3 46
9fb5f2d3
SS
47 - file:
48 path: /etc/service/nginx/run
49 chmod: "+x"
50 contents: |
51 #!/bin/sh
52 exec 2>&1
4695d446 53 mkdir -p /var/log/nginx
9fb5f2d3
SS
54 exec /usr/sbin/nginx
55
56 - exec:
57 cd: $home
58 hook: code
59 cmd:
60 - git reset --hard
61 - git clean -f
36c6b609 62 - git remote set-branches --add origin master
d9c1b419
S
63 - git pull
64 - git fetch origin $version
9fb5f2d3 65 - git checkout $version
9fb5f2d3
SS
66 - mkdir -p tmp/pids
67 - mkdir -p tmp/sockets
b150cad1 68 - touch tmp/.gitkeep
e56a65f6
MB
69 - mkdir -p /shared/log/rails
70 - bash -c "touch /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log"
71 - bash -c "ln -s /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr}.log $home/log"
72 - bash -c "mkdir -p /shared/{uploads,backups}"
73 - bash -c "ln -s /shared/{uploads,backups} $home/public"
74 - chown -R discourse:www-data /shared/log/rails /shared/uploads /shared/backups
c4498636 75
9fb5f2d3
SS
76 - exec:
77 cmd:
78 - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
79 - "rm /etc/nginx/sites-enabled/default"
69c891fd 80 - "mkdir -p /var/nginx/cache"
9fb5f2d3
SS
81
82 - replace:
83 filename: /etc/nginx/nginx.conf
84 from: pid /run/nginx.pid;
85 to: daemon off;
86
87 - replace:
88 filename: "/etc/nginx/conf.d/discourse.conf"
89 from: /upstream[^\}]+\}/m
90 to: "upstream discourse {
91 server 127.0.0.1:3000;
92 }"
93
94 - replace:
95 filename: "/etc/nginx/conf.d/discourse.conf"
96 from: /server_name.+$/
97 to: server_name _ ;
98
6e23c775 99 - replace:
100 filename: "/etc/nginx/conf.d/discourse.conf"
101 from: /client_max_body_size.+$/
102 to: client_max_body_size $upload_size ;
103
9e8e16a8
SS
104 - exec:
105 cmd: echo "done configuring web"
106 hook: web_config
107
9fb5f2d3
SS
108 - exec:
109 cd: $home
62418f96 110 hook: web
9fb5f2d3 111 cmd:
e64b0a0b
S
112 # ensure we are on latest bundler
113 - gem update bundler
9fb5f2d3 114 - chown -R discourse $home
e56a65f6
MB
115 - su discourse -c 'bundle install --deployment --verbose --without test --without development'
116 - su discourse -c 'bundle exec rake db:migrate'
117 - su discourse -c 'bundle exec rake assets:precompile'
9fb5f2d3 118
553a4fc9
S
119 - file:
120 path: /usr/local/bin/discourse
121 chmod: +x
122 contents: |
123 #!/bin/bash
124 (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec script/discourse "$@")
125
126 - file:
127 path: /usr/local/bin/rails
128 chmod: +x
129 contents: |
130 #!/bin/bash
cbfcacda
KY
131 # If they requested a console, load pry instead
132 if [ "$@" == "c" -o "$@" == "console" ]
133 then
134 (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec pry -r ./config/environment)
135 else
136 (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec script/rails "$@")
137 fi
553a4fc9
S
138
139 - file:
140 path: /usr/local/bin/rake
141 chmod: +x
142 contents: |
143 #!/bin/bash
144 (cd /var/www/discourse && RAILS_ENV=production sudo -E -u discourse bundle exec bin/rake "$@")
145
146 - file:
147 path: /etc/update-motd.d/10-web
148 chmod: +x
149 contents: |
150 #!/bin/bash
151 echo
152 echo Use: rails, rake or discourse to execute commands in production
153 echo
154
be82e068
S
155 - file:
156 path: /etc/logrotate.d/rails
157 contents: |
158 /shared/log/rails/*.log
159 {
160 rotate 14
161 dateext
162 daily
163 missingok
164 notifempty
165 delaycompress
166 compress
167 postrotate
168 sv 1 unicorn
169 endscript
170 }