Skip to content

Commit

Permalink
fix: linting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkProminic authored Jan 9, 2024
1 parent 5c30988 commit b936a8b
Showing 1 changed file with 25 additions and 40 deletions.
65 changes: 25 additions & 40 deletions lib/vagrant-zones/action/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
require 'fileutils'
require 'pathname'
require 'log4r'
require 'vagrant/util/safe_chdir'
require 'vagrant/util/subprocess'
module VagrantPlugins
module ProviderZone
module Action
Expand Down Expand Up @@ -43,6 +41,7 @@ def call(env)
## Create Snapshot
tmp_dir = "#{Dir.pwd}/_tmp_package"
Dir.mkdir(tmp_dir)
Dir.chdir(tmp_dir)
datasetpath = "#{@machine.provider_config.boot['array']}/#{@machine.provider_config.boot['dataset']}/#{name}"
t = Time.new
datetime = %(#{t.year}-#{t.month}-#{t.day}-#{t.hour}:#{t.min}:#{t.sec})
Expand All @@ -60,20 +59,16 @@ def call(env)
files[file] = dest
end

if env['package.vagrantfile']
# Vagrantfiles are treated special and mapped to a specific file
files[env['package.vagrantfile']] = '_Vagrantfile'
end

# Verify the mapping
files.each_key do |from|
raise Vagrant::Errors::PackageIncludeMissing, file: from unless File.exist?(from)
end

copy_include_files(files, tmp_dir)
## Create a Vagrantfile or load from Users Defined File
vagrantfile_content = %{require 'yaml'
require File.expand_path("#{File.dirname(__FILE__)}/Hosts.rb")
settings = YAML::load(File.read("#{File.dirname(__FILE__)}/Hosts.yml"))
Vagrant.configure("2") do |config|
Hosts.configure(config, settings)
end}
File.write('./Vagrantfile', vagrantfile_content)

## Create the Metadata and Vagrantfile
Dir.chdir(tmp_dir)
files[env['package.vagrantfile']] = '_Vagrantfile' if env['package.vagrantfile']

metadata_content_hash = {
'provider' => 'zone',
Expand All @@ -83,18 +78,23 @@ def call(env)
'kernel' => kernel,
'url' => "https://app.vagrantup.com/#{vcc}/boxes/#{boxshortname}"
}

File.write('./metadata.json', metadata_content_hash)

user_vagrantfile = File.expand_path('Vagrantfile', __dir__)
vagrantfile_content = %{require 'yaml'
require File.expand_path("#{File.dirname(__FILE__)}/Hosts.rb")
settings = YAML::load(File.read("#{File.dirname(__FILE__)}/Hosts.yml"))
Vagrant.configure("2") do |config|
Hosts.configure(config, settings)
end}
vagrantfile_content = File.read(user_vagrantfile) if File.exist?(user_vagrantfile)
File.write('./Vagrantfile', vagrantfile_content)
# Verify the mapping
files.each_key do |from|
raise Vagrant::Errors::PackageIncludeMissing, file: from unless File.exist?(from)
end

files.each do |from, dest|
include_directory = Pathname.new(destination)
to = include_directory.join(dest)
FileUtils.mkdir_p(to.parent)
if File.directory?(from)
FileUtils.cp_r(Dir.glob(from), to.parent, preserve: true)
else
FileUtils.cp(from, to, preserve: true)
end
end

## Create the Box file
assemble_box(boxname)
Expand Down Expand Up @@ -122,21 +122,6 @@ def snapshot_send(datasetpath, destination, datetime, uii, config)
puts "#{@pfexec} zfs send -r #{datasetpath}/boot@vagrant_box#{datetime} > #{destination}" if result.zero? && config.debug
end

# This method copies the include files (passed in via command line) to the
# temporary directory so they are included in a sub-folder within the actual box
def copy_include_files(include_files, destination)
include_files.each do |from, dest|
include_directory = Pathname.new(destination)
to = include_directory.join(dest)
FileUtils.mkdir_p(to.parent)
if File.directory?(from)
FileUtils.cp_r(Dir.glob(from), to.parent, preserve: true)
else
FileUtils.cp(from, to, preserve: true)
end
end
end

def assemble_box(boxname)
is_linux = `bash -c '[[ "$(uname -a)" =~ "Linux" ]]'`
files = Dir.glob(File.join('.', '*'))
Expand Down

0 comments on commit b936a8b

Please sign in to comment.