singel 0.0.2 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e82274c305c1b24a5b34ca59c4a0a3b1dfa0f2c
4
- data.tar.gz: 889f5510b79cdb3f950b90c1254be0ca33df17f0
3
+ metadata.gz: c8523164bf81e274258f9fd9df632e69e0073def
4
+ data.tar.gz: 591fe73ad0d036a8d0f015f47a142494f7a3a837
5
5
  SHA512:
6
- metadata.gz: e038a10b508b2a9d7d1893ea47592330b81d1b5e35a1f9061711f05fcf221e769ef687d6686ed0317c85924c9cdd14bcc3377394d8e9091061046b794c9cd95e
7
- data.tar.gz: 8d2206cb434d4005c31a25bb436ba595700ab140cc20997b72751fa17aa309c300469af0c059f456d157ee32df1fbff36c794192d0f88d283520cb400c7b619f
6
+ metadata.gz: 7e48ba26e94473f9d535a24d0866314c7e7e162e77ae2e0dc761b513631b2e6acf2ad874426b44008ab6102b45d9ca824ef14e08a0df02b6cd1d8b651f5ca706
7
+ data.tar.gz: e34077f5eb6321a36ccf4a8da79f3f32aa461e9cc909b51cdf5a829f5781858e78b9b326be823fb0891f99cf994ca49f7425cbfe998ee765a49d91fa0cfb60dd
data/.gitignore CHANGED
@@ -26,13 +26,16 @@ build/
26
26
 
27
27
  # for a library or gem, you might want to ignore these files since the code is
28
28
  # intended to run in multiple environments; otherwise, check them in:
29
- # Gemfile.lock
29
+ Gemfile.lock
30
30
  # .ruby-version
31
31
  # .ruby-gemset
32
32
 
33
33
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
34
  .rvmrc
35
35
 
36
+ # OS X
37
+ .DS_Store
38
+
36
39
  # singel related files
37
40
  outputs
38
41
  packer
@@ -22,5 +22,3 @@ SingleSpaceBeforeFirstArg:
22
22
  Enabled: false
23
23
  PerceivedComplexity:
24
24
  Enabled: false
25
- FileName:
26
- Enabled: false
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.5
5
+ - 2.2.0
6
+ script:
7
+ - bundle exec rake test
8
+
data/Gemfile CHANGED
@@ -1,3 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'aws-sdk-core'
4
+
5
+ group :test do
6
+ gem 'rubocop', '~> 0.28.0'
7
+ gem 'rake', '~> 10.0'
8
+ end
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # singel
2
+ [![Build Status](https://travis-ci.org/tas50/singel.svg)](https://travis-ci.org/tas50/singel)
2
3
 
3
4
  Singel is the first, and main, canal in Amsterdam. The canal served as the basis for the Amsterdam economy ferrying goods between producers and markets, and it also provided security by insulating the city from the surrounding areas. Singel the application provides the basis for unified system creation and provides the peace of mind that local test environments match production hosts. Singel wraps Packer (https://packer.io/) and allows for a single command to build various packer templates, ideally using Jenkins.
4
5
 
data/bin/singel CHANGED
@@ -1,4 +1,20 @@
1
- #!/usr/bin/env ruby
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.
2
18
 
3
19
  lib = File.expand_path('../../lib', __FILE__)
4
20
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -10,6 +26,7 @@ begin
10
26
  require 'json'
11
27
  require 'orchestrator.rb'
12
28
  require 'executor.rb'
29
+ require 'uploader.rb'
13
30
  rescue LoadError => e
14
31
  raise "Missing gem or lib #{e}"
15
32
  end
@@ -1,11 +1,26 @@
1
- #!/usr/bin/env ruby
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.
2
18
 
3
19
  # executes packer commands against template files
4
20
  class SingelExecutor
5
- def initialize(filename)
6
- @filename = filename
7
- @packer_dir = File.absolute_path(File.join(File.dirname($PROGRAM_NAME), 'packer'))
8
- @file_path = File.join(@packer_dir, filename)
21
+ def initialize(template)
22
+ @file_path = template
23
+ @packer_dir = File.dirname(template)
9
24
  @builders = {}
10
25
  end
11
26
 
@@ -13,7 +28,6 @@ class SingelExecutor
13
28
  def validates?
14
29
  Dir.chdir(@packer_dir)
15
30
  `packer validate #{@file_path} 2>&1`
16
- Dir.chdir('..') # prevent poisening $0 path on the next instance
17
31
  $CHILD_STATUS.success? ? true : false
18
32
  end
19
33
 
@@ -24,11 +38,14 @@ class SingelExecutor
24
38
  template_json['builders'].each do |builder|
25
39
  @builders[builder['name']] = builder['type']
26
40
  end
41
+ rescue Errno::ENOENT
42
+ puts "- Could not find the passed template file #{@file_path}".indent.to_red
43
+ exit
27
44
  end
28
45
 
29
46
  # print out the builders for this template
30
47
  def list
31
- puts @filename.gsub('.json', '') + ':'
48
+ puts File.basename(@file_path, '.json') + ':'
32
49
  parse_builders
33
50
  if @builders.empty?
34
51
  puts '- No builders found'.indent.to_red
@@ -38,4 +55,13 @@ class SingelExecutor
38
55
  end
39
56
  end
40
57
  end
58
+
59
+ def build
60
+ puts "Building #{File.basename(@file_path, '.json')}:".to_green
61
+ IO.popen("packer build #{@file_path}") do |cmd|
62
+ cmd.each { |line| puts line }
63
+ end
64
+
65
+ SingelUploader.new(@file_path).push
66
+ end
41
67
  end
@@ -1,9 +1,26 @@
1
- #!/usr/bin/env ruby
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.
2
18
 
19
+ # class to control validation of configs / prereqs and to
20
+ # fire off the individual executor instances to build each template
3
21
  class SingelOrchestrator
4
22
  def initialize(options)
5
23
  @options = options
6
- @templates = find_templates
7
24
  end
8
25
 
9
26
  # main method used to kick off the run
@@ -11,18 +28,17 @@ class SingelOrchestrator
11
28
  puts "\nsingel - unified image creation tool"
12
29
  puts "-----------------------------------------\n\n"
13
30
 
14
- check_aws_keys
31
+ check_dirs
15
32
  check_executables
33
+ @templates = find_templates
34
+ check_aws_keys
16
35
 
17
36
  execute_command(ARGV[0])
18
37
  end
19
38
 
20
- # check to make sure necessary directories exist
39
+ # check to make sure the packer dir exists
21
40
  def check_dirs
22
- unless Dir.exist?(@options[:packer_dir])
23
- puts "#{@options[:packer_dir]} not present. Cannot continue".to_red
24
- exit
25
- end
41
+ (puts "#{@options[:packer_dir]} not present. Cannot continue".to_red && exit) unless Dir.exist?(@options[:packer_dir])
26
42
  end
27
43
 
28
44
  # make a test connection using the AWS keys to determine if they're valid
@@ -47,25 +63,33 @@ class SingelOrchestrator
47
63
 
48
64
  # find the available packer templates on the host
49
65
  def find_templates
50
- check_dirs
51
- templates = []
52
- Dir.foreach(@options[:packer_dir]) do |item|
53
- templates << item if File.extname(item).downcase == '.json'
54
- end
66
+ if @options[:templates].empty?
67
+ templates = []
68
+ Dir.foreach(@options[:packer_dir]) do |item|
69
+ templates << File.join(@options[:packer_dir], item) if File.extname(item).downcase == '.json'
70
+ end
55
71
 
56
- if templates.empty?
57
- puts "No packer templates found in the 'packer' dir. Cannot continue.".to_red
58
- exit
72
+ if templates.empty?
73
+ puts "No packer templates found in the 'packer' dir. Cannot continue.".to_red
74
+ exit
75
+ end
76
+ templates
77
+ else
78
+ @options[:templates].map { |x| File.join(@options[:packer_dir], x) }
59
79
  end
60
- templates
61
80
  end
62
81
 
63
82
  # run the passed command per packer template
64
83
  def execute_command(cmd)
65
84
  @templates.each do |template|
66
85
  packer = SingelExecutor.new(template)
67
- puts "Packer template validation for #{template} failed.".to_red unless packer.validates?
68
- packer.send(cmd)
86
+ puts "Packer template validation for #{template} failed.\n".to_red unless packer.validates?
87
+ begin
88
+ packer.send(cmd)
89
+ rescue NoMethodError
90
+ puts "Action \"#{cmd}\" not found. Cannot continue".to_red
91
+ exit
92
+ end
69
93
  end
70
94
  end
71
95
  end
@@ -0,0 +1,28 @@
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
+ # uploads the packer artifacts to S3
20
+ class SingelUploader
21
+ def initialize(template)
22
+ @file_path = template
23
+ end
24
+
25
+ def push
26
+ puts "- Would be uploading the artifact for #{File.basename(@file_path, '.json')}".to_green.indent
27
+ end
28
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'singel'
3
- s.version = '0.0.2'
3
+ s.version = '0.1.1'
4
4
  s.date = Date.today.to_s
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.extra_rdoc_files = ['README.md', 'LICENSE']
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.add_development_dependency 'rubocop', '~> 0.28.0'
18
18
 
19
19
  s.files = `git ls-files -z`.split("\x0")
20
- s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ s.executables = s.name
21
21
  s.require_paths = ['lib']
22
22
  s.extra_rdoc_files = ['README.md']
23
23
  s.rdoc_options = ['--line-numbers', '--inline-source', '--title', 'singel', '--main', 'README.md']
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.0.2
4
+ version: 0.1.1
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-01-31 00:00:00.000000000 Z
11
+ date: 2015-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-core
@@ -62,6 +62,7 @@ extra_rdoc_files:
62
62
  files:
63
63
  - .gitignore
64
64
  - .rubocop.yml
65
+ - .travis.yml
65
66
  - Gemfile
66
67
  - LICENSE
67
68
  - README.md
@@ -69,6 +70,7 @@ files:
69
70
  - bin/singel
70
71
  - lib/executor.rb
71
72
  - lib/orchestrator.rb
73
+ - lib/uploader.rb
72
74
  - singel.gemspec
73
75
  homepage: http://www.github.com/tas50/singel
74
76
  licenses: