4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/bard/cli/setup.rb', line 4
def self.included mod
mod.class_eval do
desc "setup", "installs app in nginx"
def setup
system "sudo tee /etc/nginx/snippets/common.conf >/dev/null <<-EOF
listen 80;
passenger_enabled on;
location ~* \\.(ico|css|js|gif|jp?g|png|webp) {
access_log off;
if (\\$request_filename ~ \"-[0-9a-f]{32}\\.\") {
expires max;
add_header Cache-Control public;
}
}
gzip_static on;
EOF"
path = "/etc/nginx/sites-available/#{project_name}"
system "sudo tee #{path} >/dev/null <<-EOF
server {
include /etc/nginx/snippets/common.conf;
server_name #{nginx_server_name};
root #{Dir.pwd}/public;
}
EOF"
dest_path = path.sub("sites-available", "sites-enabled")
system "sudo ln -sf #{path} #{dest_path}" if !File.exist?(dest_path)
system "sudo service nginx restart"
end
private
def nginx_server_name
case ENV["RAILS_ENV"]
when "production"
(config[:production].ping.map do |str|
"*.#{URI.parse(str).host}"
end + ["_"]).join(" ")
when "staging" then "#{project_name}.botandrose.com"
else "#{project_name}.localhost"
end
end
end
end
|