soyuz 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.octopolo.yml +4 -0
- data/.soyuz.yml +13 -0
- data/CHANGELOG.markdown +11 -0
- data/README.md +18 -11
- data/lib/soyuz.rb +0 -1
- data/lib/soyuz/command.rb +3 -2
- data/lib/soyuz/command_choice.rb +3 -1
- data/lib/soyuz/config.rb +5 -17
- data/lib/soyuz/environment.rb +17 -2
- data/lib/soyuz/support.rb +27 -0
- data/lib/soyuz/version.rb +1 -1
- data/spec/files/soyuz_example.yml +3 -0
- data/spec/soyuz/command_choice_spec.rb +15 -1
- data/spec/soyuz/command_spec.rb +8 -0
- data/spec/soyuz/environment_spec.rb +21 -8
- data/spec/soyuz/support_spec.rb +73 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c53680db5dda2fb6c19772c76e4f59a657a2579f
|
4
|
+
data.tar.gz: 56cdcfb9e19379ba71cd46ed6c25bd8713191a43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfd38427d3133f9a1480a8bf02efa392586935cb535602fad61df3c0bfe0a45f53f3592b7da71bc660fc3220ee9c2c7fae6a91255932a4801cc80d3b4324aa42
|
7
|
+
data.tar.gz: d008cd34a69fd1f4fcb7b77027c95c87c84e816ea139adf734a47e1804db545220d325faf6bbac0913d73ddcb853a4ccabcdb8b54b75684a728d4f52badd8991
|
data/.octopolo.yml
ADDED
data/.soyuz.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
defaults:
|
2
|
+
deploy_cmd: gem push *.gem
|
3
|
+
before_deploy_cmds:
|
4
|
+
- op tag-release
|
5
|
+
- sed -i '' -e "s/\".*/\"$(git tag | tail -1 | sed s/v//)\"/" lib/soyuz/version.rb
|
6
|
+
- git add lib/soyuz/version.rb
|
7
|
+
- git commit -m "Version Bump" && git push
|
8
|
+
- gem build soyuz.gemspec
|
9
|
+
after_deploy_cmds:
|
10
|
+
- rm *.gem
|
11
|
+
environments:
|
12
|
+
-
|
13
|
+
rubygems: {}
|
data/CHANGELOG.markdown
ADDED
data/README.md
CHANGED
@@ -21,20 +21,22 @@ Or install it yourself as:
|
|
21
21
|
```yaml
|
22
22
|
# .soyuz.yml in the app you want to deploy with soyuz
|
23
23
|
defaults:
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
deploy_cmds:
|
25
|
+
- 'opsicle deploy $SOYUZ_ENVIRONMENT'
|
26
|
+
|
27
|
+
|
27
28
|
environments:
|
28
|
-
-
|
29
|
+
-
|
29
30
|
production:
|
30
|
-
|
31
|
-
-
|
32
|
-
display: "Deploy"
|
33
|
-
cmd: "cap $SOYUZ_ENVIRONMENT deploy:rolling"
|
31
|
+
deploy_cmds:
|
34
32
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
-
|
34
|
+
display: "Deploy"
|
35
|
+
cmd: "cap $SOYUZ_ENVIRONMENT deploy:rolling"
|
36
|
+
-
|
37
|
+
display: "Deploy with Migrations"
|
38
|
+
cmd: "cap $SOYUZ_ENVIRONMENT deploy:rolling_migrations"
|
39
|
+
|
38
40
|
before_deploy_cmds:
|
39
41
|
- accept-pull
|
40
42
|
- tag-release
|
@@ -69,6 +71,11 @@ post-deploy-notes
|
|
69
71
|
# post all of your deploy notes somewhere useful
|
70
72
|
```
|
71
73
|
|
74
|
+
## Deprications
|
75
|
+
|
76
|
+
`:deploy_cmd` has be depricated in favor of `:deploy_cmds` to better
|
77
|
+
match the before_deploy_cmds and after_deploy_cmds symantics
|
78
|
+
|
72
79
|
## Contributing
|
73
80
|
|
74
81
|
1. Fork it ( http://github.com/sportngin/soyuz/fork )
|
data/lib/soyuz.rb
CHANGED
data/lib/soyuz/command.rb
CHANGED
@@ -9,12 +9,13 @@ module Soyuz
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.build(cmd)
|
12
|
-
|
12
|
+
return if cmd.nil? || cmd.empty?
|
13
|
+
cmd.is_a?(Array) ? CommandChoice.new(cmd) : new(cmd)
|
13
14
|
end
|
14
15
|
|
15
16
|
def run
|
16
17
|
say("<%= color('executing [#{@cmd}]...', :green) %>")
|
17
|
-
system(@cmd)
|
18
|
+
exit(false) unless system(@cmd)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
data/lib/soyuz/command_choice.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require_relative "command"
|
2
|
+
|
2
3
|
module Soyuz
|
3
4
|
class CommandChoice
|
5
|
+
|
4
6
|
def initialize(choices)
|
5
7
|
raise ArgumentError, "Choices must be an array" unless choices.is_a?(Array)
|
6
8
|
@choices = choices
|
@@ -11,7 +13,7 @@ module Soyuz
|
|
11
13
|
say "#{index+1}) #{choice[:display]}"
|
12
14
|
end
|
13
15
|
choice = ask("? ", Integer) { |q| q.in = 1..@choices.length }
|
14
|
-
Command.
|
16
|
+
Command.build(@choices[choice-1][:cmd]).run
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
data/lib/soyuz/config.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
require 'safe_yaml'
|
2
2
|
require_relative 'environment'
|
3
|
+
require_relative 'support'
|
4
|
+
|
3
5
|
module Soyuz
|
4
6
|
class Config
|
7
|
+
include Soyuz::Support
|
8
|
+
|
5
9
|
def initialize(config_file)
|
6
10
|
@config_file = config_file
|
7
11
|
end
|
@@ -37,27 +41,11 @@ module Soyuz
|
|
37
41
|
def valid?
|
38
42
|
begin
|
39
43
|
File.exists?(@config_file) && config_data.is_a?(Hash)
|
44
|
+
environments.all?{|env| env.valid?}
|
40
45
|
rescue StandardError
|
41
46
|
false
|
42
47
|
end
|
43
48
|
end
|
44
|
-
|
45
|
-
def symbolize_keys(hash)
|
46
|
-
return hash unless hash.is_a?(Hash)
|
47
|
-
hash.inject({}){|result, (key, value)|
|
48
|
-
new_key = case key
|
49
|
-
when String then key.to_sym
|
50
|
-
else key
|
51
|
-
end
|
52
|
-
new_value = case value
|
53
|
-
when Hash then symbolize_keys(value)
|
54
|
-
when Array then value.map{|el| symbolize_keys(el) }
|
55
|
-
else value
|
56
|
-
end
|
57
|
-
result[new_key] = new_value
|
58
|
-
result
|
59
|
-
}
|
60
|
-
end
|
61
49
|
end
|
62
50
|
InvalidConfig = Class.new(StandardError)
|
63
51
|
end
|
data/lib/soyuz/environment.rb
CHANGED
@@ -1,11 +1,22 @@
|
|
1
1
|
require_relative 'command'
|
2
|
+
|
2
3
|
module Soyuz
|
3
4
|
class Environment
|
4
5
|
def initialize(attributes={}, defaults={})
|
5
6
|
set_attributes(attributes, defaults)
|
7
|
+
|
8
|
+
if [:deploy_cmds, :deploy_cmd].all?{ |attr| @attributes.has_key?(attr) }
|
9
|
+
raise ArgumentError, "Only one definiton of deploy_cmd or deploy_cmds is allowed"
|
10
|
+
end
|
11
|
+
|
6
12
|
build
|
7
13
|
end
|
8
14
|
|
15
|
+
def valid?
|
16
|
+
# If the environment built then it's valid
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
9
20
|
def before_callbacks
|
10
21
|
@before_callbacks.each do|cmd|
|
11
22
|
cmd.run
|
@@ -19,7 +30,9 @@ module Soyuz
|
|
19
30
|
end
|
20
31
|
|
21
32
|
def deploy
|
22
|
-
@
|
33
|
+
@deploy_cmds.each do |cmd|
|
34
|
+
cmd.run
|
35
|
+
end
|
23
36
|
end
|
24
37
|
|
25
38
|
def name
|
@@ -34,7 +47,9 @@ module Soyuz
|
|
34
47
|
end
|
35
48
|
|
36
49
|
def build
|
37
|
-
|
50
|
+
# deploy_cmd is deprecated and will be removed in a future version
|
51
|
+
@deploy_cmds = Array(Command.build(@attributes[:deploy_cmd]))
|
52
|
+
@deploy_cmds += Array(@attributes[:deploy_cmds]).compact.map{|cmd| Command.build(cmd) }
|
38
53
|
@before_callbacks = Array(@attributes[:before_deploy_cmds]).compact.map{|cmd| Command.build(cmd) }
|
39
54
|
@after_callbacks = Array(@attributes[:after_deploy_cmds]).compact.map{|cmd| Command.build(cmd) }
|
40
55
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Soyuz
|
2
|
+
module Support
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def symbolize_keys(objekt)
|
7
|
+
case objekt
|
8
|
+
when Hash then symbolize_hash(objekt)
|
9
|
+
when Array then symbolize_array(objekt)
|
10
|
+
else objekt
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def symbolize_hash(hash)
|
15
|
+
hash.inject({}) do |result, (key, value)|
|
16
|
+
new_key = key.to_sym rescue key
|
17
|
+
result[new_key] = symbolize_keys(value)
|
18
|
+
result
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def symbolize_array(array)
|
23
|
+
array.map {|val| symbolize_keys(val)}
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/soyuz/version.rb
CHANGED
@@ -15,13 +15,27 @@ module Soyuz
|
|
15
15
|
end
|
16
16
|
|
17
17
|
context "#run" do
|
18
|
+
|
18
19
|
it "creates a command for the given choice" do
|
19
20
|
expect(subject).to receive(:say).with("1) choice1").once
|
20
21
|
expect(subject).to receive(:say).with("2) choice2").once
|
21
22
|
expect(subject).to receive(:ask).with(instance_of(String), Integer).and_return(1).once
|
22
|
-
expect(Command).to receive(:
|
23
|
+
expect(Command).to receive(:build).with("echo choice1").and_return(command_double)
|
23
24
|
subject.run
|
24
25
|
end
|
26
|
+
|
27
|
+
context "Nested choices" do
|
28
|
+
let(:nested_choices) { [{display: "choice1.1", cmd: "echo choice1.1"}, {display: "choice1.2", cmd: "echo choice1.2" }] }
|
29
|
+
let(:choices){ [{display: "choice1", cmd: nested_choices }, {display: "choice2", cmd: "echo choice2" }] }
|
30
|
+
|
31
|
+
it "creates a command for the given choice" do
|
32
|
+
expect(subject).to receive(:say).with("1) choice1").once
|
33
|
+
expect(subject).to receive(:say).with("2) choice2").once
|
34
|
+
expect(subject).to receive(:ask).with(instance_of(String), Integer).and_return(1).once
|
35
|
+
expect(Command).to receive(:build).with(nested_choices).and_return(command_double)
|
36
|
+
subject.run
|
37
|
+
end
|
38
|
+
end
|
25
39
|
end
|
26
40
|
|
27
41
|
end
|
data/spec/soyuz/command_spec.rb
CHANGED
@@ -18,8 +18,16 @@ module Soyuz
|
|
18
18
|
end
|
19
19
|
|
20
20
|
context "#run" do
|
21
|
+
before(:each) { allow(subject).to receive(:say) }
|
22
|
+
|
21
23
|
it "to make a system call" do
|
24
|
+
expect(subject).to receive(:system).and_return(true)
|
25
|
+
subject.run
|
26
|
+
end
|
27
|
+
|
28
|
+
it "exits if the command returns a non-zero exist status" do
|
22
29
|
expect(subject).to receive(:system)
|
30
|
+
expect(subject).to receive(:exit)
|
23
31
|
subject.run
|
24
32
|
end
|
25
33
|
end
|
@@ -2,51 +2,64 @@ require 'spec_helper'
|
|
2
2
|
require 'soyuz/environment'
|
3
3
|
module Soyuz
|
4
4
|
describe Environment do
|
5
|
-
let(:attributes){ {environment: {
|
5
|
+
let(:attributes){ {environment: {deploy_cmds: ["echo herp", "echo blarg"], before_deploy_cmds: ['echo before', 'echo more before'], after_deploy_cmds: ['echo after', 'echo another after']}} }
|
6
6
|
subject{ Environment.new(attributes) }
|
7
7
|
let(:cmd){ double("Command") }
|
8
8
|
|
9
9
|
context ".new" do
|
10
|
+
|
10
11
|
subject{ Environment }
|
12
|
+
|
13
|
+
context "invalid deploy command" do
|
14
|
+
|
15
|
+
let(:attributes){ {environment: {deploy_cmd: "echo derp", deploy_cmds: ["echo herp", "echo blarg"], before_deploy_cmds: ['echo before', 'echo more before'], after_deploy_cmds: ['echo after', 'echo another after']}} }
|
16
|
+
|
17
|
+
it "Rasies an invalid configuration error if both deploy_cmd and deploy_cmds are defined" do
|
18
|
+
expect{ subject.new(attributes) }.to raise_error(ArgumentError)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
11
23
|
it "sets the environment name" do
|
12
24
|
expect(subject.name).to_not be_nil
|
13
25
|
subject.new(attributes)
|
14
26
|
end
|
15
|
-
it "sets the attributes" do
|
16
|
-
allow_any_instance_of(subject).to receive(:build)
|
17
|
-
expect_any_instance_of(subject).to receive(:set_attributes)
|
18
|
-
subject.new(attributes)
|
19
|
-
end
|
20
27
|
|
21
28
|
it "builds the environment" do
|
22
|
-
allow_any_instance_of(subject).to receive(:set_attributes)
|
23
29
|
expect_any_instance_of(subject).to receive(:build)
|
24
30
|
subject.new(attributes)
|
25
31
|
end
|
32
|
+
|
26
33
|
end
|
27
34
|
|
28
35
|
context "#deploy" do
|
36
|
+
|
29
37
|
it "runs the deploy command" do
|
30
38
|
allow(Command).to receive(:new).and_return(cmd)
|
31
|
-
expect(cmd).to receive(:run)
|
39
|
+
expect(cmd).to receive(:run).exactly(2).times
|
32
40
|
subject.deploy
|
33
41
|
end
|
42
|
+
|
34
43
|
end
|
35
44
|
|
36
45
|
context "#before_callbacks" do
|
46
|
+
|
37
47
|
it "runs all of the before callbacks" do
|
38
48
|
allow(Command).to receive(:new).and_return(cmd)
|
39
49
|
expect(cmd).to receive(:run).twice
|
40
50
|
subject.before_callbacks
|
41
51
|
end
|
52
|
+
|
42
53
|
end
|
43
54
|
|
44
55
|
context "#after_callbacks" do
|
56
|
+
|
45
57
|
it "runs all of the after callbacks" do
|
46
58
|
allow(Command).to receive(:new).and_return(cmd)
|
47
59
|
expect(cmd).to receive(:run).twice
|
48
60
|
subject.after_callbacks
|
49
61
|
end
|
62
|
+
|
50
63
|
end
|
51
64
|
end
|
52
65
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'soyuz/support'
|
3
|
+
|
4
|
+
describe Soyuz::Support do
|
5
|
+
|
6
|
+
let(:soyuz_class) { Class.new { include Soyuz::Support }.new }
|
7
|
+
|
8
|
+
describe "#symbolize_keys" do
|
9
|
+
context "for a hash" do
|
10
|
+
subject { {'foo' => 'bar'} }
|
11
|
+
|
12
|
+
it "converts all the keys to symbols" do
|
13
|
+
new_keys = soyuz_class.send(:symbolize_keys, subject).keys
|
14
|
+
expect(new_keys).to eq([:foo])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "for a hash with a hash for a value" do
|
19
|
+
subject { {'foo' => {'bar' => 'baz'}} }
|
20
|
+
|
21
|
+
it "converts all the keys nested in the array" do
|
22
|
+
value_keys = soyuz_class.send(:symbolize_keys, subject).values.first.keys
|
23
|
+
expect(value_keys).to eq([:bar])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "for a hash with an array for a value" do
|
28
|
+
subject { {'foo' => [{'bar' => 'baz'}]} }
|
29
|
+
|
30
|
+
it "converts all the keys nested in the array" do
|
31
|
+
array_keys = soyuz_class.send(:symbolize_keys, subject).values.first.first.keys
|
32
|
+
expect(array_keys).to eq([:bar])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "with a non-string/non-symbol key" do
|
37
|
+
subject { {1 => 2} }
|
38
|
+
|
39
|
+
it "does not convert the key" do
|
40
|
+
new_keys = soyuz_class.send(:symbolize_keys, subject).keys
|
41
|
+
expect(new_keys).to eq([1])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when a non-hash is passed in" do
|
46
|
+
subject { [1,2] }
|
47
|
+
|
48
|
+
it "does not convert the key" do
|
49
|
+
result = soyuz_class.send(:symbolize_keys, subject)
|
50
|
+
expect(result).to eq([1, 2])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with a hash nested in an array" do
|
55
|
+
subject { [{'foo' => 'bar'}] }
|
56
|
+
|
57
|
+
it "it converts the keys" do
|
58
|
+
result = soyuz_class.send(:symbolize_keys, subject)
|
59
|
+
expect(result).to eq([{:foo => 'bar'}])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "with a hash deeply nested in multiple arrays" do
|
64
|
+
subject { [[[{'foo' => 'bar'}]]] }
|
65
|
+
|
66
|
+
it "it converts the keys" do
|
67
|
+
result = soyuz_class.send(:symbolize_keys, subject)
|
68
|
+
expect(result).to eq([[[{:foo => 'bar'}]]])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soyuz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Fleener
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|
@@ -146,10 +146,13 @@ extensions: []
|
|
146
146
|
extra_rdoc_files: []
|
147
147
|
files:
|
148
148
|
- ".gitignore"
|
149
|
+
- ".octopolo.yml"
|
149
150
|
- ".rspec"
|
150
151
|
- ".ruby-gemset"
|
151
152
|
- ".ruby-version"
|
153
|
+
- ".soyuz.yml"
|
152
154
|
- ".travis.yml"
|
155
|
+
- CHANGELOG.markdown
|
153
156
|
- Gemfile
|
154
157
|
- Guardfile
|
155
158
|
- LICENSE.txt
|
@@ -162,6 +165,7 @@ files:
|
|
162
165
|
- lib/soyuz/config.rb
|
163
166
|
- lib/soyuz/deploy.rb
|
164
167
|
- lib/soyuz/environment.rb
|
168
|
+
- lib/soyuz/support.rb
|
165
169
|
- lib/soyuz/version.rb
|
166
170
|
- soyuz.gemspec
|
167
171
|
- spec/files/soyuz_example.yml
|
@@ -170,6 +174,7 @@ files:
|
|
170
174
|
- spec/soyuz/config_spec.rb
|
171
175
|
- spec/soyuz/deploy_spec.rb
|
172
176
|
- spec/soyuz/environment_spec.rb
|
177
|
+
- spec/soyuz/support_spec.rb
|
173
178
|
- spec/spec_helper.rb
|
174
179
|
homepage: https://github.com/sportngin/soyuz
|
175
180
|
licenses:
|
@@ -202,4 +207,5 @@ test_files:
|
|
202
207
|
- spec/soyuz/config_spec.rb
|
203
208
|
- spec/soyuz/deploy_spec.rb
|
204
209
|
- spec/soyuz/environment_spec.rb
|
210
|
+
- spec/soyuz/support_spec.rb
|
205
211
|
- spec/spec_helper.rb
|