Skip to content

Commit

Permalink
Implement writing out a containerfile for a host
Browse files Browse the repository at this point in the history
This allows running:

    beaker-docker containerfile centos9-64

The spec is ran through beaker-hostgenerator and then it writes to
Containerfile. The filename can also be passed in as an additional
argument.
  • Loading branch information
ekohl committed Mar 9, 2024
1 parent 72dda38 commit e13be08
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion bin/beaker-docker
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,27 @@
# frozen_string_literal: true

require 'rubygems' unless defined?(Gem)
require 'beaker'
require 'beaker-docker'

def dockerfile(hostspec, filename)
ENV['BEAKER_HYPERVISOR'] = 'docker'
options = Beaker::Options::Parser.new.parse_args(['--hosts', hostspec || '', '--no-provision'])
options[:logger] = Beaker::Logger.new(options)
network_manager = Beaker::NetworkManager.new(options, options[:logger])
network_manager.provision
hosts = network_manager.hosts

if hosts.size != 1
options[:logger].error "Found #{hosts.size} hosts, expected 1"
exit(1)
end

hypervisor = network_manager.hypervisors['docker']
# TODO: private method
File.write(filename, hypervisor.send(:dockerfile_for, hosts.first))
end

VERSION_STRING = <<'VER'
_ .--.
( ` )
Expand All @@ -25,6 +44,13 @@ VERSION_STRING = <<'VER'
'=='
VER

puts VERSION_STRING % BeakerDocker::VERSION
case ARGV[0]
when 'containerfile'
dockerfile(ARGV[1], ARGV[2] || 'Containerfile')
when 'dockerfile'
dockerfile(ARGV[1], ARGV[2] || 'Dockerfile')
else
puts VERSION_STRING % BeakerDocker::VERSION
end

exit 0

0 comments on commit e13be08

Please sign in to comment.