4e67e6e3bd245d3609eaf617ecff415ad13b121e
[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 RAILS4: 1
15 UNICORN_WORKERS: 3
16
17 params:
18 # SSH key is required for remote access into the container
19 ssh_key: YOUR_SSH_KEY_HERE
20 version: HEAD
21
22 home: /var/www/discourse
23
24 # You can connect to any DB you wish to
25 database_yml:
26 production:
27 database: discourse
28 username: discourse
29 socket: /var/run/postgresql
30 password:
31 host:
32 host_names:
33 - YOUR_HOSTNAME_HERE
34
35 run:
36 - file:
37 path: /etc/service/unicorn/run
38 chmod: "+x"
39 contents: |
40 #!/bin/bash
41 exec 2>&1
42 $env
43 sv start redis || exit 1
44 sv start postgres || exit 1
45 cd $home
46 exec sudo -E -u discourse bundle exec unicorn -c config/unicorn.conf.rb
47
48 - file:
49 path: /etc/service/sidekiq/run
50 chmod: "+x"
51 contents: |
52 #!/bin/bash
53 exec 2>&1
54 $env
55 sv start redis || exit 1
56 sv start postgres || exit 1
57 cd $home
58 exec sudo -E -u discourse bundle exec sidekiq
59
60 - file:
61 path: /etc/service/sshd/run
62 chmod: "+x"
63 contents: |
64 #!/bin/sh
65 exec 2>&1
66 exec /usr/sbin/sshd -D -e
67
68 - file:
69 path: /etc/service/redis/run
70 chmod: "+x"
71 contents: |
72 #!/bin/sh
73 exec 2>&1
74 exec sudo -u redis /usr/bin/redis-server /etc/redis/redis.conf
75
76 - file:
77 path: /etc/service/nginx/run
78 chmod: "+x"
79 contents: |
80 #!/bin/sh
81 exec 2>&1
82 exec /usr/sbin/nginx
83
84 - file:
85 path: /etc/service/postgres/run
86 chmod: "+x"
87 contents: |
88 #!/bin/sh
89 exec 2>&1
90 exec sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main
91
92
93 - exec:
94 cd: $home
95 hook: code
96 cmd:
97 - git reset --hard
98 - git clean -f
99 - git pull
100 - git checkout $head
101 - cp config/database.yml.production-sample config/database.yml
102 - cp config/redis.yml.sample config/redis.yml
103 - cp config/environments/production.rb.sample config/environments/production.rb
104 - mkdir -p tmp/pids
105 - mkdir -p tmp/sockets
106 - mkdir -p log
107 - exec:
108 cmd:
109 - mkdir -p /var/run/sshd
110 - mkdir -p /root/.ssh
111 - echo $ssh_key >> /root/.ssh/authorized_keys
112 - exec:
113 cmd:
114 - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
115 - "rm /etc/nginx/sites-enabled/default"
116
117 - replace:
118 filename: /etc/nginx/nginx.conf
119 from: pid /run/nginx.pid;
120 to: daemon off;
121
122 - replace:
123 filename: "/etc/nginx/conf.d/discourse.conf"
124 from: /upstream[^\}]+\}/m
125 to: "upstream discourse {
126 server 127.0.0.1:3000;
127 }"
128
129 - replace:
130 filename: "/etc/nginx/conf.d/discourse.conf"
131 from: /server_name.+$/
132 to: server_name _ ;
133
134 - replace:
135 filename: "/etc/redis/redis.conf"
136 from: "daemonize yes"
137 to: ""
138 - replace:
139 filename: "/etc/redis/redis.conf"
140 from: /^pidfile.*$/
141 to: ""
142
143 - exec:
144 cmd:
145 - mkdir -p /shared/redis_data
146 - chown -R redis /shared/redis_data
147 - chgrp -R redis /shared/redis_data
148
149 - replace:
150 filename: "/etc/redis/redis.conf"
151 from: /^logfile.*$/
152 to: "logfile stdout"
153
154 - replace:
155 filename: "/etc/redis/redis.conf"
156 from: /^dir .*$/
157 to: "dir /shared/redis_data"
158
159 # we can not migrate without redis
160 - exec:
161 background: true
162 cmd: "sudo -u redis /usr/bin/redis-server /etc/redis/redis.conf"
163
164 - merge: $home/config/database.yml $database_yml
165
166 - exec:
167 cmd:
168 - chown -R root /var/lib/postgresql/9.2/main
169 - "[ ! -e /shared/postgres_data ] && cp -r /var/lib/postgresql/9.2/main /shared/postgres_data || exit 0"
170 - chown -R postgres /shared/postgres_data
171 - chgrp -R postgres /shared/postgres_data
172
173 - replace:
174 filename: "/etc/postgresql/9.2/main/postgresql.conf"
175 from: "data_directory = '/var/lib/postgresql/9.2/main'"
176 to: "data_directory = '/shared/postgres_data'"
177
178 - exec:
179 background: true
180 cmd: "sudo -u postgres /usr/lib/postgresql/9.2/bin/postmaster -D /etc/postgresql/9.2/main"
181
182 # give db a few secs to start up
183 - exec: "sleep 5"
184
185 - exec: sudo -u postgres createdb discourse || exit 0
186 - exec:
187 stdin: |
188 create user discourse;
189 cmd: sudo -u postgres psql discourse
190 raise_on_fail: false
191
192 - exec:
193 stdin: |
194 grant all privileges on database discourse to discourse;
195 cmd: sudo -u postgres psql discourse
196 raise_on_fail: false
197
198 - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "create extension if not exists hstore;"'
199 - exec: /bin/bash -c 'sudo -u postgres psql discourse <<< "create extension if not exists pg_trgm;"'
200
201
202 - exec:
203 cd: $home
204 cmd:
205 - chown -R discourse $home
206 - sudo -E -u discourse bundle install --deployment
207 - sudo -E -u discourse bundle exec rake db:migrate
208 - sudo -E -u discourse bundle exec rake assets:precompile
209