minimal_pipeline 0.0.7 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2fbef7a5fe784df8ff482b86cc27d4fc8640a4d660da61d7a151cc38ae0d1c36
4
- data.tar.gz: ebf05b45d3aa4fe56c99f8de0d8941ba3662d4b32911cdd299f1d5d4fe97c867
3
+ metadata.gz: '0049179db6389e8fce50230b52b9965b98dd5c7ff041190a274e39eb29174cca'
4
+ data.tar.gz: fd8b0632cde9a18e26be5d94344a53e08d546f085a95c0eb13c02f8076e88bc6
5
5
  SHA512:
6
- metadata.gz: e1543410703abd71b9b2f44a2dff03a193ba51c5d330d1460995d208b273b32b1449e7f3b179cab5de43f6adf930c45e48f7e95532d94661ba929e8017b72460
7
- data.tar.gz: b6f1d8c7a2741ca90e03ef9e3a698bf33b2342c0f22692f98223fbfb1cc10be65e9bf344ea0c92cccfb4fc08b11567f7d22d25275068c6af2e4422289d22df56
6
+ metadata.gz: dd83066fa798f9b314fddaf0a79e7be6c441b591f26d686871d9a64822b0d31ae330a6dadb3bc52ef0e7660f152934f44b261e36bd557b826c5689aab3d51b5c
7
+ data.tar.gz: 0ac1739f0f2382fca438dec93f70986452b88134a7d2603df8c301e8edeaa6899b49e5830023f01cbec26b866ae29a6fa0e80f594cd1438a16b4152f3b4a8019
@@ -80,17 +80,17 @@ class MinimalPipeline
80
80
  # @param stack_parameters [Hash] Parameters to be passed into the stack
81
81
  def deploy_stack(stack_name, stack_parameters)
82
82
  unless @client.describe_stacks(stack_name: stack_name).stacks.empty?
83
- puts 'Updating the existing stack'
83
+ puts 'Updating the existing stack' if ENV['DEBUG']
84
84
  @client.update_stack(stack_parameters)
85
85
  @client.wait_until(:stack_update_complete, stack_name: stack_name)
86
86
  end
87
87
  rescue Aws::CloudFormation::Errors::ValidationError => error
88
88
  if error.to_s.include? 'No updates are to be performed.'
89
- puts 'Nothing to do.'
89
+ puts 'Nothing to do.' if ENV['DEBUG']
90
90
  elsif error.to_s.include? 'Template error'
91
91
  raise error
92
92
  else
93
- puts 'Creating a new stack'
93
+ puts 'Creating a new stack' if ENV['DEBUG']
94
94
  @client.create_stack(stack_parameters)
95
95
  @client.wait_until(:stack_create_complete, stack_name: stack_name)
96
96
  end
@@ -77,7 +77,7 @@ class MinimalPipeline
77
77
  't' => image_id,
78
78
  'buildargs' => JSON.dump(build_args)
79
79
  }
80
- puts "Build args: #{args.inspect}"
80
+ puts "Build args: #{args.inspect}" if ENV['DEBUG']
81
81
  ::Docker.options[:read_timeout] = timeout
82
82
  ::Docker::Image.build_from_dir(dir, args) { |v| build_output(v) }
83
83
  end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'packer-config'
4
+
5
+ class MinimalPipeline
6
+ # Here is an example of how to use this class to build AMIs from Packer YAML
7
+ #
8
+ # ```
9
+ # Pass in the path to the Packer JSON config file
10
+ # packer = MinimalPipeline::Packer.new('path/to/packer.json')
11
+ #
12
+ # variables = {
13
+ # 'foo' => 'bar',
14
+ # }
15
+ #
16
+ # # Build the AMI and get the new AMI ID
17
+ # new_ami_id = packer.build_ami(variables)
18
+ # ```
19
+ class Packer
20
+ attr_accessor :config
21
+
22
+ # Instaniate a Packer object
23
+ #
24
+ # @param packer_config [String] Path to the JSON packer config file
25
+ def initialize(packer_config)
26
+ @config = packer_config
27
+ end
28
+
29
+ # Parse the newly built AMI from a given packer command output
30
+ #
31
+ # @param output [String] The command output of a packer run
32
+ # @return [String]
33
+ def get_ami_id(output)
34
+ return if output.nil? || output.empty?
35
+ output.match(/AMIs were created:\\nus-east-1: (ami-.+)\\n/)[1]
36
+ end
37
+
38
+ # Build and execute a packer build command
39
+ #
40
+ # @param variables [Hash] Optional key value pairs of packer variables
41
+ # @return [String]
42
+ def build_ami(variables = {})
43
+ variable_string = ''
44
+
45
+ variables.each_pair do |key, value|
46
+ variable_string += "-var '#{key}=#{value}' "
47
+ end
48
+
49
+ command = 'packer -machine-readable build '
50
+ command += variable_string unless variable_string.empty?
51
+ command += @config
52
+ puts command if ENV['DEBUG']
53
+
54
+ output = `#{command}`
55
+ get_ami_id(output)
56
+ end
57
+ end
58
+ end
@@ -14,4 +14,5 @@ class MinimalPipeline
14
14
  autoload(:Crossing, 'minimal_pipeline/crossing')
15
15
  autoload(:Docker, 'minimal_pipeline/docker')
16
16
  autoload(:Keystore, 'minimal_pipeline/keystore')
17
+ autoload(:Packer, 'minimal_pipeline/packer')
17
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minimal_pipeline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mayowa Aladeojebi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-09-20 00:00:00.000000000 Z
12
+ date: 2018-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -67,6 +67,20 @@ dependencies:
67
67
  - - '='
68
68
  - !ruby/object:Gem::Version
69
69
  version: 0.1.7
70
+ - !ruby/object:Gem::Dependency
71
+ name: packer-config
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '='
75
+ - !ruby/object:Gem::Version
76
+ version: 1.6.3
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '='
82
+ - !ruby/object:Gem::Version
83
+ version: 1.6.3
70
84
  - !ruby/object:Gem::Dependency
71
85
  name: rake
72
86
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +122,7 @@ files:
108
122
  - lib/minimal_pipeline/crossing.rb
109
123
  - lib/minimal_pipeline/docker.rb
110
124
  - lib/minimal_pipeline/keystore.rb
125
+ - lib/minimal_pipeline/packer.rb
111
126
  homepage: https://github.com/stelligent/minimal-pipeline-gem
112
127
  licenses:
113
128
  - 0BSD