vscripts 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +39 -2
- data/VERSION +1 -1
- data/lib/vscripts/aws/ec2.rb +13 -4
- data/lib/vscripts/aws/metadata.rb +2 -3
- data/lib/vscripts/command.rb +1 -0
- data/lib/vscripts/commands/identify.rb +169 -0
- data/lib/vscripts/commands/tags2facts.rb +18 -5
- data/lib/vscripts/util/local_system.rb +7 -0
- data/spec/vscripts/aws/ec2_spec.rb +9 -0
- data/spec/vscripts/commands/identify_spec.rb +111 -0
- data/spec/vscripts/commands/tags2facts_spec.rb +2 -1
- data/tasks/deploy.rake +29 -6
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f136dbab318d66e5849bc3fd0c919f705f3f4628
|
4
|
+
data.tar.gz: 1a8fc5ec87de153df9422c606b8bcb92e10a1d42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6102d72f4aaed7bf46c3bda322ec5f9d8a41b631c402da8572adde1ebde9b0e63ea51bf07971951a2bfc55b9ac7f0b90cb57d14f2a0e6c0375d9b5df25de3b58
|
7
|
+
data.tar.gz: e9d7926d647076d643f8d3f898d990298eb5f268d287335f0dfae69db2703ca3c030f2ba1a05669107355fac20f73e5740d9e5673330702b0159d682873928f6
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
Version 0.1.0
|
2
|
+
---
|
3
|
+
* Domain fallback to local ([Vlad Ghinea - c0d176f](https://github.com/vghn/vscripts/commit/c0d176fe244c10dd8d2b394075d5d6ef1c0ef332))
|
4
|
+
* Add EC2 region support ([Vlad Ghinea - 8bc9561](https://github.com/vghn/vscripts/commit/8bc956128ca6495392d553366ad34aa15b375afa))
|
5
|
+
* Fix JSON tags generation ([Vlad Ghinea - 0134d42](https://github.com/vghn/vscripts/commit/0134d421abb875a1e948927162606b8cfbd7ab43))
|
6
|
+
* Fix filtered tags hash ([Vlad Ghinea - 8f72637](https://github.com/vghn/vscripts/commit/8f72637a555d5f0535d1a87be6c50f36fb8ee181))
|
7
|
+
* Clean-up code ([Vlad Ghinea - 9d1d544](https://github.com/vghn/vscripts/commit/9d1d544eb8c824ab42e0c3cde5485846833b9af8))
|
8
|
+
* New tag query and creation functions ([Vlad Ghinea - 12f1ca0](https://github.com/vghn/vscripts/commit/12f1ca069fef78699c02b8818c8da299e024a785))
|
9
|
+
* Clean up code ([Vlad Ghinea - f7a9d16](https://github.com/vghn/vscripts/commit/f7a9d16eb69365b01365285dba4f9ec5052cae53))
|
10
|
+
* Add identify command ([Vlad Ghinea - eea3876](https://github.com/vghn/vscripts/commit/eea387656e36137f93b84a8437632f5ca1cbe17d))
|
11
|
+
* Update README ([Vlad Ghinea - 90dcf2e](https://github.com/vghn/vscripts/commit/90dcf2eda7640f4705e385e5df0d99abda81ec68))
|
12
|
+
* Add automated semantic versioning task ([Vlad Ghinea - 5b60e02](https://github.com/vghn/vscripts/commit/5b60e02d64588b1b09dfc3b5848e9ea1aada535e))
|
13
|
+
|
1
14
|
Version 0.0.3
|
2
15
|
---
|
3
16
|
* Fix command line ([Vlad - 78c776a](https://github.com/vghn/vscripts/commit/78c776ab75f4b4469a73fd08d083b43291b20db0))
|
data/README.md
CHANGED
@@ -52,8 +52,45 @@ can be overridden by adding `[-a|--all]` command line option.
|
|
52
52
|
|
53
53
|
> **EXAMPLES**:
|
54
54
|
```
|
55
|
-
$ vscripts tags2facts
|
56
|
-
$ vscripts tags2facts --file /tmp/my_tags.json --all
|
55
|
+
$ vscripts tags2facts
|
56
|
+
$ vscripts tags2facts --file /tmp/my_tags.json --all
|
57
|
+
```
|
58
|
+
|
59
|
+
2. **identify**
|
60
|
+
This command creates a themed host name and fully qualified domain name for
|
61
|
+
the server, using AWS EC2 tags. The default theme is `Group-Role-#` which means
|
62
|
+
that the command collects the value of the `Group` and the `Role` AWS EC2 tags
|
63
|
+
(if they are associated with the instance). Additionally, the value of the
|
64
|
+
`Domain` tag is also collected so the resulting new host name will be
|
65
|
+
`MYGROUP-MYROLE-#.MYDOMAIN`.
|
66
|
+
These tags can be any existing EC2 tags. `#` is used as a placeholder for a
|
67
|
+
number. This number starts at 1, and, in case other similarly named instances
|
68
|
+
exist in the current AWS account, it will be incremented accordingly.
|
69
|
+
Once a new host name is composed, both `/etc/hostname` and `/etc/hosts` are
|
70
|
+
modified on the local instance and a new `Name` EC2 tag is created and
|
71
|
+
associated with the current instance.
|
72
|
+
|
73
|
+
If a ***--host*** argument is provided it will override the default theme.
|
74
|
+
*DOMAIN* is still looked up.
|
75
|
+
If a ***--domain*** argument is provided it will override the default
|
76
|
+
domain.
|
77
|
+
|
78
|
+
> Options:
|
79
|
+
> ```
|
80
|
+
--ec2-tag-theme, -e <s>: Theme (default: Group-Role-#)
|
81
|
+
--host, -n <s>: Host name
|
82
|
+
--domain, -d <s>: Domain
|
83
|
+
--help, -h: Shows help
|
84
|
+
```
|
85
|
+
|
86
|
+
> EXAMPLES:
|
87
|
+
```
|
88
|
+
$ vscripts identify
|
89
|
+
MyGroup-MyRole-1.Example.tld
|
90
|
+
$ vscripts identify --ec2-tag-theme NAME-#
|
91
|
+
MyName-1.Example.tld
|
92
|
+
$ vscripts identify --host myhost --domain example.com
|
93
|
+
myhost.example.com
|
57
94
|
```
|
58
95
|
|
59
96
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/vscripts/aws/ec2.rb
CHANGED
@@ -12,7 +12,7 @@ module VScripts
|
|
12
12
|
|
13
13
|
# Load AWS SDK for EC2
|
14
14
|
def initialize
|
15
|
-
@ec2 ||= ::AWS::EC2.new
|
15
|
+
@ec2 ||= ::AWS::EC2.new(region: region)
|
16
16
|
end
|
17
17
|
|
18
18
|
# @return [AWS::EC2]
|
@@ -29,6 +29,16 @@ module VScripts
|
|
29
29
|
instance.tags
|
30
30
|
end
|
31
31
|
|
32
|
+
# @return [AWS::EC2::ResourceTagCollection] Tags collection
|
33
|
+
def tag(key)
|
34
|
+
instance.tags[key]
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [AWS::EC2::Tag] Creates an EC2 Tag
|
38
|
+
def create_tag(resource, key, value)
|
39
|
+
ec2.tags.create(resource, key, value)
|
40
|
+
end
|
41
|
+
|
32
42
|
# Get a list of tags
|
33
43
|
def tags_without(list = [])
|
34
44
|
all = all_tags
|
@@ -59,9 +69,8 @@ module VScripts
|
|
59
69
|
def similar_instances
|
60
70
|
check_instance
|
61
71
|
functional_instances.map do |functional_instance|
|
62
|
-
if functional_instance.id
|
63
|
-
|
64
|
-
end
|
72
|
+
next if functional_instance.id == instance_id
|
73
|
+
functional_instance.tags['Name']
|
65
74
|
end
|
66
75
|
end
|
67
76
|
end # class EC2
|
@@ -41,9 +41,8 @@ module VScripts
|
|
41
41
|
|
42
42
|
# Fail if the current instance is not an EC2 instance
|
43
43
|
def check_instance
|
44
|
-
|
45
|
-
|
46
|
-
end
|
44
|
+
return if ec2_instance?
|
45
|
+
abort 'FATAL: NOT an EC2 instance or could not connect to Metadata'
|
47
46
|
end
|
48
47
|
end # module Metadata
|
49
48
|
end # module AWS
|
data/lib/vscripts/command.rb
CHANGED
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'trollop'
|
2
|
+
require 'vscripts/aws/ec2'
|
3
|
+
require 'vscripts/util/local_system'
|
4
|
+
|
5
|
+
module VScripts
|
6
|
+
# Commands module
|
7
|
+
module Commands
|
8
|
+
# @ec2 smells of :reek:UncommunicativeVariableName
|
9
|
+
|
10
|
+
# Identify Class
|
11
|
+
class Identify # rubocop:disable ClassLength
|
12
|
+
include VScripts::Util::LocalSystem
|
13
|
+
|
14
|
+
# HELP
|
15
|
+
USAGE = <<-EOS
|
16
|
+
This command creates a themed host name and fully qualified domain name for
|
17
|
+
the server, using AWS EC2 tags. The default theme is `Group-Role-#` which means
|
18
|
+
that the command collects the value of the `Group` and the `Role` AWS EC2 tags
|
19
|
+
(if they are associated with the instance). Additionally, the value of the
|
20
|
+
`Domain` tag is also collected so the resulting new host name will be
|
21
|
+
`MYGROUP-MYROLE-#.MYDOMAIN`.
|
22
|
+
These tags can be any existing EC2 tags. `#` is used as a placeholder for a
|
23
|
+
number. This number starts at 1, and, in case other similarly named instances
|
24
|
+
exist in the current AWS account, it will be incremented accordingly.
|
25
|
+
Once a new host name is composed, both `/etc/hostname` and `/etc/hosts` are
|
26
|
+
modified on the local instance and a new `Name` EC2 tag is created and
|
27
|
+
associated with the current instance.
|
28
|
+
|
29
|
+
If a ***--host*** argument is provided it will override the default theme.
|
30
|
+
*DOMAIN* is still looked up.
|
31
|
+
If a ***--domain*** argument is provided it will override the default
|
32
|
+
domain.
|
33
|
+
|
34
|
+
EXAMPLES:
|
35
|
+
$ vscripts identify
|
36
|
+
MyGroup-MyRole-1.Example.tld
|
37
|
+
$ vscripts identify --ec2-tag-theme NAME-#
|
38
|
+
MyName-1.Example.tld`
|
39
|
+
$ vscripts identify --host myhost --domain example.com
|
40
|
+
myhost.example.com`
|
41
|
+
|
42
|
+
Options:
|
43
|
+
EOS
|
44
|
+
|
45
|
+
# @return [AWS::EC2] EC2 SDK
|
46
|
+
attr_reader :ec2
|
47
|
+
# @return [String] Theme string
|
48
|
+
attr_reader :theme
|
49
|
+
# @return [String] Host name
|
50
|
+
attr_reader :host
|
51
|
+
# @return [String] Domain name
|
52
|
+
attr_reader :domain
|
53
|
+
# @return [Array] Command specific arguments
|
54
|
+
attr_reader :arguments
|
55
|
+
|
56
|
+
def initialize(argv = [])
|
57
|
+
@arguments ||= argv
|
58
|
+
@theme ||= cli.ec2_tag_theme
|
59
|
+
@host ||= cli.host
|
60
|
+
@domain ||= cli.domain
|
61
|
+
end
|
62
|
+
|
63
|
+
# Specifies command line options
|
64
|
+
# This method smells of :reek:TooManyStatements but ignores them
|
65
|
+
def parser
|
66
|
+
Trollop::Parser.new do
|
67
|
+
banner USAGE
|
68
|
+
opt :ec2_tag_theme, 'Theme (default: Group-Role-#)',
|
69
|
+
type: :string, default: 'Group-Role-#', short: '-t'
|
70
|
+
opt :host, 'Host name', type: :string, short: '-n'
|
71
|
+
opt :domain, 'Domain name', type: :string, short: '-d'
|
72
|
+
stop_on_unknown
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Parses command line arguments
|
77
|
+
def cli
|
78
|
+
@cli ||= Trollop.with_standard_exception_handling parser do
|
79
|
+
parser.parse arguments
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Loads AWS::EC2
|
84
|
+
# This method smells of :reek:UncommunicativeMethodName but ignores it
|
85
|
+
def ec2
|
86
|
+
@ec2 ||= VScripts::AWS::EC2.new
|
87
|
+
end
|
88
|
+
|
89
|
+
# @return [Array] Splits theme into elements
|
90
|
+
def theme_elements
|
91
|
+
theme.split('-')
|
92
|
+
end
|
93
|
+
|
94
|
+
# @return [Array] An array of values for each tag specified in the theme
|
95
|
+
def map2tags
|
96
|
+
theme_elements.map do |element|
|
97
|
+
element == '#' ? element : ec2.tag(element)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# @return [String] Compose host name based on found tags
|
102
|
+
def themed_host_name
|
103
|
+
map2tags.compact.join('-')
|
104
|
+
end
|
105
|
+
|
106
|
+
# @return [String] The incremented host name
|
107
|
+
def incremented_hostname
|
108
|
+
number = 1
|
109
|
+
while ec2.similar_instances.include? "#{themed_host_name}.#{domain}"
|
110
|
+
.sub(/#/, "#{number}")
|
111
|
+
number += 1
|
112
|
+
end
|
113
|
+
"#{themed_host_name}".sub(/#/, "#{number}")
|
114
|
+
end
|
115
|
+
|
116
|
+
# @return [String] The command line --host argument or the themed hostname
|
117
|
+
def new_hostname
|
118
|
+
host || incremented_hostname || local_host_name
|
119
|
+
end
|
120
|
+
|
121
|
+
# @return [String] The value of the command line --domain argument, or the
|
122
|
+
# value of the 'Domain' EC2 tag or the local domain name.
|
123
|
+
def new_domain
|
124
|
+
domain || ec2.tag('Domain') || local_domain_name
|
125
|
+
end
|
126
|
+
|
127
|
+
# @return [String] The fully qualified domain name
|
128
|
+
def new_fqdn
|
129
|
+
"#{new_hostname}.#{new_domain}"
|
130
|
+
end
|
131
|
+
|
132
|
+
# Modify the 'Name' tag
|
133
|
+
def set_name_tag
|
134
|
+
return if ec2.tag('Name') == new_fqdn
|
135
|
+
puts "Setting name tag to \"#{new_fqdn}\"..."
|
136
|
+
ec2.create_tag(ec2.instance, 'Name', value: new_fqdn)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Modify the host name
|
140
|
+
def set_hostname
|
141
|
+
return if File.read(hostname_path).strip == new_hostname
|
142
|
+
puts "Setting local hostname (#{new_hostname})..."
|
143
|
+
write_file(hostname_path, new_hostname)
|
144
|
+
`hostname -F /etc/hostname`
|
145
|
+
end
|
146
|
+
|
147
|
+
# Modify the hosts file
|
148
|
+
def update_hosts
|
149
|
+
return if File.readlines(hosts_path)
|
150
|
+
.grep(/#{new_fqdn} #{new_hostname}/)
|
151
|
+
.any?
|
152
|
+
hosts_body = hosts_file.gsub(
|
153
|
+
/^127\.0\.0\.1.*/,
|
154
|
+
"127\.0\.0\.1 #{new_fqdn} #{new_hostname} localhost"
|
155
|
+
)
|
156
|
+
puts "Adding \"#{new_fqdn}\" to #{hosts_path}..."
|
157
|
+
write_file(hosts_path, hosts_body)
|
158
|
+
end
|
159
|
+
|
160
|
+
# Executes the command
|
161
|
+
def execute
|
162
|
+
set_name_tag
|
163
|
+
set_hostname
|
164
|
+
update_hosts
|
165
|
+
puts 'Done.'
|
166
|
+
end
|
167
|
+
end # class Identify
|
168
|
+
end # module Commands
|
169
|
+
end # module VScripts
|
@@ -36,7 +36,6 @@ module VScripts
|
|
36
36
|
|
37
37
|
def initialize(argv = [])
|
38
38
|
@arguments ||= argv
|
39
|
-
@ec2 ||= VScripts::AWS::EC2.new
|
40
39
|
end
|
41
40
|
|
42
41
|
# Specifies command line options
|
@@ -50,6 +49,12 @@ module VScripts
|
|
50
49
|
end
|
51
50
|
end
|
52
51
|
|
52
|
+
# Loads AWS EC2
|
53
|
+
# This method smells of :reek:UncommunicativeMethodName but ignores it
|
54
|
+
def ec2
|
55
|
+
@ec2 ||= VScripts::AWS::EC2.new
|
56
|
+
end
|
57
|
+
|
53
58
|
# Parses command line arguments
|
54
59
|
def cli
|
55
60
|
@cli ||= Trollop.with_standard_exception_handling parser do
|
@@ -62,14 +67,22 @@ module VScripts
|
|
62
67
|
cli.all ? [] : %w(Name Domain)
|
63
68
|
end
|
64
69
|
|
65
|
-
# @return [Hash]
|
66
|
-
def
|
67
|
-
ec2.tags_without(exclude_list).
|
70
|
+
# @return [Hash] Filtered tags
|
71
|
+
def filtered_tags
|
72
|
+
ec2.tags_without(exclude_list).each_with_object({}) do |tag, hash|
|
73
|
+
hash[tag[0]] = tag[1]
|
74
|
+
hash
|
75
|
+
end
|
68
76
|
end
|
69
77
|
|
70
78
|
# @return [JSON] Formatted JSON
|
71
79
|
def tags_json
|
72
|
-
|
80
|
+
tags_hash = filtered_tags
|
81
|
+
if tags_hash.empty?
|
82
|
+
abort 'No tags were found!'
|
83
|
+
else
|
84
|
+
JSON.pretty_generate(tags_hash)
|
85
|
+
end
|
73
86
|
end
|
74
87
|
|
75
88
|
# Writes the formatted JSON to a file
|
@@ -11,6 +11,11 @@ module VScripts
|
|
11
11
|
'/etc/hosts'
|
12
12
|
end
|
13
13
|
|
14
|
+
# @return[String] The contents of the hosts file
|
15
|
+
def hosts_file
|
16
|
+
File.read(hosts_path)
|
17
|
+
end
|
18
|
+
|
14
19
|
# Hostname file path
|
15
20
|
def hostname_path
|
16
21
|
'/etc/hostname'
|
@@ -29,6 +34,8 @@ module VScripts
|
|
29
34
|
# Returns the local domain name
|
30
35
|
def local_domain_name
|
31
36
|
`dnsdomainname`.strip
|
37
|
+
rescue
|
38
|
+
'local'
|
32
39
|
end
|
33
40
|
|
34
41
|
# Tries to get the reverse dns
|
@@ -21,6 +21,7 @@ describe VScripts::AWS::EC2 do
|
|
21
21
|
@ec2 = VScripts::AWS::EC2
|
22
22
|
@ec2.any_instance.stub(:check_instance) { true }
|
23
23
|
@ec2.any_instance.stub(:instance_id) { @inst1.id }
|
24
|
+
@ec2.any_instance.stub(:region) { 'us-east-1' }
|
24
25
|
end
|
25
26
|
|
26
27
|
describe '#instance' do
|
@@ -43,6 +44,14 @@ describe VScripts::AWS::EC2 do
|
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
47
|
+
describe '#tag' do
|
48
|
+
it 'returns the tag value' do
|
49
|
+
subject.stub_chain(:instance, :tags) {@tags}
|
50
|
+
expect(subject.tag('Name'))
|
51
|
+
.to eq('test')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
46
55
|
describe '#tags_without' do
|
47
56
|
it 'returns a Hash' do
|
48
57
|
expect(subject.tags_without)
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'vscripts/commands/identify'
|
3
|
+
|
4
|
+
describe VScripts::Commands::Identify do
|
5
|
+
before :each do
|
6
|
+
@identify = VScripts::Commands::Identify.new
|
7
|
+
@identify.stub_chain(:ec2, :tag).with('Group') {'TestGroup'}
|
8
|
+
@identify.stub_chain(:ec2, :tag).with('Role') {'TestRole'}
|
9
|
+
@identify.stub_chain(:ec2, :similar_instances) {[
|
10
|
+
'TestGroup-TestRole-1.'
|
11
|
+
]}
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#new' do
|
15
|
+
context 'when theme is not passed' do
|
16
|
+
it 'returns the default theme' do
|
17
|
+
expect(@identify.theme).to eq('Group-Role-#')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
context 'when theme is passed' do
|
21
|
+
it 'returns the theme' do
|
22
|
+
@identify = VScripts::Commands::Identify.new(['--ec2-tag-theme=test'])
|
23
|
+
expect(@identify.theme).to eq('test')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
context 'when host is not passed' do
|
27
|
+
it 'host is nil' do
|
28
|
+
expect(@identify.host).to be_nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
context 'when host is passed' do
|
32
|
+
it 'returns the host' do
|
33
|
+
@identify = VScripts::Commands::Identify.new(['--host=test'])
|
34
|
+
expect(@identify.host).to eq('test')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
context 'when domain is not passed' do
|
38
|
+
it 'domain is nil' do
|
39
|
+
expect(@identify.domain).to be_nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
context 'when domain is passed' do
|
43
|
+
it 'returns the domain' do
|
44
|
+
@identify = VScripts::Commands::Identify.new(['--domain=test'])
|
45
|
+
expect(@identify.domain).to eq('test')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#theme_elements' do
|
51
|
+
it 'returns an array' do
|
52
|
+
expect(@identify.theme_elements).to eq(['Group', 'Role', '#'])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#map2tags' do
|
57
|
+
it 'returns an array' do
|
58
|
+
expect(@identify.map2tags).to eq(['TestGroup', 'TestRole', '#'])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#themed_host_name' do
|
63
|
+
it 'returns a string' do
|
64
|
+
expect(@identify.themed_host_name).to eq('TestGroup-TestRole-#')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#incremented_hostname' do
|
69
|
+
it 'returns a string' do
|
70
|
+
expect(@identify.incremented_hostname).to eq('TestGroup-TestRole-2')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#new_hostname' do
|
75
|
+
context 'when host is not passed' do
|
76
|
+
it 'hostname is incremented' do
|
77
|
+
expect(@identify.new_hostname).to eq('TestGroup-TestRole-2')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
context 'when host is passed' do
|
81
|
+
it 'returns a string' do
|
82
|
+
@identify = VScripts::Commands::Identify.new(['--host=test'])
|
83
|
+
expect(@identify.new_hostname).to eq('test')
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#new_domain' do
|
89
|
+
context 'when domain is not passed' do
|
90
|
+
context 'when tag is not present' do
|
91
|
+
it 'returns a String' do
|
92
|
+
@identify.stub_chain(:ec2, :tag).with('Domain') {nil}
|
93
|
+
@identify.stub(:local_domain_name) {'local'}
|
94
|
+
expect(@identify.new_domain).to eq('local')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
context 'when tag is present' do
|
98
|
+
it 'returns a String' do
|
99
|
+
@identify.stub_chain(:ec2, :tag).with('Domain') {'Test'}
|
100
|
+
expect(@identify.new_domain).to eq('Test')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
context 'when domain is passed' do
|
105
|
+
it 'returns a string' do
|
106
|
+
@identify = VScripts::Commands::Identify.new(['--domain=test'])
|
107
|
+
expect(@identify.new_domain).to eq('test')
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -3,6 +3,7 @@ require 'vscripts/commands/tags2facts'
|
|
3
3
|
describe VScripts::Commands::Tags2facts do
|
4
4
|
|
5
5
|
before :each do
|
6
|
+
VScripts::AWS::EC2.any_instance.stub(:region) { 'us-east-1' }
|
6
7
|
@tags2facts = VScripts::Commands::Tags2facts.new(['extra_args'])
|
7
8
|
end
|
8
9
|
|
@@ -27,7 +28,7 @@ describe VScripts::Commands::Tags2facts do
|
|
27
28
|
|
28
29
|
describe '#tags_json' do
|
29
30
|
it 'returns JSON formatted string' do
|
30
|
-
@tags2facts.
|
31
|
+
@tags2facts.stub(:filtered_tags) {{ key: 'value' }}
|
31
32
|
expect(@tags2facts.tags_json).to eq("{\n \"key\": \"value\"\n}")
|
32
33
|
end
|
33
34
|
end
|
data/tasks/deploy.rake
CHANGED
@@ -3,9 +3,25 @@ LOG_RANGE = "master...#{DEV_BRANCH}"
|
|
3
3
|
VERSION_FILE = 'VERSION'
|
4
4
|
CHANGELOG_FILE = 'CHANGELOG.md'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
namespace 'deploy' do
|
7
|
+
desc 'Automated deployment (increment patch)'
|
8
|
+
task :patch do
|
9
|
+
bump_version('patch')
|
10
|
+
deploy
|
11
|
+
end
|
12
|
+
desc 'Automated deployment (increment minor)'
|
13
|
+
task :minor do
|
14
|
+
bump_version('minor')
|
15
|
+
deploy
|
16
|
+
end
|
17
|
+
desc 'Automated deployment (increment major)'
|
18
|
+
task :major do
|
19
|
+
bump_version('major')
|
20
|
+
deploy
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def deploy
|
9
25
|
commit_changelog
|
10
26
|
merge_changes
|
11
27
|
push_release
|
@@ -21,12 +37,20 @@ def check_branch
|
|
21
37
|
`git fetch`
|
22
38
|
end
|
23
39
|
|
24
|
-
def bump_version
|
40
|
+
def bump_version(type = 'patch')
|
41
|
+
check_branch
|
25
42
|
@version = File.read(VERSION_FILE).strip
|
26
43
|
@version.gsub(/(\d+)\.(\d+)\.(\d+)/) {
|
27
44
|
@major, @minor, @patch = $1.to_i, $2.to_i, $3.to_i
|
28
45
|
}
|
29
|
-
|
46
|
+
case type
|
47
|
+
when 'patch'
|
48
|
+
@new_version = "#{@major}.#{@minor}.#{@patch + 1}"
|
49
|
+
when 'minor'
|
50
|
+
@new_version = "#{@major}.#{@minor + 1}.0"
|
51
|
+
when 'major'
|
52
|
+
@new_version = "#{@major + 1}.0.0"
|
53
|
+
end
|
30
54
|
File.write('VERSION', @new_version)
|
31
55
|
end
|
32
56
|
|
@@ -43,7 +67,6 @@ def pretty_changes
|
|
43
67
|
end
|
44
68
|
|
45
69
|
def update_changelog
|
46
|
-
bump_version
|
47
70
|
puts 'Writing new changelog'
|
48
71
|
File.write(
|
49
72
|
CHANGELOG_FILE,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vscripts
|
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
|
- Vlad Ghinea
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -216,6 +216,7 @@ files:
|
|
216
216
|
- lib/vscripts/aws/metadata.rb
|
217
217
|
- lib/vscripts/command.rb
|
218
218
|
- lib/vscripts/command_line.rb
|
219
|
+
- lib/vscripts/commands/identify.rb
|
219
220
|
- lib/vscripts/commands/tags2facts.rb
|
220
221
|
- lib/vscripts/util/local_system.rb
|
221
222
|
- lib/vscripts/version.rb
|
@@ -225,6 +226,7 @@ files:
|
|
225
226
|
- spec/vscripts/aws_spec.rb
|
226
227
|
- spec/vscripts/command_line_spec.rb
|
227
228
|
- spec/vscripts/command_spec.rb
|
229
|
+
- spec/vscripts/commands/identify_spec.rb
|
228
230
|
- spec/vscripts/commands/tags2facts_spec.rb
|
229
231
|
- spec/vscripts/util/local_system_spec.rb
|
230
232
|
- spec/vscripts/version_spec.rb
|
@@ -263,6 +265,7 @@ test_files:
|
|
263
265
|
- spec/vscripts/aws_spec.rb
|
264
266
|
- spec/vscripts/command_line_spec.rb
|
265
267
|
- spec/vscripts/command_spec.rb
|
268
|
+
- spec/vscripts/commands/identify_spec.rb
|
266
269
|
- spec/vscripts/commands/tags2facts_spec.rb
|
267
270
|
- spec/vscripts/util/local_system_spec.rb
|
268
271
|
- spec/vscripts/version_spec.rb
|