module Singel
main orchestrator of singel runs
- Author
-
Tim Smith (<tim@cozy.co>)
- Copyright
-
Copyright © 2014 Tim Smith
- License
-
Apache License, Version 2.0
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
- Author
-
Tim Smith (<tim@cozy.co>)
- Copyright
-
Copyright © 2014 Tim Smith
- License
-
Apache License, Version 2.0
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
- Author
-
Tim Smith (<tim@cozy.co>)
- Copyright
-
Copyright © 2014 Tim Smith
- License
-
Apache License, Version 2.0
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
- Author
-
Tim Smith (<tim@cozy.co>)
- Copyright
-
Copyright © 2014 Tim Smith
- License
-
Apache License, Version 2.0
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Public Class Methods
main method used to kick off the run
# File lib/singel.rb 30 def self::run 31 # flush output immediatly so job status shows up in jenkins 32 $stdout.sync = $stderr.sync = true 33 @options = Config.config 34 puts "\nsingel - unified image creation tool" 35 puts "-----------------------------------------\n\n" 36 37 check_dirs 38 check_executables 39 @templates = find_templates 40 check_aws_keys 41 42 execute_command(ARGV[0]) 43 end
Private Class Methods
make a test connection using the AWS keys to determine if they're valid
# File lib/singel.rb 57 def self::check_aws_keys 58 ec2 = Aws::EC2::Client.new(region: 'us-east-1') 59 ec2.describe_instance_status 60 rescue 61 puts 'Could not connect to EC2. Check your local AWS credentials before continuing.'.to_red 62 STDOUT.flush 63 exit! 64 end
check to make sure the packer dir exists
# File lib/singel.rb 48 def self::check_dirs 49 unless Dir.exist?(@options[:packer_dir]) 50 puts "#{@options[:packer_dir]} not present.".to_red 51 puts "See help for information on specifying an alternate dir.\n".to_red 52 exit! 53 end 54 end
check to make sure the prereq binaries present
# File lib/singel.rb 67 def self::check_executables 68 { 'Virtualbox' => 'vboxwebsrv', 'Packer' => 'packer' }.each_pair do |name, binary| 69 `which #{binary} 2>&1` 70 unless $CHILD_STATUS.success? 71 puts "Could not find #{name} binary #{binary}. You must install #{name} before continuing.".to_red unless $CHILD_STATUS 72 exit! 73 end 74 end 75 end
run the passed command per packer template
# File lib/singel.rb 98 def self::execute_command(cmd) 99 @templates.each do |t| 100 template = PackerTemplate.new(t) 101 executor = PackerExecutor.new(template, @options[:builders]) 102 puts "Packer template validation for #{template.path} failed.\n".to_red unless template.validates? 103 begin 104 executor.send(cmd) 105 rescue NoMethodError 106 puts "Action \"#{cmd}\" not found. Cannot continue".to_red 107 exit! 108 end 109 end 110 end
find the available packer templates on the host
# File lib/singel.rb 78 def self::find_templates 79 # find packer templates on disk since none were passed via args 80 if @options[:templates].empty? 81 templates = [] 82 Dir.foreach(@options[:packer_dir]) do |item| 83 templates << File.join(@options[:packer_dir], item) if File.extname(item).casecmp('.json').zero? 84 end 85 86 # throw and error and exist if we still dont find any templates 87 if templates.empty? 88 puts "No packer templates found in the 'packer' dir. Cannot continue.".to_red 89 exit! 90 end 91 templates 92 else # parse the arg provided template list 93 @options[:templates].map { |x| File.join(@options[:packer_dir], x) } 94 end 95 end