stop contorting with buggy awk code
[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/runit/1.d/copy-env
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 /usr/local/bin/ruby -e 'ENV.each{|k,v| puts "#{$1.downcase} = #{v}" if k =~ /^DISCOURSE_(.*)/}' > $conf
34
35 - file:
36 path: /etc/service/unicorn/run
37 chmod: "+x"
38 contents: |
39 #!/bin/bash
40 exec 2>&1
41 # redis
42 # postgres
43 cd $home
44 chown -R discourse:www-data /shared/log/rails
45 LD_PRELOAD=/usr/lib/libjemalloc.so.1 HOME=/home/discourse USER=discourse exec chpst -u discourse:www-data -U discourse:www-data bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb
46
47 - file:
48 path: /etc/service/nginx/run
49 chmod: "+x"
50 contents: |
51 #!/bin/sh
52 exec 2>&1
53 mkdir -p /var/log/nginx
54 exec /usr/sbin/nginx
55
56 - exec:
57 cd: $home
58 hook: code
59 cmd:
60 - git reset --hard
61 - git clean -f
62 - git remote set-branches --add origin master
63 - git pull
64 - git fetch origin $version
65 - git checkout $version
66 - mkdir -p tmp/pids
67 - mkdir -p tmp/sockets
68 - touch tmp/.gitkeep
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
75
76 - exec:
77 cmd:
78 - "cp $home/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf"
79 - "rm /etc/nginx/sites-enabled/default"
80 - "mkdir -p /var/nginx/cache"
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
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
104 - exec:
105 cmd: echo "done configuring web"
106 hook: web_config
107
108 - exec:
109 cd: $home
110 hook: web
111 cmd:
112 # ensure we are on latest bundler
113 - gem update bundler
114 - chown -R discourse $home
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'
118
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
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
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
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 }