singel 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/singel +3 -2
- data/lib/executor.rb +17 -31
- data/lib/orchestrator.rb +17 -10
- data/lib/template.rb +53 -0
- data/singel.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ee381a02993b614f5755e85d1f245423a4b0433
|
4
|
+
data.tar.gz: c42b7f3206eef7232508b63031fdbc39feed355f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0cbeb4027d312aa825eabfd05e1be3d0728b2f65ff2b4cf4c1b7b58bc49ad7c0e3902b77b45a0647a0e7da970152c640a1ef332351878c24545b47e860e9226
|
7
|
+
data.tar.gz: 0e54f2c167cb5b7452128995a1ed31254eddd99823d92edd993e1ca4c54363dbe0e2e9794b318c63ceeeb552be328a700f8e31fb4f008cf4c83a51f7be1aaa3d
|
data/bin/singel
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
# encoding: UTF-8
|
2
3
|
#
|
3
4
|
# Author:: Tim Smith (<tim@cozy.co>)
|
@@ -16,8 +17,7 @@
|
|
16
17
|
# See the License for the specific language governing permissions and
|
17
18
|
# limitations under the License.
|
18
19
|
|
19
|
-
|
20
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
20
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
21
21
|
|
22
22
|
begin
|
23
23
|
require 'optparse'
|
@@ -27,6 +27,7 @@ begin
|
|
27
27
|
require 'orchestrator.rb'
|
28
28
|
require 'executor.rb'
|
29
29
|
require 'uploader.rb'
|
30
|
+
require 'template.rb'
|
30
31
|
rescue LoadError => e
|
31
32
|
raise "Missing gem or lib #{e}"
|
32
33
|
end
|
data/lib/executor.rb
CHANGED
@@ -16,52 +16,38 @@
|
|
16
16
|
# See the License for the specific language governing permissions and
|
17
17
|
# limitations under the License.
|
18
18
|
|
19
|
-
# executes packer commands against template
|
20
|
-
class
|
21
|
-
def initialize(template)
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@
|
25
|
-
|
26
|
-
|
27
|
-
# shell out to packer to validate the config files for correctness
|
28
|
-
def validates?
|
29
|
-
Dir.chdir(@packer_dir)
|
30
|
-
`packer validate #{@file_path} 2>&1`
|
31
|
-
$CHILD_STATUS.success? ? true : false
|
32
|
-
end
|
33
|
-
|
34
|
-
# inspect the json file to determine the name and type of the builders
|
35
|
-
def parse_builders
|
36
|
-
template_file = File.read(@file_path)
|
37
|
-
template_json = JSON.parse(template_file)
|
38
|
-
template_json['builders'].each do |builder|
|
39
|
-
@builders[builder['name']] = builder['type']
|
40
|
-
end
|
41
|
-
rescue Errno::ENOENT
|
42
|
-
puts "- Could not find the passed template file #{@file_path}".indent.to_red
|
43
|
-
exit
|
19
|
+
# executes packer commands against template object
|
20
|
+
class PackerExecutor
|
21
|
+
def initialize(template, builders)
|
22
|
+
@template = template
|
23
|
+
@file_path = template.path
|
24
|
+
@template_builders = template.builders
|
25
|
+
@specified_builders = builders
|
44
26
|
end
|
45
27
|
|
46
28
|
# print out the builders for this template
|
47
29
|
def list
|
48
30
|
puts File.basename(@file_path, '.json') + ':'
|
49
|
-
|
50
|
-
|
31
|
+
|
32
|
+
builders = @template.builders_hash
|
33
|
+
if builders.empty?
|
51
34
|
puts '- No builders found'.indent.to_red
|
52
35
|
else
|
53
|
-
|
36
|
+
builders.each_pair do |name, type|
|
54
37
|
puts "- #{name} (type: #{type})".indent
|
55
38
|
end
|
56
39
|
end
|
57
40
|
end
|
58
41
|
|
42
|
+
# specify the builders if any were passed
|
43
|
+
def build_options
|
44
|
+
"-only=#{@specified_builders.join(',')}" unless @specified_builders.empty?
|
45
|
+
end
|
46
|
+
|
59
47
|
def build
|
60
48
|
puts "Building #{File.basename(@file_path, '.json')}:".to_green
|
61
|
-
IO.popen("packer build #{@file_path}") do |cmd|
|
49
|
+
IO.popen("packer build #{build_options} #{@file_path}") do |cmd|
|
62
50
|
cmd.each { |line| puts line }
|
63
51
|
end
|
64
|
-
|
65
|
-
SingelUploader.new(@file_path).push
|
66
52
|
end
|
67
53
|
end
|
data/lib/orchestrator.rb
CHANGED
@@ -38,7 +38,11 @@ class SingelOrchestrator
|
|
38
38
|
|
39
39
|
# check to make sure the packer dir exists
|
40
40
|
def check_dirs
|
41
|
-
|
41
|
+
unless Dir.exist?(@options[:packer_dir])
|
42
|
+
puts "#{@options[:packer_dir]} not present.".to_red
|
43
|
+
puts "See help for information on specifying an alternate dir.\n".to_red
|
44
|
+
exit!
|
45
|
+
end
|
42
46
|
end
|
43
47
|
|
44
48
|
# make a test connection using the AWS keys to determine if they're valid
|
@@ -47,7 +51,7 @@ class SingelOrchestrator
|
|
47
51
|
ec2.describe_instance_status
|
48
52
|
rescue
|
49
53
|
puts 'Could not connect to EC2. Check your local AWS credentials before continuing.'.to_red
|
50
|
-
exit
|
54
|
+
exit!
|
51
55
|
end
|
52
56
|
|
53
57
|
# check to make sure the prereq binaries present
|
@@ -56,39 +60,42 @@ class SingelOrchestrator
|
|
56
60
|
`which #{binary} 2>&1`
|
57
61
|
unless $CHILD_STATUS.success?
|
58
62
|
puts "Could not find #{name} binary #{binary}. You must install #{name} before continuing.".to_red unless $CHILD_STATUS
|
59
|
-
exit
|
63
|
+
exit!
|
60
64
|
end
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
64
68
|
# find the available packer templates on the host
|
65
69
|
def find_templates
|
70
|
+
# find packer templates on disk since none were passed via args
|
66
71
|
if @options[:templates].empty?
|
67
72
|
templates = []
|
68
73
|
Dir.foreach(@options[:packer_dir]) do |item|
|
69
74
|
templates << File.join(@options[:packer_dir], item) if File.extname(item).downcase == '.json'
|
70
75
|
end
|
71
76
|
|
77
|
+
# throw and error and exist if we still dont find any templates
|
72
78
|
if templates.empty?
|
73
79
|
puts "No packer templates found in the 'packer' dir. Cannot continue.".to_red
|
74
|
-
exit
|
80
|
+
exit!
|
75
81
|
end
|
76
82
|
templates
|
77
|
-
else
|
83
|
+
else # parse the arg provided template list
|
78
84
|
@options[:templates].map { |x| File.join(@options[:packer_dir], x) }
|
79
85
|
end
|
80
86
|
end
|
81
87
|
|
82
88
|
# run the passed command per packer template
|
83
89
|
def execute_command(cmd)
|
84
|
-
@templates.each do |
|
85
|
-
|
86
|
-
|
90
|
+
@templates.each do |t|
|
91
|
+
template = PackerTemplate.new(t)
|
92
|
+
executor = PackerExecutor.new(template, @options[:builders])
|
93
|
+
puts "Packer template validation for #{template.path} failed.\n".to_red unless template.validates?
|
87
94
|
begin
|
88
|
-
|
95
|
+
executor.send(cmd)
|
89
96
|
rescue NoMethodError
|
90
97
|
puts "Action \"#{cmd}\" not found. Cannot continue".to_red
|
91
|
-
exit
|
98
|
+
exit!
|
92
99
|
end
|
93
100
|
end
|
94
101
|
end
|
data/lib/template.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Author:: Tim Smith (<tim@cozy.co>)
|
4
|
+
# Copyright:: Copyright (c) 2014 Tim Smith
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
|
19
|
+
require 'json'
|
20
|
+
|
21
|
+
# instance of a single packer template with methods to validate and extract data
|
22
|
+
class PackerTemplate
|
23
|
+
attr_accessor :path, :name
|
24
|
+
|
25
|
+
def initialize(path)
|
26
|
+
@path = File.expand_path(path)
|
27
|
+
@name = File.basename(@path, '.json')
|
28
|
+
@file = File.read(path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def json
|
32
|
+
@parsed || @parsed = JSON.parse(@file)
|
33
|
+
end
|
34
|
+
|
35
|
+
def builders
|
36
|
+
json['builders'].map { |b| b['name'] }
|
37
|
+
end
|
38
|
+
|
39
|
+
def builders_hash
|
40
|
+
builders = {}
|
41
|
+
json['builders'].each do |builder|
|
42
|
+
builders[builder['name']] = builder['type']
|
43
|
+
end
|
44
|
+
builders
|
45
|
+
end
|
46
|
+
|
47
|
+
# shell out to packer to validate the config files for correctness
|
48
|
+
def validates?
|
49
|
+
Dir.chdir(File.dirname(@path))
|
50
|
+
`packer validate #{@path} 2>&1`
|
51
|
+
$CHILD_STATUS.success? ? true : false
|
52
|
+
end
|
53
|
+
end
|
data/singel.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: singel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-core
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- bin/singel
|
71
71
|
- lib/executor.rb
|
72
72
|
- lib/orchestrator.rb
|
73
|
+
- lib/template.rb
|
73
74
|
- lib/uploader.rb
|
74
75
|
- singel.gemspec
|
75
76
|
homepage: http://www.github.com/tas50/singel
|