-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.rb
106 lines (91 loc) · 3.43 KB
/
install.rb
1
2
3
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Install a spontaneous stack onto the server configured in config/deploy.rb
# The same server could potentially host multiple sites
# so anything that happens here should try to respect any shared state
# The only case I can think of that might cause problems is the
# simultaneous server installation where different sites could be built
# against different Gem versions.
$:<< File.join(File.dirname(__FILE__))
%w(swap essential scm system_update imagemagick image_optimization xapian postgresql wale nginx runit chruby simultaneous user spontaneous).each do |lib|
require "stack/#{lib}"
end
# Let vim provide the :editor package
require 'stack/vim'
# Get current simultaneous version
require 'simultaneous'
# Use dotenv to load production env settings
require 'dotenv'
# install the version of ruby that we're using to develop locally
ruby_version = "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
ruby = "ruby-#{ruby_version}"
opts = {
ruby_version: ruby_version,
ruby: ruby,
simultaneous_version: Simultaneous::VERSION,
simultaneous_socket: Simultaneous::DEFAULT_CONNECTION,
group: 'spontaneous',
# additional site env settings
environment: {},
secure: false
}
policy :system, roles: [:app, :db] do
# REENABLE AFTER DEV
requires :system_update
requires :swap, {}, opts
requires :essential
requires :editor
requires :scm
requires :process_manager
end
policy :db, roles: :db do
requires :database, {}, opts
requires :database_backup, {}, opts
end
policy :spontaneous, roles: :app do
requires :image_processing, {}, opts
requires :image_optimization, {}, opts
requires :search, {}, opts
# Slightly weird params... the first hash are taken as opts for sprinkle
# the second is passed to the package itself
requires :ruby, {}, opts
requires :simultaneous, {}, opts
requires :user, {}, opts
requires :webserver, {}, opts
requires :spontaneous, {}, opts
end
deployment do
delivery :capistrano do
begin
recipes 'config/deploy'
rescue LoadError
$stderr.puts "Unable to load 'deploy'"
exit 1
end
# this runs in a Capistrano::Config context so we can override config here
# run as root for installation
opts[:ruby_version] = fetch(:ruby_version, opts[:ruby_version])
opts[:user] = fetch(:user)
opts[:repository] = fetch(:repository)
opts[:domain] = fetch(:domain)
opts[:cms_host] = fetch(:cms)
opts[:site_id] = fetch(:domain).to_s.gsub(/\./, '_')
# http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server
# I'm mostly making the numbers up. Without the ability to introspect the
# server state/config a la Chef there's no good way to provide server-specific
# values without hand-coding
server_memory = fetch(:server_memory_mb)
opts[:server_memory_mb] = server_memory
opts[:nginx_opts] = fetch(:nginx_opts, {})
opts[:postgres_config] = {
shared_buffers: (server_memory * 0.15).to_i, # If you have less RAM ... 15% is more typical there
effective_cache_size: 80, # On UNIX-like systems, add the free+cached numbers from free or top to get an estimate
}.merge(fetch(:postgres_config, {}))
set :user, 'root'
env = Dotenv::Environment.new(fetch(:production_env_file)) if File.exist?(fetch(:production_env_file))
opts[:production_env] = env
end
source do
prefix '/usr/local'
archives '/usr/local/sources'
builds '/usr/local/build'
end
end