builderator 0.3.15 → 1.0.0.pre.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +9 -0
- data/Gemfile.lock +440 -0
- data/README.md +72 -18
- data/Rakefile +1 -2
- data/VERSION +1 -1
- data/bin/build-clean +102 -0
- data/bin/build-data +45 -0
- data/builderator.gemspec +7 -4
- data/docs/configuration.md +154 -0
- data/docs/configuration/cookbook.md +19 -0
- data/docs/configuration/profile.md +71 -0
- data/docs/versioning.md +65 -0
- data/lib/builderator.rb +3 -0
- data/lib/builderator/config.rb +93 -0
- data/lib/builderator/config/attributes.rb +287 -0
- data/lib/builderator/config/defaults.rb +163 -0
- data/lib/builderator/config/file.rb +336 -0
- data/lib/builderator/config/rash.rb +80 -0
- data/lib/builderator/control/cleaner.rb +138 -0
- data/lib/builderator/control/cookbook.rb +16 -0
- data/lib/builderator/control/data.rb +16 -0
- data/lib/builderator/control/data/image.rb +98 -0
- data/lib/builderator/control/version.rb +128 -0
- data/lib/builderator/control/version/auto.rb +48 -0
- data/lib/builderator/control/version/bump.rb +82 -0
- data/lib/builderator/control/version/comparable.rb +77 -0
- data/lib/builderator/control/version/git.rb +45 -0
- data/lib/builderator/control/version/scm.rb +92 -0
- data/lib/builderator/interface.rb +67 -0
- data/lib/builderator/interface/berkshelf.rb +38 -0
- data/lib/builderator/interface/packer.rb +75 -0
- data/lib/builderator/interface/vagrant.rb +31 -0
- data/lib/builderator/metadata.rb +5 -3
- data/lib/builderator/model/cleaner.rb +49 -0
- data/lib/builderator/model/cleaner/images.rb +93 -0
- data/lib/builderator/model/cleaner/instances.rb +58 -0
- data/lib/builderator/model/cleaner/launch_configs.rb +47 -0
- data/lib/builderator/model/cleaner/scaling_groups.rb +45 -0
- data/lib/builderator/model/cleaner/snapshots.rb +50 -0
- data/lib/builderator/model/cleaner/volumes.rb +48 -0
- data/lib/builderator/patch/berkshelf.rb +18 -0
- data/lib/builderator/patch/thor-actions.rb +47 -0
- data/lib/builderator/tasks.rb +127 -17
- data/lib/builderator/tasks/berkshelf.rb +63 -0
- data/lib/builderator/tasks/packer.rb +17 -56
- data/lib/builderator/tasks/vagrant.rb +111 -42
- data/lib/builderator/tasks/vendor.rb +94 -0
- data/lib/builderator/tasks/version.rb +58 -0
- data/lib/builderator/util.rb +37 -11
- data/lib/builderator/util/aws_exception.rb +1 -1
- data/lib/builderator/util/limit_exception.rb +12 -11
- data/lib/builderator/util/task_exception.rb +0 -2
- data/mkmf.log +4 -0
- data/spec/config_spec.rb +30 -0
- data/spec/data/Berksfile +6 -0
- data/spec/data/Buildfile +0 -0
- data/spec/data/Vagrantfile +0 -0
- data/spec/data/history.json +483 -0
- data/spec/data/packer.json +0 -0
- data/spec/interface_spec.rb +36 -0
- data/spec/resource/Buildfile +27 -0
- data/spec/spec_helper.rb +90 -0
- data/spec/version_spec.rb +282 -0
- data/template/Berksfile.erb +10 -0
- data/template/Buildfile.erb +28 -0
- data/template/Gemfile.erb +16 -0
- data/template/README.md.erb +61 -0
- data/template/Vagrantfile.erb +75 -0
- data/template/gitignore.erb +104 -0
- data/{.rubocop.yml → template/rubocop.erb} +0 -0
- metadata +203 -56
- data/.gitignore +0 -14
- data/lib/builderator/control/ami.rb +0 -65
- data/lib/builderator/control/clean.rb +0 -130
- data/lib/builderator/model.rb +0 -46
- data/lib/builderator/model/images.rb +0 -89
- data/lib/builderator/model/instances.rb +0 -55
- data/lib/builderator/model/launch_configs.rb +0 -46
- data/lib/builderator/model/scaling_groups.rb +0 -43
- data/lib/builderator/model/snapshots.rb +0 -49
- data/lib/builderator/model/volumes.rb +0 -48
- data/lib/builderator/tasks/ami.rb +0 -47
- data/lib/builderator/tasks/berks.rb +0 -68
- data/lib/builderator/tasks/clean.rb +0 -97
- data/lib/builderator/util/berkshim.rb +0 -34
- data/lib/builderator/util/cookbook.rb +0 -87
- data/lib/builderator/util/packer.rb +0 -39
- data/lib/builderator/util/shell.rb +0 -44
@@ -0,0 +1,163 @@
|
|
1
|
+
require_relative './file'
|
2
|
+
require_relative '../util'
|
3
|
+
|
4
|
+
module Builderator
|
5
|
+
# :nodoc
|
6
|
+
module Config
|
7
|
+
##
|
8
|
+
# Global predefined defaults
|
9
|
+
##
|
10
|
+
GLOBAL_DEFAULTS = File.new({}, :source => 'GLOBAL_DEFAULTS') do
|
11
|
+
cleanup true
|
12
|
+
version '0.0.0'
|
13
|
+
build_number 0
|
14
|
+
|
15
|
+
autoversion do |autoversion|
|
16
|
+
autoversion.create_tags false
|
17
|
+
autoversion.search_tags true
|
18
|
+
end
|
19
|
+
|
20
|
+
local do |local|
|
21
|
+
local.cookbook_path Util.workspace('cookbooks')
|
22
|
+
end
|
23
|
+
|
24
|
+
chef do |chef|
|
25
|
+
chef.log_level :info
|
26
|
+
chef.staging_directory '/var/chef'
|
27
|
+
chef.version = '12.5.1'
|
28
|
+
end
|
29
|
+
|
30
|
+
cookbook do |cookbook|
|
31
|
+
cookbook.path = '.'
|
32
|
+
cookbook.berkshelf_config = ::File.join(ENV['HOME'], '.berkshelf/config.json')
|
33
|
+
cookbook.add_source 'https://supermarket.chef.io'
|
34
|
+
end
|
35
|
+
|
36
|
+
aws.region 'us-east-1'
|
37
|
+
|
38
|
+
profile :default do |profile|
|
39
|
+
profile.log_level :info
|
40
|
+
|
41
|
+
profile.vagrant do |vagrant|
|
42
|
+
vagrant.ec2 do |ec2|
|
43
|
+
ec2.provider :aws
|
44
|
+
|
45
|
+
ec2.box 'dummy'
|
46
|
+
ec2.box_url 'https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box'
|
47
|
+
|
48
|
+
ec2.region = 'us-east-1'
|
49
|
+
ec2.instance_type 't2.micro'
|
50
|
+
ec2.ssh_username 'ubuntu'
|
51
|
+
ec2.ssh_host_attribute :public_ip_address
|
52
|
+
end
|
53
|
+
|
54
|
+
vagrant.local do |local|
|
55
|
+
local.provider :virtualbox
|
56
|
+
|
57
|
+
## Atlas metadata for Ubuntu cloud-images: https://atlas.hashicorp.com/ubuntu/boxes/trusty64
|
58
|
+
local.box 'ubuntu/trusty64'
|
59
|
+
|
60
|
+
local.memory 1024
|
61
|
+
local.cpus 2
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
profile.packer do |packer|
|
66
|
+
packer.build :default do |build|
|
67
|
+
build.type 'amazon-ebs'
|
68
|
+
build.region = 'us-east-1'
|
69
|
+
build.instance_type 'c3.large'
|
70
|
+
build.ami_virtualization_type 'hvm'
|
71
|
+
|
72
|
+
build.ssh_username 'ubuntu'
|
73
|
+
|
74
|
+
build.ami_name [Config.build_name, Config.version, Config.build_number].reject(&:nil?).join('-')
|
75
|
+
build.ami_description Config.description
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
cleaner do |cleaner|
|
81
|
+
cleaner.commit false
|
82
|
+
cleaner.force false
|
83
|
+
cleaner.filters {}
|
84
|
+
cleaner.sort_by 'creation_date'
|
85
|
+
cleaner.keep 5
|
86
|
+
|
87
|
+
cleaner.limits do |limits|
|
88
|
+
limits.images 24
|
89
|
+
limits.launch_configs 48
|
90
|
+
limits.snapshots 24
|
91
|
+
limits.volumes 8
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
generator.project :default do |default|
|
96
|
+
default.builderator.version '~> 1.0'
|
97
|
+
|
98
|
+
default.vagrant do |vagrant|
|
99
|
+
vagrant.install false
|
100
|
+
vagrant.version 'v1.8.0'
|
101
|
+
|
102
|
+
vagrant.plugin 'vagrant-aws'
|
103
|
+
vagrant.plugin 'vagrant-omnibus'
|
104
|
+
end
|
105
|
+
|
106
|
+
default.resource :berksfile do |berksfile|
|
107
|
+
berksfile.path 'Berksfile', 'Berksfile.lock'
|
108
|
+
berksfile.action :rm
|
109
|
+
end
|
110
|
+
|
111
|
+
default.resource :buildfile do |buildfile|
|
112
|
+
buildfile.path 'Buildfile'
|
113
|
+
buildfile.action :create
|
114
|
+
buildfile.template 'template/Buildfile.erb'
|
115
|
+
end
|
116
|
+
|
117
|
+
default.resource :cookbook do |cookbook|
|
118
|
+
cookbook.path 'cookbook'
|
119
|
+
cookbook.action :rm
|
120
|
+
end
|
121
|
+
|
122
|
+
default.resource :gemfile do |gemfile|
|
123
|
+
gemfile.path 'Gemfile'
|
124
|
+
gemfile.action :create
|
125
|
+
gemfile.template 'template/Gemfile.erb'
|
126
|
+
end
|
127
|
+
|
128
|
+
default.resource :gitignore do |gitignore|
|
129
|
+
gitignore.path '.gitignore'
|
130
|
+
gitignore.action :create
|
131
|
+
gitignore.template 'template/gitignore.erb'
|
132
|
+
end
|
133
|
+
|
134
|
+
default.resource :packerfile do |packerfile|
|
135
|
+
packerfile.path 'packer.json', 'packer'
|
136
|
+
packerfile.action :rm
|
137
|
+
end
|
138
|
+
|
139
|
+
default.resource :rubocop do |rubocop|
|
140
|
+
rubocop.path '.rubocop.yml'
|
141
|
+
rubocop.action :create
|
142
|
+
rubocop.template 'template/rubocop.erb'
|
143
|
+
end
|
144
|
+
|
145
|
+
default.resource :readme do |readme|
|
146
|
+
readme.path 'README.md'
|
147
|
+
readme.action :create
|
148
|
+
readme.template 'template/README.md.erb'
|
149
|
+
end
|
150
|
+
|
151
|
+
default.resource :thorfile do |thorfile|
|
152
|
+
thorfile.path 'Thorfile'
|
153
|
+
thorfile.action :rm
|
154
|
+
end
|
155
|
+
|
156
|
+
default.resource :vagrantfile do |vagrantfile|
|
157
|
+
vagrantfile.path 'Vagrantfile'
|
158
|
+
vagrantfile.action :rm
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,336 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
require_relative './attributes'
|
4
|
+
require_relative '../control/data'
|
5
|
+
require_relative '../util'
|
6
|
+
|
7
|
+
# rubocop:disable Metrics/ClassLength
|
8
|
+
|
9
|
+
module Builderator
|
10
|
+
module Config
|
11
|
+
##
|
12
|
+
# DSL Loader for a configuration file
|
13
|
+
##
|
14
|
+
class File < Attributes
|
15
|
+
class << self
|
16
|
+
## DSL Loaders
|
17
|
+
def from_file(source, **options)
|
18
|
+
new({}, options.merge(:type => :file, :source => source))
|
19
|
+
end
|
20
|
+
|
21
|
+
def from_json(source, **options)
|
22
|
+
new({}, options.merge(:type => :json, :source => source))
|
23
|
+
end
|
24
|
+
|
25
|
+
def lookup_cache
|
26
|
+
@lookup_cache ||= {}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_reader :date ## Provide an authoritative, UTC-based date for any consumers
|
31
|
+
attr_reader :source ## Where the instance was defined
|
32
|
+
attr_reader :type ## How compile should populate attributes
|
33
|
+
|
34
|
+
def initialize(attributes = {}, options = {}, &block)
|
35
|
+
super(attributes, &block)
|
36
|
+
|
37
|
+
@date = Time.now.utc
|
38
|
+
@type = options.fetch(:type, :code)
|
39
|
+
@source = options.fetch(:source, nil)
|
40
|
+
end
|
41
|
+
|
42
|
+
def compile
|
43
|
+
clean ## Clear dirty flag before re-parsing file or block
|
44
|
+
|
45
|
+
case @type
|
46
|
+
when :file
|
47
|
+
instance_eval(IO.read(source), source, 0)
|
48
|
+
when :json
|
49
|
+
@attributes = Rash.coerce(JSON.parse(IO.read(source)))
|
50
|
+
else
|
51
|
+
instance_eval(&@block) if @block
|
52
|
+
end
|
53
|
+
|
54
|
+
## Overlay policies
|
55
|
+
policy.each do |_, policy|
|
56
|
+
if policy.has?(:path)
|
57
|
+
next unless ::File.exist?(policy.path)
|
58
|
+
merge(self.class.from_file(policy.path).compile)
|
59
|
+
end
|
60
|
+
|
61
|
+
if policy.has?(:json)
|
62
|
+
next unless ::File.exist?(policy.json)
|
63
|
+
merge(self.class.from_json(policy.json).compile)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
## Use the Data controller to fetch IDs from the EC2 API at compile time
|
71
|
+
def lookup(source, query)
|
72
|
+
self.class.lookup_cache[cache_key(query)] ||= Control::Data.lookup(source, query)
|
73
|
+
end
|
74
|
+
|
75
|
+
## Helper to resolve paths to vendored files
|
76
|
+
def vendored(name, *path)
|
77
|
+
Util.vendor(name, *path)
|
78
|
+
end
|
79
|
+
|
80
|
+
## Helper to resolve absolute paths relative to this `File`.
|
81
|
+
## Only works for `File`s with valid filesystem source attributes!
|
82
|
+
def relative(*path)
|
83
|
+
Pathname.new(source).join(*(['..', path].flatten)).expand_path
|
84
|
+
end
|
85
|
+
|
86
|
+
attribute :build_name, :required => true
|
87
|
+
attribute :build_number
|
88
|
+
attribute :build_url
|
89
|
+
|
90
|
+
attribute :description
|
91
|
+
attribute :version
|
92
|
+
|
93
|
+
collection :policy do
|
94
|
+
attribute :path, :relative => true
|
95
|
+
attribute :json, :relative => true
|
96
|
+
end
|
97
|
+
|
98
|
+
##
|
99
|
+
# Enable/disable auto-versioning features
|
100
|
+
##
|
101
|
+
namespace :autoversion do
|
102
|
+
attribute :create_tags
|
103
|
+
attribute :search_tags
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# Local resource paths
|
108
|
+
##
|
109
|
+
namespace :local do
|
110
|
+
attribute :cookbook_path
|
111
|
+
attribute :data_bag_path
|
112
|
+
attribute :environment_path
|
113
|
+
end
|
114
|
+
|
115
|
+
namespace :chef do
|
116
|
+
attribute :log_level
|
117
|
+
attribute :staging_directory
|
118
|
+
attribute :version
|
119
|
+
end
|
120
|
+
|
121
|
+
##
|
122
|
+
# Cookbook build options
|
123
|
+
##
|
124
|
+
namespace :cookbook do
|
125
|
+
attribute :path
|
126
|
+
attribute :berkshelf_config
|
127
|
+
|
128
|
+
attribute :sources, :type => :list, :singular => :add_source
|
129
|
+
attribute :metadata
|
130
|
+
|
131
|
+
collection :depends do
|
132
|
+
attribute :version
|
133
|
+
|
134
|
+
attribute :git
|
135
|
+
attribute :github
|
136
|
+
attribute :branch
|
137
|
+
attribute :tag
|
138
|
+
attribute :ref
|
139
|
+
attribute :rel
|
140
|
+
|
141
|
+
attribute :path, :relative => true
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
##
|
146
|
+
# AWS configurations
|
147
|
+
##
|
148
|
+
namespace :aws do
|
149
|
+
attribute :region
|
150
|
+
attribute :access_key
|
151
|
+
attribute :secret_key
|
152
|
+
end
|
153
|
+
|
154
|
+
collection :profile do
|
155
|
+
attribute :tags, :type => :hash
|
156
|
+
attribute :log_level
|
157
|
+
|
158
|
+
##
|
159
|
+
# Sync'd artifacts
|
160
|
+
##
|
161
|
+
collection :artifact do
|
162
|
+
attribute :path, :relative => true
|
163
|
+
attribute :destination
|
164
|
+
end
|
165
|
+
|
166
|
+
##
|
167
|
+
# Chef configurations
|
168
|
+
##
|
169
|
+
namespace :chef do
|
170
|
+
attribute :run_list, :type => :list, :singular => :run_list_item
|
171
|
+
attribute :environment
|
172
|
+
attribute :node_attrs
|
173
|
+
end
|
174
|
+
|
175
|
+
##
|
176
|
+
# Packerfile
|
177
|
+
#
|
178
|
+
# This currently supports the AWS/EC2 builder.
|
179
|
+
##
|
180
|
+
namespace :packer do
|
181
|
+
collection :build do
|
182
|
+
attribute :type
|
183
|
+
|
184
|
+
## EC2 Placement and Virtualization parameters
|
185
|
+
attribute :region
|
186
|
+
attribute :availability_zone
|
187
|
+
attribute :vpc_id
|
188
|
+
attribute :subnet_id
|
189
|
+
|
190
|
+
attribute :instance_type
|
191
|
+
attribute :ami_virtualization_type
|
192
|
+
attribute :enhanced_networking
|
193
|
+
attribute :security_group_ids, :type => :list, :singular => :security_group_id
|
194
|
+
attribute :iam_instance_profile
|
195
|
+
|
196
|
+
attribute :source_ami
|
197
|
+
attribute :user_data
|
198
|
+
attribute :user_data_file
|
199
|
+
|
200
|
+
attribute :windows_password_timeout
|
201
|
+
|
202
|
+
## Access parameters
|
203
|
+
attribute :ssh_username
|
204
|
+
attribute :ssh_keypair_name
|
205
|
+
attribute :ssh_private_key_file
|
206
|
+
attribute :ssh_private_ip
|
207
|
+
attribute :temporary_key_pair_name
|
208
|
+
|
209
|
+
attribute :ami_name
|
210
|
+
attribute :ami_description
|
211
|
+
attribute :ami_users, :type => :list
|
212
|
+
attribute :ami_regions, :type => :list
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
##
|
217
|
+
# Vagrantfile
|
218
|
+
##
|
219
|
+
namespace :vagrant do
|
220
|
+
namespace :local do
|
221
|
+
attribute :provider
|
222
|
+
attribute :box
|
223
|
+
attribute :box_url
|
224
|
+
|
225
|
+
attribute :cpus
|
226
|
+
attribute :memory
|
227
|
+
end
|
228
|
+
|
229
|
+
namespace :ec2 do
|
230
|
+
attribute :provider
|
231
|
+
attribute :box
|
232
|
+
attribute :box_url
|
233
|
+
|
234
|
+
attribute :region
|
235
|
+
attribute :availability_zone
|
236
|
+
attribute :subnet_id
|
237
|
+
attribute :private_ip_address
|
238
|
+
|
239
|
+
attribute :instance_type
|
240
|
+
attribute :security_groups, :type => :list
|
241
|
+
attribute :iam_instance_profile_arn
|
242
|
+
|
243
|
+
attribute :source_ami
|
244
|
+
attribute :user_data
|
245
|
+
|
246
|
+
attribute :ssh_username
|
247
|
+
attribute :keypair_name
|
248
|
+
attribute :private_key_path
|
249
|
+
|
250
|
+
attribute :associate_public_ip
|
251
|
+
attribute :ssh_host_attribute
|
252
|
+
attribute :instance_ready_timeout
|
253
|
+
attribute :instance_check_interval
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
##
|
259
|
+
# Configure resources that must be fetched for a build
|
260
|
+
##
|
261
|
+
collection :vendor do
|
262
|
+
attribute :path, :relative => true
|
263
|
+
|
264
|
+
attribute :git
|
265
|
+
attribute :github
|
266
|
+
attribute :branch
|
267
|
+
attribute :tag
|
268
|
+
attribute :ref
|
269
|
+
attribute :rel
|
270
|
+
end
|
271
|
+
|
272
|
+
##
|
273
|
+
# Cleaner Parameters
|
274
|
+
##
|
275
|
+
namespace :cleaner do
|
276
|
+
attribute :commit
|
277
|
+
attribute :force
|
278
|
+
attribute :filters, Hash
|
279
|
+
attribute :group_by, :type => :list
|
280
|
+
attribute :sort_by
|
281
|
+
attribute :keep
|
282
|
+
|
283
|
+
namespace :limits do
|
284
|
+
attribute :images
|
285
|
+
attribute :launch_configs
|
286
|
+
attribute :snapshots
|
287
|
+
attribute :volumes
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
##
|
292
|
+
# Generator Options
|
293
|
+
##
|
294
|
+
namespace :generator do
|
295
|
+
collection :project do
|
296
|
+
namespace :builderator do
|
297
|
+
attribute :version
|
298
|
+
end
|
299
|
+
|
300
|
+
namespace :ruby do
|
301
|
+
attribute :version
|
302
|
+
end
|
303
|
+
|
304
|
+
namespace :vagrant do
|
305
|
+
attribute :install
|
306
|
+
attribute :version
|
307
|
+
|
308
|
+
collection :plugin do
|
309
|
+
attribute :version
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
collection :resource do
|
314
|
+
attribute :path, :type => :list
|
315
|
+
attribute :action
|
316
|
+
attribute :template
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
##
|
322
|
+
# Option to disable cleanup of build resources
|
323
|
+
##
|
324
|
+
attribute :cleanup
|
325
|
+
|
326
|
+
private
|
327
|
+
|
328
|
+
## Helper to generate unique, predictable keys for caching
|
329
|
+
def cache_key(query)
|
330
|
+
query.keys.sort.map { |k| "#{k}:#{query[k]}" }.join('|')
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
# rubocop:enable Metrics/ClassLength
|