Skip to content

Commit

Permalink
Merge pull request #745 from chef/bentoya
Browse files Browse the repository at this point in the history
Use the bento-ya gem, add builds.yml
  • Loading branch information
Seth Thomas authored Dec 19, 2016
2 parents f82fcb2 + d8a7012 commit 5d1cd38
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 996 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ packer.log
/builds/
.kitchen
.kitchen.*.yml
Gemfile.lock
7 changes: 1 addition & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
source 'https://rubygems.org'

gem 'rake'
gem 'thor'
gem 'test-kitchen'
gem 'json'
gem 'mixlib-shellout'
gem 'aws-sdk'
gem 'bento-ya'
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,20 @@ end

### Using `bento`

In the `bin` directory of this repo is the `bento` utility which wraps `packer` as well as allowing other related functionality.
This is an opinionated tool that the project uses for building the hosted boxes listed above.
```
$ gem install bento-ya
```

If you use Bundler, you can add run `bundle install` from the bento repo.
Prefix commands with `bundle exec` if doing so.

To build multiple templates for all providers (VirtualBox, Fusion, Parallels, etc):

$ bin/bento build debian-8.6-amd64 debian-8.6-i386
$ bento build debian-8.6-amd64 debian-8.6-i386

To build a box for a single provider:

$ bin/bento build --only=virtualbox-iso debian-8.6-amd64
$ bento build --only=virtualbox-iso debian-8.6-amd64

### Using `packer`

Expand Down
97 changes: 52 additions & 45 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
require 'json'
require 'yaml'

# TODO: private boxes may need to specify a mirror

# Enables `bundle exec rake do_all[ubuntu-12.04-amd64,centos-7.1-x86_64]
# http://blog.stevenocchipinti.com/2013/10/18/rake-task-with-an-arbitrary-number-of-arguments/
task :do_all do |_task, args|
args.extras.each do |a|
# build stage
Rake::Task['build_box'].invoke(a)
Rake::Task['build_box'].reenable
builds = YAML.load(File.read("builds.yml"))

desc 'Do ALL THE THINGS'
task :do_all do
# build stage
builds['public'].each do |platform, versions|
versions.each do |version, archs|
archs.each do |arch|
builds['providers'].each do |provider|
# build stage
Rake::Task['build_box'].invoke("#{platform}-#{version}-#{arch}", "#{provider}")
Rake::Task['build_box'].reenable
puts "#{platform}-#{version}-#{arch}, #{provider}"
# verification stage
Rake::Task['test_all'].invoke
Rake::Task['test_all'].reenable
# publish stage
Rake::Task['upload_all'].invoke
Rake::Task['upload_all'].reenable
# release stage
Rake::Task['release_all'].invoke
Rake::Task['release_all'].reenable
# clean stage
Rake::Task['clean'].invoke
Rake::Task['clean'].reenable
end
end
end
end

# verification stage
Rake::Task['test_all'].invoke
Rake::Task['test_all'].reenable

# publish stage
Rake::Task['upload_all'].invoke
Rake::Task['upload_all'].reenable

# release stage
Rake::Task['release_all'].invoke
Rake::Task['release_all'].reenable
end

desc 'Test all boxes with Test Kitchen'
task :test_all do
sh './bin/bento test'
sh 'bento test -f'
end

desc 'Upload all boxes to Atlas and S3 for all providers'
desc 'Upload all boxes to Atlas for all providers'
task :upload_all do
sh './bin/bento upload'
sh 'bento upload'
end

desc 'Release all'
Expand All @@ -44,23 +56,30 @@ task :release_all do
end

desc 'Build a bento template'
task :build_box, :template do |_, args|
sh build_command(args[:template])
task :build_box, :template, :provider do |_, args|
bento_provider = ENV['BENTO_PROVIDERS'] ? ENV['BENTO_PROVIDERS'] : args[:provider]
cmd = %W(bento build #{args[:template]})
cmd.insert(2, "--only #{bento_provider}")
cmd.insert(2, "--mirror #{ENV['PACKER_MIRROR']}") if ENV['PACKER_MIRROR']
cmd.insert(2, "--version #{ENV['BENTO_VERSION']}") if ENV['BENTO_VERSION']
cmd.insert(2, "--headless")
cmd.join(' ')
sh a_to_s(cmd)
end

desc 'Release a version of a box'
task :release, [:boxname, :version] do |_, args|
sh "./bin/bento release #{args[:boxname]} #{args[:version]}"
sh "bento release #{args[:boxname]} #{args[:version]}"
end

desc 'Revoke a version of a box'
task :revoke, [:boxname, :version] do |_, args|
sh "./bin/bento revoke #{args[:boxname]} #{args[:version]}"
sh "bento revoke #{args[:boxname]} #{args[:version]}"
end

desc 'Delete a version of a box'
task :delete, [:boxname, :version] do |_, args|
sh "./bin/bento delete #{args[:boxname]} #{args[:version]}"
sh "bento delete #{args[:boxname]} #{args[:version]}"
end

desc 'Clean the build directory'
Expand All @@ -69,6 +88,14 @@ task :clean do
`rm -rf builds/*.json builds/*.box packer-* .kitchen.*.yml`
end

def a_to_s(*args)
clean_array(*args).join(" ")
end

def clean_array(*args)
args.flatten.reject { |i| i.nil? || i == "" }.map(&:to_s)
end

def box_metadata(metadata_file)
metadata = {}
file = File.read(metadata_file)
Expand All @@ -85,15 +112,6 @@ def box_metadata(metadata_file)
metadata
end

def build_command(template)
cmd = %W(./bin/bento build #{template})
cmd.insert(2, "--only #{ENV['BENTO_PROVIDERS']}") if ENV['BENTO_PROVIDERS']
cmd.insert(2, "--mirror #{ENV['PACKER_MIRROR']}") if ENV['PACKER_MIRROR']
cmd.insert(2, "--version #{ENV['BENTO_VERSION']}") if ENV['BENTO_VERSION']
cmd.insert(2, "--headless")
cmd.join(' ')
end

def metadata_files
@metadata_files ||= compute_metadata_files
end
Expand All @@ -102,14 +120,3 @@ def compute_metadata_files
`ls builds/*.json`.split("\n")
end

# http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
end
end
false
end
Loading

0 comments on commit 5d1cd38

Please sign in to comment.