foreplay 0.9.13 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +1 -1
- data/lib/foreplay/cli.rb +47 -45
- data/lib/foreplay/engine/defaults.rb +60 -0
- data/lib/foreplay/engine/logger.rb +50 -46
- data/lib/foreplay/engine/port.rb +65 -60
- data/lib/foreplay/engine/remote/check.rb +44 -38
- data/lib/foreplay/engine/remote/step.rb +34 -28
- data/lib/foreplay/engine/remote.rb +93 -86
- data/lib/foreplay/engine/role.rb +19 -15
- data/lib/foreplay/engine/secrets.rb +28 -24
- data/lib/foreplay/engine/server.rb +66 -55
- data/lib/foreplay/engine/step.rb +100 -96
- data/lib/foreplay/engine.rb +57 -106
- data/lib/foreplay/launcher.rb +9 -7
- data/lib/foreplay/setup.rb +26 -24
- data/lib/foreplay/version.rb +1 -1
- data/lib/foreplay.rb +14 -11
- data/spec/lib/foreplay/deploy_spec.rb +6 -2
- metadata +3 -4
- data/foreplay.rake +0 -28
- data/lib/foreplay/foreplay.rb +0 -9
data/lib/foreplay/engine.rb
CHANGED
@@ -2,126 +2,77 @@ require 'yaml'
|
|
2
2
|
require 'string'
|
3
3
|
require 'hash'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
@mode = :check
|
24
|
-
execute
|
25
|
-
end
|
26
|
-
|
27
|
-
def execute
|
28
|
-
puts "#{mode.capitalize}ing #{environment.dup.yellow} environment, "\
|
29
|
-
"#{explanatory_text(filters, 'role')}, #{explanatory_text(filters, 'server')}"
|
30
|
-
|
31
|
-
actionable_roles.map { |role, instructions| threads(role, instructions) }.flatten.each(&:join)
|
32
|
-
|
33
|
-
puts mode == :deploy ? 'Finished deployment' : 'Deployment configuration check was successful'
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
5
|
+
require 'foreplay/engine/defaults'
|
6
|
+
require 'foreplay/engine/logger'
|
7
|
+
require 'foreplay/engine/port'
|
8
|
+
require 'foreplay/engine/remote'
|
9
|
+
require 'foreplay/engine/role'
|
10
|
+
require 'foreplay/engine/secrets'
|
11
|
+
require 'foreplay/engine/server'
|
12
|
+
require 'foreplay/engine/step'
|
13
|
+
|
14
|
+
module Foreplay
|
15
|
+
class Engine
|
16
|
+
include Foreplay::Engine::Defaults
|
17
|
+
attr_reader :mode, :environment, :filters
|
18
|
+
|
19
|
+
def initialize(e, f)
|
20
|
+
@environment = e
|
21
|
+
@filters = f
|
22
|
+
end
|
37
23
|
|
38
|
-
|
39
|
-
roles.select { |role, _i| role != DEFAULTS_KEY && role != filters['role'] }
|
40
|
-
end
|
24
|
+
[:deploy, :check].each { |m| define_method(m) { execute m } }
|
41
25
|
|
42
|
-
|
43
|
-
|
44
|
-
environment,
|
45
|
-
|
46
|
-
build_instructions(role, instructions)
|
47
|
-
).threads
|
48
|
-
end
|
26
|
+
def execute(m)
|
27
|
+
@mode = m
|
28
|
+
puts "#{mode.capitalize}ing #{environment.dup.yellow} environment, "\
|
29
|
+
"#{explanatory_text(filters, 'role')}, #{explanatory_text(filters, 'server')}"
|
49
30
|
|
50
|
-
|
51
|
-
hsh.key?(key) ? "#{hsh[key].dup.yellow} #{key}" : "all #{key}s"
|
52
|
-
end
|
31
|
+
actionable_roles.map { |role, instructions| threads(role, instructions) }.flatten.each(&:join)
|
53
32
|
|
54
|
-
|
55
|
-
instructions = defaults.supermerge(additional_instructions)
|
56
|
-
instructions['role'] = role
|
57
|
-
instructions['verbose'] = verbose
|
58
|
-
required_keys = %w(name environment role servers path repository)
|
59
|
-
|
60
|
-
required_keys.each do |key|
|
61
|
-
next if instructions.key? key
|
62
|
-
terminate("Required key #{key} not found in instructions for #{environment} environment.\nCheck #{config_file}")
|
33
|
+
puts mode == :deploy ? 'Finished deployment' : 'Deployment configuration check was successful'
|
63
34
|
end
|
64
35
|
|
65
|
-
|
66
|
-
instructions['servers'] &= server_filter if server_filter
|
67
|
-
instructions
|
68
|
-
end
|
69
|
-
|
70
|
-
def server_filter
|
71
|
-
@server_filter ||= filters['server'].split(',') if filters.key?('server')
|
72
|
-
end
|
73
|
-
|
74
|
-
def config_file
|
75
|
-
@config_file ||= (filters['config_file'] || DEFAULT_CONFIG_FILE)
|
76
|
-
end
|
36
|
+
private
|
77
37
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
# Establish defaults
|
82
|
-
# First the default defaults
|
83
|
-
@defaults = {
|
84
|
-
'name' => File.basename(Dir.getwd),
|
85
|
-
'environment' => environment,
|
86
|
-
'env' => { 'RAILS_ENV' => environment },
|
87
|
-
'port' => 50_000
|
88
|
-
}
|
89
|
-
|
90
|
-
@defaults['env'].merge! secrets
|
91
|
-
@defaults['application'] = secrets
|
92
|
-
@defaults = @defaults.supermerge(roles_all[DEFAULTS_KEY]) if roles_all.key? DEFAULTS_KEY
|
93
|
-
@defaults = @defaults.supermerge(roles[DEFAULTS_KEY]) if roles.key? DEFAULTS_KEY
|
94
|
-
@defaults
|
95
|
-
end
|
38
|
+
def actionable_roles
|
39
|
+
roles.select { |role, _i| role != DEFAULTS_KEY && (filters.key?('role') ? role == filters['role'] : true) }
|
40
|
+
end
|
96
41
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
42
|
+
def threads(role, instructions)
|
43
|
+
Foreplay::Engine::Role.new(
|
44
|
+
environment,
|
45
|
+
mode,
|
46
|
+
build_instructions(role, instructions)
|
47
|
+
).threads
|
48
|
+
end
|
101
49
|
|
102
|
-
|
103
|
-
|
104
|
-
|
50
|
+
def explanatory_text(hsh, key)
|
51
|
+
hsh.key?(key) ? "#{hsh[key].dup.yellow} #{key}" : "all #{key}s"
|
52
|
+
end
|
105
53
|
|
106
|
-
|
107
|
-
|
108
|
-
|
54
|
+
def build_instructions(role, additional_instructions)
|
55
|
+
instructions = defaults.supermerge(additional_instructions)
|
56
|
+
instructions['role'] = role
|
57
|
+
instructions['verbose'] = verbose
|
58
|
+
required_keys = %w(name environment role servers path repository)
|
109
59
|
|
110
|
-
|
111
|
-
|
60
|
+
required_keys.each do |key|
|
61
|
+
next if instructions.key? key
|
62
|
+
terminate("Required key #{key} not found in instructions for #{environment} environment.\nCheck #{config_file}")
|
63
|
+
end
|
112
64
|
|
113
|
-
|
65
|
+
# Apply server filter
|
66
|
+
instructions['servers'] &= server_filter if server_filter
|
67
|
+
instructions
|
68
|
+
end
|
114
69
|
|
115
|
-
|
116
|
-
|
117
|
-
terminate("No deployment configuration defined for #{environment} environment.\nCheck #{config_file}")
|
70
|
+
def server_filter
|
71
|
+
@server_filter ||= filters['server'].split(',') if filters.key?('server')
|
118
72
|
end
|
119
73
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
rescue Psych::SyntaxError
|
124
|
-
terminate "I don't understand the configuration file #{config_file}.\n"\
|
125
|
-
'Please run foreplay setup or edit the file manually.'
|
74
|
+
def verbose
|
75
|
+
@verbose ||= filters.key?('verbose')
|
76
|
+
end
|
126
77
|
end
|
127
78
|
end
|
data/lib/foreplay/launcher.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
require 'thor/group'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Foreplay
|
4
|
+
class Launcher < Thor::Group
|
5
|
+
include Thor::Actions
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
argument :mode, type: :string, required: true
|
8
|
+
argument :environment, type: :string, required: true
|
9
|
+
argument :filters, type: :hash, required: false
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
def parse
|
12
|
+
Foreplay::Engine.new(environment, filters).__send__ mode
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
data/lib/foreplay/setup.rb
CHANGED
@@ -1,31 +1,33 @@
|
|
1
1
|
require 'thor/group'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Foreplay
|
4
|
+
class Setup < Thor::Group
|
5
|
+
include Thor::Actions
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
7
|
+
class_option :name, aliases: '-n', default: File.basename(Dir.getwd)
|
8
|
+
class_option :repository, aliases: '-r'
|
9
|
+
class_option :user, aliases: '-u'
|
10
|
+
class_option :password
|
11
|
+
class_option :keyfile
|
12
|
+
class_option :private_key, aliases: '-k'
|
13
|
+
class_option :port, aliases: '-p', default: 50_000
|
14
|
+
class_option :path, aliases: '-f'
|
15
|
+
class_option :servers, aliases: '-s', type: :array
|
16
|
+
class_option :db_adapter, aliases: '-a', default: 'postgresql'
|
17
|
+
class_option :db_encoding, aliases: '-e', default: 'utf8'
|
18
|
+
class_option :db_pool, default: 5
|
19
|
+
class_option :db_name, aliases: '-d'
|
20
|
+
class_option :db_host, aliases: '-h'
|
21
|
+
class_option :db_user
|
22
|
+
class_option :db_password
|
23
|
+
class_option :resque_redis
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def self.source_root
|
26
|
+
File.dirname(__FILE__)
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
def config
|
30
|
+
template('setup/foreplay.yml', 'config/foreplay.yml')
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
data/lib/foreplay/version.rb
CHANGED
data/lib/foreplay.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
require 'foreplay/version'
|
2
|
-
require 'foreplay/foreplay'
|
3
|
-
require 'foreplay/launcher'
|
4
2
|
require 'foreplay/engine'
|
5
|
-
require 'foreplay/
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
require 'foreplay/launcher'
|
4
|
+
|
5
|
+
module Foreplay
|
6
|
+
DEFAULT_PORT = 50_000
|
7
|
+
PORT_GAP = 1_000
|
8
|
+
|
9
|
+
def log(message, options = {})
|
10
|
+
Foreplay::Engine::Logger.new(message, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def terminate(message)
|
14
|
+
fail message
|
15
|
+
end
|
16
|
+
end
|
@@ -137,9 +137,13 @@ describe Foreplay::Launcher do
|
|
137
137
|
'rvm rvmrc warning ignore 50000',
|
138
138
|
'gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys D39DC0E3',
|
139
139
|
'cd 50000 && mkdir -p tmp doc log config',
|
140
|
-
'rvm info',
|
140
|
+
'rvm rvmrc load && rvm info',
|
141
141
|
'if [ -f .ruby-version ] ; then rvm install `cat .ruby-version` ; else echo "No .ruby-version file found" ; fi',
|
142
|
-
'echo "
|
142
|
+
'echo "HOME=$HOME" > .env',
|
143
|
+
'echo "SHELL=$SHELL" >> .env',
|
144
|
+
'echo "PATH=$PATH:`which bundle`" >> .env',
|
145
|
+
'echo "GEM_HOME=$HOME/.rvm/gems/`rvm tools identifier`" >> .env',
|
146
|
+
'echo "RAILS_ENV=production" >> .env',
|
143
147
|
'echo "concurrency: web=1,worker=0,scheduler=0" > .foreman',
|
144
148
|
'echo "app: foreplay-50000" >> .foreman',
|
145
149
|
'echo "port: 50000" >> .foreman',
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreplay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xenapto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: foreman
|
@@ -218,10 +218,10 @@ files:
|
|
218
218
|
- features/setup.feature
|
219
219
|
- features/support/env.rb
|
220
220
|
- foreplay.gemspec
|
221
|
-
- foreplay.rake
|
222
221
|
- lib/foreplay.rb
|
223
222
|
- lib/foreplay/cli.rb
|
224
223
|
- lib/foreplay/engine.rb
|
224
|
+
- lib/foreplay/engine/defaults.rb
|
225
225
|
- lib/foreplay/engine/logger.rb
|
226
226
|
- lib/foreplay/engine/port.rb
|
227
227
|
- lib/foreplay/engine/remote.rb
|
@@ -232,7 +232,6 @@ files:
|
|
232
232
|
- lib/foreplay/engine/server.rb
|
233
233
|
- lib/foreplay/engine/step.rb
|
234
234
|
- lib/foreplay/engine/steps.yml
|
235
|
-
- lib/foreplay/foreplay.rb
|
236
235
|
- lib/foreplay/launcher.rb
|
237
236
|
- lib/foreplay/setup.rb
|
238
237
|
- lib/foreplay/setup/foreplay.yml
|
data/foreplay.rake
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# Syntax:
|
2
|
-
#
|
3
|
-
# rake ENV=production [ROLE=web] foreplay:command
|
4
|
-
#
|
5
|
-
# You can set the environment variables ENV and ROLE elsewhere if you wish.
|
6
|
-
# If ROLE is not defined then we deploy all roles.
|
7
|
-
#
|
8
|
-
# Dependencies:
|
9
|
-
#
|
10
|
-
# gem 'net-ssh-shell'
|
11
|
-
#
|
12
|
-
# You can constrain this to whatever group you use for initiating deployments, e.g.
|
13
|
-
#
|
14
|
-
# group :development do
|
15
|
-
# gem 'net-ssh-shell'
|
16
|
-
# end
|
17
|
-
|
18
|
-
namespace :foreplay do
|
19
|
-
desc 'Push app to deployment targets'
|
20
|
-
task push: :environment do
|
21
|
-
Foreplay.push
|
22
|
-
end
|
23
|
-
|
24
|
-
desc 'Check deployment configuration'
|
25
|
-
task check: :environment do
|
26
|
-
Foreplay.push true
|
27
|
-
end
|
28
|
-
end
|