ssh needs to be first right after runit, otherwise hard to extend
[discourse_docker.git] / standalone.template.yml
1 # expose:
2 # expose public port 80 to map to private docker port 80 (web)
3 # - "80:80"
4 # expose public port 2222 to map to private docker port 22 (ssh)
5 # - "2222:22"
6
7 # ENV is baked in to the image, any changes here require ./launcher bootstrap to run
8 env:
9 # Comma delimited list of emails, required if you want admin access for first account
10 DEVELOPER_EMAILS: 'YOUR_EMAIL@EMAIL.COM1'
11 # You can have redis on a different box
12 # REDIS_PROVIDER_URL: 'redis://l.discourse:6379'
13 RAILS_ENV: 'production'
14 UNICORN_WORKERS: 3
15 # slightly less aggressive than "recommendation" but works fine with oobgc
16 RUBY_GC_MALLOC_LIMIT: 40000000
17
18 params:
19 # SSH key is required for remote access into the container
20 ssh_key: YOUR_SSH_KEY_HERE
21 version: HEAD
22
23 home: /var/www/discourse
24
25 # You can connect to any DB you wish to
26 database_yml:
27 production:
28 database: discourse
29 username: discourse
30 socket: /var/run/postgresql
31 password:
32 host:
33 host_names:
34 - YOUR_HOSTNAME_HERE
35
36 run:
37 - file:
38 path: /etc/service/cron/run
39 chmod: "+x"
40 contents: |
41 #!/bin/bash
42 exec 2>&1
43 cd /
44 exec cron
45
46 - file:
47 path: /var/lib/postgresql/take-database-backup
48 chown: postgres:postgres
49 chmod: "+x"
50 contents: |
51 #!/bin/bash
52 ID=db-$(date +%F_%T)
53 FILENAME=/shared/postgres_backup/$ID.tar.gz
54 pg_basebackup --format=tar --pgdata=- --xlog --gzip --label=$ID > $FILENAME
55 echo $FILENAME
56
57 - file:
58 path: /var/spool/cron/crontabs/postgres
59 contents: |
60 # m h dom mon dow command
61 #MAILTO=?
62 0 */4 * * * /var/lib/postgresql/take-database-backup
63
64 - file:
65 path: /etc/service/unicorn/run
66 chmod: "+x"
67 contents: |
68 #!/bin/bash
69 exec 2>&1
70 $env
71 sv start redis || exit 1
72 sv start postgres || exit 1
73 cd $home
74 exec sudo -E -u discourse LD_PRELOAD=/usr/lib/libjemalloc.so.1 bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb
75
76 - file:
77 path: /etc/service/sidekiq/run
78 chmod: "+x"
79 contents: |
80 #!/bin/bash
81 exec 2>&1
82 $env
83 sv start redis || exit 1
84 sv start postgres || exit 1
85 cd $home
86 exec sudo -E -u discourse LD_PRELOAD=/usr/lib/libjemalloc.so.1 bundle exec sidekiq
87
88 - file:
89 path: /etc/service/sshd/run
90 chmod: "+x"
91 contents: |
92 #!/bin/sh
93 exec 2>&1
94 exec /usr/sbin/sshd -D -e
95
96 - file:
97 path: /etc/service/redis/run
98 chmod: "+x"
99 contents: |
100 #!/bin/sh
101 exec 2>&1
102 exec sudo -u redis /usr/bin/redis-server /etc/redis/redis.conf
103
104 - file:
105 path: /etc/service/nginx/run
106 chmod: "+x"
107 contents: |
108 #!/bin/sh
109 exec 2>&1
110 exec /usr/sbin/nginx
111
112 - file:
113 path: /etc/service/postgres/run
114 chmod: "+x"
115 contents: |
116 #!/bin/sh
117 exec 2>&1
118 exec sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main
119
120 - exec:
121 cmd:
122 - mkdir -p /var/run/sshd
123 - mkdir -p /root/.ssh
124 - echo $ssh_key >> /root/.ssh/authorized_keys
125
126 - exec:
127 cd: $home
128 hook: code
129 cmd:
130 - git reset --hard
131 - git clean -f
132 - git pull
133 - git checkout $head
134 - cp config/database.yml.production-sample config/database.yml
135 - cp config/redis.yml.sample config/redis.yml
136 - cp config/environments/production.rb.sample config/environments/production.rb
137 - mkdir -p tmp/pids
138 - mkdir -p tmp/sockets
139 - touch tmp/.gitkeep
140 - mkdir -p /shared/log/rails
141 - rm -r log
142 - ln -s /shared/log/rails $home/log
143 - mkdir -p /shared/uploads
144 - ln -s /shared/uploads $home/public/uploads
145 - chown -R discourse /shared/uploads
146 - chown -R discourse /shared/log/rails
147 - exec:
148 cmd:
149 - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
150 - "rm /etc/nginx/sites-enabled/default"
151
152 - replace:
153 filename: /etc/nginx/nginx.conf
154 from: pid /run/nginx.pid;
155 to: daemon off;
156
157 - replace:
158 filename: "/etc/nginx/conf.d/discourse.conf"
159 from: /upstream[^\}]+\}/m
160 to: "upstream discourse {
161 server 127.0.0.1:3000;
162 }"
163
164 - replace:
165 filename: "/etc/nginx/conf.d/discourse.conf"
166 from: /server_name.+$/
167 to: server_name _ ;
168
169 - replace:
170 filename: "/etc/redis/redis.conf"
171 from: "daemonize yes"
172 to: ""
173 - replace:
174 filename: "/etc/redis/redis.conf"
175 from: /^pidfile.*$/
176 to: ""
177
178 - exec:
179 cmd:
180 - install -d -m 0755 -o redis -g redis /shared/redis_data
181
182 - replace:
183 filename: "/etc/redis/redis.conf"
184 from: /^logfile.*$/
185 to: "logfile stdout"
186
187 - replace:
188 filename: "/etc/redis/redis.conf"
189 from: /^dir .*$/
190 to: "dir /shared/redis_data"
191
192 # we can not migrate without redis
193 - exec:
194 background: true
195 cmd: "sudo -u redis /usr/bin/redis-server /etc/redis/redis.conf"
196
197 - merge: $home/config/database.yml $database_yml
198
199 - exec:
200 cmd:
201 - chown -R root /var/lib/postgresql/9.2/main
202 - "[ ! -e /shared/postgres_data ] && cp -r /var/lib/postgresql/9.2/main /shared/postgres_data || exit 0"
203 - chown -R postgres:postgres /shared/postgres_data
204
205 - replace:
206 filename: "/etc/postgresql/9.2/main/postgresql.conf"
207 from: "data_directory = '/var/lib/postgresql/9.2/main'"
208 to: "data_directory = '/shared/postgres_data'"
209
210 # Necessary to enable backups
211 - exec:
212 cmd:
213 - install -d -m 0755 -o postgres -g postgres /shared/postgres_backup
214
215 - replace:
216 filename: "/etc/postgresql/9.2/main/postgresql.conf"
217 from: /#?max_wal_senders *=.*/
218 to: "max_wal_senders = 4"
219
220 - replace:
221 filename: "/etc/postgresql/9.2/main/postgresql.conf"
222 from: /#?wal_level *=.*/
223 to: "wal_level = hot_standby"
224
225 - replace:
226 filename: "/etc/postgresql/9.2/main/pg_hba.conf"
227 from: /^#local +replication +postgres +peer$/
228 to: "local replication postgres peer"
229
230 - exec:
231 background: true
232 cmd: "sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main"
233
234 # give db a few secs to start up
235 - exec: "sleep 5"
236
237 - exec: sudo -u postgres createdb discourse || exit 0
238 - exec:
239 stdin: |
240 create user discourse;
241 cmd: sudo -u postgres psql discourse
242 raise_on_fail: false
243
244 - exec:
245 stdin: |
246 grant all privileges on database discourse to discourse;
247 cmd: sudo -u postgres psql discourse
248 raise_on_fail: false
249
250 - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "create extension if not exists hstore;"'
251 - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "create extension if not exists pg_trgm;"'
252
253
254 - exec:
255 cd: $home
256 cmd:
257 - chown -R discourse $home
258 - sudo -E -u discourse bundle install --deployment --without test --without development
259 - sudo -E -u discourse bundle exec rake db:migrate
260 - sudo -E -u discourse bundle exec rake assets:precompile
261