when a container starts copy the discourse ENV over to discourse.conf
[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 # slightly less aggressive than "recommendation" but works fine with oobgc
6 RUBY_GC_MALLOC_LIMIT: 40000000
7 # this ensures we have enough heap space to handle a big pile of small reqs
8 RUBY_HEAP_MIN_SLOTS: 800000
9
10 DISCOURSE_DB_SOCKET: /var/run/postgresql
11 DISCOURSE_DB_HOST:
12 DISCOURSE_DB_PORT:
13
14
15 params:
16 # SSH key is required for remote access into the container
17 version: HEAD
18
19 home: /var/www/discourse
20
21 run:
22 - file:
23 path: /etc/service/copy_env/run
24 chmod: "+x"
25 contents: |
26 #!/bin/bash
27 conf=/var/www/discourse/config/discourse.conf
28 sudo -u discourse echo > $conf
29
30 for x in `env | /usr/bin/awk -F= '{if($1 ~ /DISCOURSE_/) print $1}'`
31 do
32 c=${x,,}
33 c=${c:10}
34 echo "$c"=${!x} >> $conf
35 done
36 # I dunno there may be a cleaner way to handle this
37 exec sleep 2147483647
38
39 - file:
40 path: /etc/service/unicorn/run
41 chmod: "+x"
42 contents: |
43 #!/bin/bash
44 exec 2>&1
45 # redis
46 # postgres
47 sv start copy_env || exit 1
48 cd $home
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/sidekiq/run
53 chmod: "+x"
54 contents: |
55 #!/bin/bash
56 exec 2>&1
57 # redis
58 # postgres
59 sv start copy_env || exit 1
60 cd $home
61 exec sudo -E -u discourse LD_PRELOAD=/usr/lib/libjemalloc.so.1 bundle exec sidekiq
62
63 - file:
64 path: /etc/service/nginx/run
65 chmod: "+x"
66 contents: |
67 #!/bin/sh
68 exec 2>&1
69 exec /usr/sbin/nginx
70
71 - exec:
72 cd: $home
73 hook: code
74 cmd:
75 - git reset --hard
76 - git clean -f
77 - git pull
78 - git checkout $version
79 - mkdir -p tmp/pids
80 - mkdir -p tmp/sockets
81 - touch tmp/.gitkeep
82 - mkdir -p /shared/log/rails
83 - rm -r log
84 - ln -s /shared/log/rails $home/log
85 - mkdir -p /shared/uploads
86 - ln -s /shared/uploads $home/public/uploads
87 - chown -R discourse:www-data /shared/uploads
88 - chown -R discourse:www-data /shared/log/rails
89 - exec:
90 cmd:
91 - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
92 - "rm /etc/nginx/sites-enabled/default"
93
94 - replace:
95 filename: /etc/nginx/nginx.conf
96 from: pid /run/nginx.pid;
97 to: daemon off;
98
99 - replace:
100 filename: "/etc/nginx/conf.d/discourse.conf"
101 from: /upstream[^\}]+\}/m
102 to: "upstream discourse {
103 server 127.0.0.1:3000;
104 }"
105
106 - replace:
107 filename: "/etc/nginx/conf.d/discourse.conf"
108 from: /server_name.+$/
109 to: server_name _ ;
110
111 - exec:
112 cmd: echo "done configuring web"
113 hook: web_config
114
115 - exec:
116 cd: $home
117 cmd:
118 - chown -R discourse $home
119 - sudo -E -u discourse bundle install --deployment --verbose --without test --without development
120 - sudo -E -u discourse bundle exec rake db:migrate
121 - sudo -E -u discourse bundle exec rake assets:precompile
122