script_executor 1.7.2 → 1.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +2 -2
- data/README.md +64 -2
- data/lib/script_executor/base_provision.rb +14 -15
- data/lib/script_executor/script_locator.rb +2 -0
- data/lib/script_executor/scripts_parser.rb +2 -2
- data/lib/script_executor/scripts_transformer.rb +4 -4
- data/lib/script_executor/version.rb +1 -1
- data/spec/base_provision_spec.rb +2 -6
- data/spec/script_locator_spec.rb +6 -6
- data/spec/scripts_parser_spec.rb +34 -3
- data/spec/support/base.conf.json +1 -1
- data/spec/support/{big_script.sh → script1.sh} +0 -0
- data/spec/support/{big_script2.sh → script2.sh} +0 -0
- data/spec/support/script3.sh +24 -0
- data/spec/support/{test.conf → script4.sh} +0 -0
- data/spec/support/{test2.conf → script5.sh} +0 -0
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0a0de62f31cf6ee86a7d9ae383d1e28fa4edacd
|
4
|
+
data.tar.gz: 154c990b179af68c7dfd41697d2c8165a1e2df62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f362a894b9185ee0297885933e1db9aa5ede241635b717466fba2cf850228a2c07b006435f8ffe14aaf04a58b1bcb9d7cfd15f10db12c2ad7a5d67f10902ae64
|
7
|
+
data.tar.gz: 0e1a3bbfaceed66e2d7d2837deefd431ec40f2dce54449f96822f7c6cb4c68a6625cf26a0ac95f471ec7bdd03ed222a83307b760fdf6012ec59a2ca6a4ae8d29
|
data/CHANGES
CHANGED
data/README.md
CHANGED
@@ -95,11 +95,11 @@ require 'script_locator'
|
|
95
95
|
|
96
96
|
include ScriptLocator
|
97
97
|
|
98
|
-
|
98
|
+
scripts = scripts(__FILE__) # [command1, command2]
|
99
99
|
|
100
100
|
name = "john"
|
101
101
|
|
102
|
-
result = evaluate_script_body(
|
102
|
+
result = evaluate_script_body(scripts[:command1][:code], binding)
|
103
103
|
|
104
104
|
puts result # john
|
105
105
|
__END__
|
@@ -113,7 +113,69 @@ echo "<%= name %>"
|
|
113
113
|
echo "test2"
|
114
114
|
```
|
115
115
|
|
116
|
+
## Using BaseProvision
|
117
|
+
|
118
|
+
- Create project configuration file:
|
119
|
+
|
120
|
+
```json
|
121
|
+
# base.conf.json
|
122
|
+
{
|
123
|
+
"node": {
|
124
|
+
"domain": "22.22.22.22", // remote host, see "config.vm.synced_folder"
|
125
|
+
"port": "22", // default ssh port
|
126
|
+
"user": "vagrant", // vagrant user name
|
127
|
+
"password": "vagrant", // vagrant user password
|
128
|
+
"home": "/home/vagrant",
|
129
|
+
"remote": true
|
130
|
+
},
|
131
|
+
|
132
|
+
"project": {
|
133
|
+
"home": "#{node.home}/acceptance_demo",
|
134
|
+
"ruby_version": "2.2.3",
|
135
|
+
"gemset": "acceptance_demo"
|
136
|
+
}
|
137
|
+
}
|
138
|
+
```
|
139
|
+
|
140
|
+
- Create file with shell commands:
|
141
|
+
|
142
|
+
```
|
143
|
+
# script.sh
|
144
|
+
|
145
|
+
|
146
|
+
[echo]
|
147
|
+
|
148
|
+
echo "Hello world!"
|
149
|
+
|
150
|
+
|
151
|
+
[ubuntu_update]
|
116
152
|
|
153
|
+
sudo apt-get update
|
154
|
+
```
|
155
|
+
|
156
|
+
- Create provision based on thor and use it:
|
157
|
+
|
158
|
+
```
|
159
|
+
# install.thor
|
160
|
+
|
161
|
+
class MyProvision < Thor
|
162
|
+
@provision = BaseProvision.new self, 'base.conf.json', ['script.sh']
|
163
|
+
@provision.create_thor_methods(self)
|
164
|
+
|
165
|
+
desc "local_command", "local_command"
|
166
|
+
def local_command
|
167
|
+
invoke :echo
|
168
|
+
invoke :ubuntu_update
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
my_provision = MyProvision.new
|
173
|
+
|
174
|
+
thor my_provision:echo
|
175
|
+
thor my_provision:ubuntu_update
|
176
|
+
|
177
|
+
thor my_provision:local_command
|
178
|
+
```
|
117
179
|
|
118
180
|
## Contributing
|
119
181
|
|
@@ -10,7 +10,8 @@ class BaseProvision
|
|
10
10
|
|
11
11
|
attr_reader :interpolator, :env, :script_list, :server_info
|
12
12
|
|
13
|
-
def initialize
|
13
|
+
def initialize config_file_name, scripts_file_names
|
14
|
+
@terminal = HighLine.new
|
14
15
|
@interpolator = TextInterpolator.new
|
15
16
|
|
16
17
|
@env = read_config(config_file_name)
|
@@ -21,18 +22,14 @@ class BaseProvision
|
|
21
22
|
@script_list.merge!(scripts(name))
|
22
23
|
end
|
23
24
|
|
24
|
-
create_script_methods
|
25
|
-
|
26
|
-
create_thor_methods(parent_class) if parent_class.ancestors.collect(&:to_s).include?('Thor')
|
27
|
-
|
28
25
|
@server_info = env[:node] ? env[:node] : {}
|
29
26
|
|
30
|
-
|
27
|
+
create_script_methods
|
31
28
|
end
|
32
29
|
|
33
30
|
def run script_name, params={}, type=:string
|
34
|
-
|
35
|
-
evaluate_script_body(script_list[script_name.to_sym][:
|
31
|
+
execute(server_info) do
|
32
|
+
evaluate_script_body(script_list[script_name.to_sym][:code], params, type)
|
36
33
|
end
|
37
34
|
end
|
38
35
|
|
@@ -59,17 +56,19 @@ class BaseProvision
|
|
59
56
|
end
|
60
57
|
|
61
58
|
def create_thor_methods parent_class
|
62
|
-
|
59
|
+
if parent_class.ancestors.collect(&:to_s).include?('Thor')
|
60
|
+
provision = self
|
63
61
|
|
64
|
-
|
65
|
-
|
62
|
+
provision.script_list.each do |name, value|
|
63
|
+
title = value[:comment]
|
66
64
|
|
67
|
-
|
65
|
+
title = title.nil? ? name : title
|
68
66
|
|
69
|
-
|
67
|
+
parent_class.send(:desc, name, title) if parent_class.respond_to?(:desc)
|
70
68
|
|
71
|
-
|
72
|
-
|
69
|
+
parent_class.send(:define_method, name.to_sym) do
|
70
|
+
provision.send "#{name}".to_sym
|
71
|
+
end
|
73
72
|
end
|
74
73
|
end
|
75
74
|
end
|
@@ -12,11 +12,11 @@ class ScriptsParser < Parslet::Parser
|
|
12
12
|
rule(:ignored) { comment.repeat }
|
13
13
|
rule(:scripts) { script.repeat }
|
14
14
|
|
15
|
-
rule(:script) { emptyLines >> (name >> comment.maybe >>
|
15
|
+
rule(:script) { emptyLines >> (name >> comment.maybe >> code).as(:script) }
|
16
16
|
rule(:comment) { emptyLines >> spaces >> (str('#') >> spaces >> (newline.absent? >> any).repeat.as(:comment)) >> newline }
|
17
17
|
rule(:name) { spaces >> str('[') >> spaces >> spaces >> nameChars.as(:name) >> spaces >> str(']') >> spaces >> newline }
|
18
18
|
|
19
|
-
rule(:
|
19
|
+
rule(:code) { (emptyLines >> codeLine.repeat.maybe >> emptyLines).as(:code) }
|
20
20
|
rule(:codeLine) { emptyLines >> codeChars.as(:codeLine) >> newline }
|
21
21
|
|
22
22
|
rule(:nameChars) { match['\w\d_'].repeat(1) }
|
@@ -9,13 +9,13 @@ class ScriptsTransformer < Parslet::Transform
|
|
9
9
|
language[:scripts].each do |script|
|
10
10
|
name = script[:script][:name].to_sym
|
11
11
|
comment = script[:script][:comment].to_s
|
12
|
-
|
12
|
+
code = script[:script][:code]
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
code.each_with_index do |codeLine, index|
|
15
|
+
code[index] = codeLine[:codeLine].to_s
|
16
16
|
end
|
17
17
|
|
18
|
-
new_scripts[name] = {comment: comment,
|
18
|
+
new_scripts[name] = {comment: comment, code: code}
|
19
19
|
end
|
20
20
|
|
21
21
|
language[:scripts] = new_scripts
|
data/spec/base_provision_spec.rb
CHANGED
@@ -3,14 +3,10 @@ require 'spec_helper'
|
|
3
3
|
require 'thor'
|
4
4
|
require 'script_executor/base_provision'
|
5
5
|
|
6
|
-
class ThorClass < Thor
|
7
|
-
|
8
|
-
end
|
6
|
+
class ThorClass < Thor; end
|
9
7
|
|
10
8
|
describe BaseProvision do
|
11
|
-
subject {
|
12
|
-
BaseProvision.new ThorClass, 'spec/support/base.conf.json', ['spec/support/big_script.sh']
|
13
|
-
}
|
9
|
+
subject { BaseProvision.new 'spec/support/base.conf.json', ['spec/support/script1.sh'] }
|
14
10
|
|
15
11
|
describe "#initialize" do
|
16
12
|
it "parses content from file" do
|
data/spec/script_locator_spec.rb
CHANGED
@@ -16,7 +16,7 @@ describe ScriptLocator do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "reads from file completely if it does not have __END__ tag" do
|
19
|
-
file = File.expand_path('support/
|
19
|
+
file = File.expand_path('support/script4.sh', File.dirname(__FILE__))
|
20
20
|
|
21
21
|
scripts = subject.scripts(file)
|
22
22
|
|
@@ -30,23 +30,23 @@ describe ScriptLocator do
|
|
30
30
|
|
31
31
|
name = "alisa"
|
32
32
|
|
33
|
-
result = subject.evaluate_script_body(scripts[:test1][:
|
33
|
+
result = subject.evaluate_script_body(scripts[:test1][:code], binding)
|
34
34
|
|
35
|
-
expect(result
|
35
|
+
expect(result).to match /#{name}/
|
36
36
|
|
37
37
|
expect(scripts[:test1][:comment]).to eq "Some description"
|
38
38
|
end
|
39
39
|
|
40
40
|
it "locates script inside external file and evaluates it as string" do
|
41
|
-
file = File.expand_path('support/
|
41
|
+
file = File.expand_path('support/script4.sh', File.dirname(__FILE__))
|
42
42
|
|
43
43
|
scripts = subject.scripts(file)
|
44
44
|
|
45
45
|
env = {:name => "alisa"}
|
46
46
|
|
47
|
-
result = subject.evaluate_script_body(scripts[:test1][:
|
47
|
+
result = subject.evaluate_script_body(scripts[:test1][:code], env, :string)
|
48
48
|
|
49
|
-
expect(result
|
49
|
+
expect(result).to match /#{env[:name]}/
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
data/spec/scripts_parser_spec.rb
CHANGED
@@ -5,9 +5,40 @@ require 'script_executor/scripts_transformer'
|
|
5
5
|
|
6
6
|
describe ScriptsParser do
|
7
7
|
describe "#parse" do
|
8
|
-
it "parses content from file" do
|
9
|
-
content = File.read('spec/support/
|
10
|
-
|
8
|
+
it "parses content from file 1" do
|
9
|
+
content = File.read('spec/support/script1.sh')
|
10
|
+
|
11
|
+
parsed_content = subject.parse(content)
|
12
|
+
|
13
|
+
ap parsed_content
|
14
|
+
end
|
15
|
+
|
16
|
+
it "parses content from file 2" do
|
17
|
+
content = File.read('spec/support/script2.sh')
|
18
|
+
|
19
|
+
parsed_content = subject.parse(content)
|
20
|
+
|
21
|
+
ap parsed_content
|
22
|
+
end
|
23
|
+
|
24
|
+
it "parses content from file 3" do
|
25
|
+
content = File.read('spec/support/script3.sh')
|
26
|
+
|
27
|
+
parsed_content = subject.parse(content)
|
28
|
+
|
29
|
+
ap parsed_content
|
30
|
+
end
|
31
|
+
|
32
|
+
it "parses content from file 4" do
|
33
|
+
content = File.read('spec/support/script4.sh')
|
34
|
+
|
35
|
+
parsed_content = subject.parse(content)
|
36
|
+
|
37
|
+
ap parsed_content
|
38
|
+
end
|
39
|
+
|
40
|
+
it "parses content from file 5" do
|
41
|
+
content = File.read('spec/support/script5.sh')
|
11
42
|
|
12
43
|
parsed_content = subject.parse(content)
|
13
44
|
|
data/spec/support/base.conf.json
CHANGED
File without changes
|
File without changes
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
[gen_key]
|
3
|
+
|
4
|
+
echo "Generating ssh key..."
|
5
|
+
|
6
|
+
cd ~/.ssh
|
7
|
+
ssh-keygen
|
8
|
+
|
9
|
+
[cp_key1]
|
10
|
+
|
11
|
+
echo "Copying public key to remote server..."
|
12
|
+
|
13
|
+
echo <%= user %>
|
14
|
+
echo <%= host %>
|
15
|
+
|
16
|
+
scp ~/.ssh/id_rsa.pub <%= user %>@<%= host %>:~/pubkey.txt
|
17
|
+
|
18
|
+
[cp_key2]
|
19
|
+
|
20
|
+
mkdir -p ~/.ssh
|
21
|
+
chmod 700 .ssh
|
22
|
+
cat pubkey.txt >> ~/.ssh/authorized_keys
|
23
|
+
rm ~/pubkey.txt
|
24
|
+
chmod 600 ~/.ssh/*
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: script_executor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Shvets
|
@@ -172,10 +172,11 @@ files:
|
|
172
172
|
- spec/scripts_parser_spec.rb
|
173
173
|
- spec/spec_helper.rb
|
174
174
|
- spec/support/base.conf.json
|
175
|
-
- spec/support/
|
176
|
-
- spec/support/
|
177
|
-
- spec/support/
|
178
|
-
- spec/support/
|
175
|
+
- spec/support/script1.sh
|
176
|
+
- spec/support/script2.sh
|
177
|
+
- spec/support/script3.sh
|
178
|
+
- spec/support/script4.sh
|
179
|
+
- spec/support/script5.sh
|
179
180
|
homepage: http://github.com/shvets/script_executor
|
180
181
|
licenses:
|
181
182
|
- MIT
|
@@ -207,7 +208,8 @@ test_files:
|
|
207
208
|
- spec/scripts_parser_spec.rb
|
208
209
|
- spec/spec_helper.rb
|
209
210
|
- spec/support/base.conf.json
|
210
|
-
- spec/support/
|
211
|
-
- spec/support/
|
212
|
-
- spec/support/
|
213
|
-
- spec/support/
|
211
|
+
- spec/support/script1.sh
|
212
|
+
- spec/support/script2.sh
|
213
|
+
- spec/support/script3.sh
|
214
|
+
- spec/support/script4.sh
|
215
|
+
- spec/support/script5.sh
|