builderator 1.2.2 → 1.2.3.pre.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/builderator/config/attributes.rb +4 -1
- data/lib/builderator/config/defaults.rb +10 -0
- data/lib/builderator/config/file.rb +34 -1
- data/lib/builderator/control/data.rb +1 -0
- data/lib/builderator/control/data/ecr.rb +40 -0
- data/lib/builderator/interface/packer.rb +69 -15
- data/lib/builderator/tasks.rb +8 -0
- data/lib/builderator/util.rb +4 -0
- data/template/Vagrantfile.erb +12 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83b75ce26deeb6612ec531be9a548b2b5c43f412
|
4
|
+
data.tar.gz: 1622ca8922bb3596167b1341d3f170ec3feba4e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16cc1d59457a54b2b86e6ae401b1d870fbb768ae3d61aae10a024a1da7927ef444d7721f1423edef5fa6fe9099ef2159c317766340f02a23d827bc7bf6783203
|
7
|
+
data.tar.gz: 6d1e30012ec43092c5cd1c3bdab195b1fdc4f6776840367c4b97dbdd7e2630dac6e4a3bc35467f18f25a19c53a6b3b8440e156184fe417619819c0f593b327c0
|
@@ -23,7 +23,10 @@ module Builderator
|
|
23
23
|
## Instantiate List if it doesn't exist yet. `||=` will always return a new Rash.
|
24
24
|
@attributes[attribute_name] = Config::List.new(run_options) unless @attributes.has?(attribute_name, Config::List)
|
25
25
|
|
26
|
-
|
26
|
+
unless arg.empty?
|
27
|
+
@attributes[attribute_name].set(*arg.flatten)
|
28
|
+
@attributes[attribute_name].set(*arg) if options[:flatten] == false
|
29
|
+
end
|
27
30
|
@attributes[attribute_name]
|
28
31
|
end
|
29
32
|
|
@@ -80,6 +80,16 @@ module Builderator
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
profile :docker do |profile|
|
84
|
+
profile.log_level :info
|
85
|
+
|
86
|
+
profile.packer do |packer|
|
87
|
+
packer.build :docker do |build|
|
88
|
+
build.type 'docker'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
83
93
|
cleaner do |cleaner|
|
84
94
|
cleaner.commit false
|
85
95
|
cleaner.force false
|
@@ -191,15 +191,46 @@ module Builderator
|
|
191
191
|
attribute :binary_env
|
192
192
|
end
|
193
193
|
|
194
|
+
collection :provisioner do
|
195
|
+
attribute :inline, :type => :list
|
196
|
+
attribute :environment_vars, :type => :list
|
197
|
+
end
|
198
|
+
|
194
199
|
##
|
195
200
|
# Packerfile
|
196
201
|
#
|
197
|
-
# This currently supports the AWS/EC2
|
202
|
+
# This currently supports the AWS/EC2 and Docker builders.
|
198
203
|
##
|
199
204
|
namespace :packer do
|
200
205
|
collection :build do
|
201
206
|
attribute :type
|
202
207
|
|
208
|
+
## Docker-specific attributes
|
209
|
+
# Required
|
210
|
+
attribute :image
|
211
|
+
# One (and only one) of the following is required
|
212
|
+
attribute :commit
|
213
|
+
attribute :discard
|
214
|
+
attribute :export_path
|
215
|
+
|
216
|
+
# Optional attributes
|
217
|
+
attribute :author
|
218
|
+
attribute :aws_access_key
|
219
|
+
attribute :aws_secret_key
|
220
|
+
attribute :aws_token
|
221
|
+
attribute :changes, :type => :list
|
222
|
+
attribute :ecr_login
|
223
|
+
attribute :login
|
224
|
+
attribute :login_email
|
225
|
+
attribute :login_username
|
226
|
+
attribute :login_password
|
227
|
+
attribute :login_server
|
228
|
+
attribute :message
|
229
|
+
attribute :privileged
|
230
|
+
attribute :pull
|
231
|
+
attribute :run_command, :type => :list
|
232
|
+
attribute :volumes, :type => :hash
|
233
|
+
|
203
234
|
## EC2 Placement and Virtualization parameters
|
204
235
|
attribute :region
|
205
236
|
attribute :availability_zone
|
@@ -234,6 +265,8 @@ module Builderator
|
|
234
265
|
## Assumable role for tagging AMIs in remote accounts
|
235
266
|
attribute :tagging_role
|
236
267
|
end
|
268
|
+
|
269
|
+
attribute :post_processors, :type => :list, :flatten => false
|
237
270
|
end
|
238
271
|
|
239
272
|
##
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
require_relative '../../util'
|
5
|
+
|
6
|
+
module Builderator
|
7
|
+
module Control
|
8
|
+
# :nodoc:
|
9
|
+
module Data
|
10
|
+
# Lookup ECR repository info
|
11
|
+
#
|
12
|
+
# NB. We want to embed the login_server info into the returned repo data for
|
13
|
+
# ease of use. Thus, instead of an AWS struct-type, we get a hash with the
|
14
|
+
# injected value.
|
15
|
+
def self.repository(query = {})
|
16
|
+
ECR.search(query).map do |repo|
|
17
|
+
repo.to_h.tap { |r| r[:login_server] = "https://#{repo.repository_uri.sub(repo.repository_name, '')}" }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Find ECR repositories for sources
|
24
|
+
##
|
25
|
+
module ECR
|
26
|
+
class << self
|
27
|
+
def search(query = {})
|
28
|
+
options = {}
|
29
|
+
|
30
|
+
options['repository_names'] = Util.to_array(query.delete('name')) if query.include?('name')
|
31
|
+
options['registry_id'] = query.delete('owner') if query.include?('owner')
|
32
|
+
|
33
|
+
Util.ecr.describe_repositories(options)
|
34
|
+
.each_with_object([]) { |page, repositories| repositories.push(*page.repositories) }
|
35
|
+
.sort { |a, b| a.repository_name <=> b.repository_name }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -19,13 +19,27 @@ module Builderator
|
|
19
19
|
def initialize(*_)
|
20
20
|
super
|
21
21
|
|
22
|
+
docker_builders = Config.profile.current.packer.build.select do |_, builder|
|
23
|
+
builder.to_h[:type] == 'docker'
|
24
|
+
end
|
25
|
+
|
22
26
|
@packerfile ||= {
|
23
27
|
:builders => [],
|
24
|
-
:provisioners => []
|
28
|
+
:provisioners => [],
|
29
|
+
'post-processors' => []
|
25
30
|
}.tap do |json|
|
26
31
|
Config.profile.current.packer.build.each do |_, build|
|
27
32
|
build_hash = build.to_hash.tap do |b|
|
28
|
-
b[:tags] = Config.profile.current.tags
|
33
|
+
b[:tags] = Config.profile.current.tags unless Config.profile.current.tags.empty?
|
34
|
+
end
|
35
|
+
|
36
|
+
if build_hash[:type] == 'docker'
|
37
|
+
raise 'The Docker builder requires a base image' unless build_hash.key?(:image)
|
38
|
+
|
39
|
+
# The Docker builder requires one and only one of 'commit', 'discard', or 'export_path' set
|
40
|
+
if build_hash.keys.select { |k| [:commit, :discard, :export_path].include?(k) }.length != 1
|
41
|
+
raise 'The Docker builder requires one and only one of `commit`, `discard`, or `export_path` attributes to be defined'
|
42
|
+
end
|
29
43
|
end
|
30
44
|
|
31
45
|
# If we specify encrypted boot, packer won't allow ami_users.
|
@@ -49,16 +63,41 @@ module Builderator
|
|
49
63
|
json[:builders] << build_hash
|
50
64
|
end
|
51
65
|
|
52
|
-
|
66
|
+
# post_processors must be a List of Rashes.
|
67
|
+
post_processors = Config.profile.current.packer.post_processors.to_a
|
68
|
+
json['post-processors'] = post_processors.first unless post_processors.empty?
|
69
|
+
json.delete('post-processors') if json['post-processors'].compact.empty?
|
70
|
+
|
71
|
+
## Initialize the staging directory unless using the docker builder
|
53
72
|
json[:provisioners] << {
|
54
73
|
:type => 'shell',
|
55
74
|
:inline => "sudo mkdir -p #{Config.chef.staging_directory}/cache && "\
|
56
75
|
"sudo chown $(whoami) -R #{Config.chef.staging_directory}"
|
57
|
-
}
|
58
|
-
|
76
|
+
} if docker_builders.empty?
|
77
|
+
|
78
|
+
# Only add artifact provisioners if they're defined
|
79
|
+
Config.profile.current.artifact.each do |_, artifact|
|
80
|
+
json[:provisioners] << _artifact_provisioner(artifact)
|
81
|
+
end unless Config.profile.current.artifact.attributes.empty?
|
82
|
+
|
83
|
+
# Only add chef provisioners if they're defined
|
84
|
+
unless Config.profile.current.chef.attributes.empty?
|
85
|
+
# There are certain options (staging directory, run as sudo) that don't apply
|
86
|
+
# to the docker builder.
|
87
|
+
json[:provisioners] << if docker_builders.empty?
|
88
|
+
_chef_provisioner
|
89
|
+
else
|
90
|
+
_chef_provisioner_docker
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# After adding the default provisioners, we add any additional ones to the provisioners array
|
95
|
+
Config.profile.current.provisioner.each do |name, provisioner|
|
96
|
+
json[:provisioners] << provisioner.attributes.tap { |p| p[:type] = name.to_s }
|
97
|
+
end
|
59
98
|
|
60
|
-
|
61
|
-
|
99
|
+
json.delete(:provisioners) if json[:provisioners].empty?
|
100
|
+
end
|
62
101
|
end
|
63
102
|
|
64
103
|
def render
|
@@ -68,18 +107,30 @@ module Builderator
|
|
68
107
|
private
|
69
108
|
|
70
109
|
## Upload artifacts to the build container
|
71
|
-
def
|
72
|
-
|
73
|
-
packerfile[:provisioners] << {
|
110
|
+
def _artifact_provisioner(artifact)
|
111
|
+
{
|
74
112
|
:type => 'file',
|
75
113
|
:source => artifact.path,
|
76
114
|
:destination => artifact.destination
|
77
|
-
|
78
|
-
end
|
115
|
+
}
|
79
116
|
end
|
80
117
|
|
81
118
|
def _chef_provisioner
|
82
|
-
|
119
|
+
_chef_provisioner_base.merge(
|
120
|
+
:staging_directory => Config.chef.staging_directory,
|
121
|
+
:install_command => _chef_install_command
|
122
|
+
)
|
123
|
+
end
|
124
|
+
|
125
|
+
def _chef_provisioner_docker
|
126
|
+
_chef_provisioner_base.merge(
|
127
|
+
:prevent_sudo => true,
|
128
|
+
:install_command => _chef_install_command(false)
|
129
|
+
)
|
130
|
+
end
|
131
|
+
|
132
|
+
def _chef_provisioner_base
|
133
|
+
{
|
83
134
|
:type => 'chef-solo',
|
84
135
|
:run_list => Config.profile.current.chef.run_list,
|
85
136
|
:cookbook_paths => Config.local.cookbook_path,
|
@@ -87,10 +138,13 @@ module Builderator
|
|
87
138
|
:environments_path => Config.local.environment_path,
|
88
139
|
:chef_environment => Config.profile.current.chef.environment,
|
89
140
|
:json => Config.profile.current.chef.node_attrs,
|
90
|
-
:staging_directory => Config.chef.staging_directory,
|
91
|
-
:install_command => "curl -L https://www.chef.io/chef/install.sh | sudo bash -s -- -v #{Config.chef.version}"
|
92
141
|
}
|
93
142
|
end
|
143
|
+
|
144
|
+
def _chef_install_command(sudo = true)
|
145
|
+
template = sudo ? 'sudo' : ''
|
146
|
+
format("curl -L https://www.chef.io/chef/install.sh | %s bash -s -- -v #{Config.chef.version}", template)
|
147
|
+
end
|
94
148
|
end
|
95
149
|
end
|
96
150
|
end
|
data/lib/builderator/tasks.rb
CHANGED
@@ -82,6 +82,14 @@ module Builderator
|
|
82
82
|
invoke Tasks::Packer, :remote_tag, [profile], options if options['remote_tag']
|
83
83
|
end
|
84
84
|
|
85
|
+
desc 'container [PROFILE = docker]', 'Build a container of PROFILE'
|
86
|
+
method_option :debug, :type => :boolean
|
87
|
+
def container(profile = :docker)
|
88
|
+
prepare
|
89
|
+
|
90
|
+
invoke Tasks::Packer, :build, [profile], options
|
91
|
+
end
|
92
|
+
|
85
93
|
# desc 'cookbook SUBCOMMAND', 'Cookbook tasks'
|
86
94
|
# subcommand 'cookbook', Tasks::Cookbook
|
87
95
|
|
data/lib/builderator/util.rb
CHANGED
@@ -71,6 +71,10 @@ module Builderator
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
def ecr(region = Config.aws.region)
|
75
|
+
clients["ecr-#{region}"] ||= Aws::ECR::Client.new(:region => region)
|
76
|
+
end
|
77
|
+
|
74
78
|
def asg(region = Config.aws.region)
|
75
79
|
clients["asg-#{region}"] ||= Aws::AutoScaling::Client.new(:region => region)
|
76
80
|
end
|
data/template/Vagrantfile.erb
CHANGED
@@ -94,4 +94,16 @@ Vagrant.configure('2') do |config|
|
|
94
94
|
## Tell Chef that this is a Vagrant build
|
95
95
|
chef.json[:vagrant] = true
|
96
96
|
end
|
97
|
+
|
98
|
+
<%- profile.current.provisioner.each do |name, provisioner| -%>
|
99
|
+
<%- provisioner.each do |func, val| -%>
|
100
|
+
<%- if val.is_a?(Array) -%>
|
101
|
+
<%- val.each do |v| -%>
|
102
|
+
config.vm.provision "<%= name %>", <%= func %>: "<%= v %>"
|
103
|
+
<%- end -%>
|
104
|
+
<%- else -%>
|
105
|
+
config.vm.provision "<%= name %>", <%= func %>: "<%= val %>"
|
106
|
+
<%- end -%>
|
107
|
+
<%- end -%>
|
108
|
+
<%- end -%>
|
97
109
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: builderator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3.pre.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Manero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -205,6 +205,7 @@ files:
|
|
205
205
|
- lib/builderator/control/cleaner.rb
|
206
206
|
- lib/builderator/control/cookbook.rb
|
207
207
|
- lib/builderator/control/data.rb
|
208
|
+
- lib/builderator/control/data/ecr.rb
|
208
209
|
- lib/builderator/control/data/image.rb
|
209
210
|
- lib/builderator/control/version.rb
|
210
211
|
- lib/builderator/control/version/auto.rb
|
@@ -259,12 +260,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
259
260
|
version: '0'
|
260
261
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
261
262
|
requirements:
|
262
|
-
- - "
|
263
|
+
- - ">"
|
263
264
|
- !ruby/object:Gem::Version
|
264
|
-
version:
|
265
|
+
version: 1.3.1
|
265
266
|
requirements: []
|
266
267
|
rubyforge_project:
|
267
|
-
rubygems_version: 2.
|
268
|
+
rubygems_version: 2.5.2
|
268
269
|
signing_key:
|
269
270
|
specification_version: 4
|
270
271
|
summary: Tools to make CI Packer builds awesome
|