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