Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add vagrant architecture support #491

Merged
merged 8 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions lib/kitchen/driver/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class Vagrant < Kitchen::Driver::Base

default_config :box_version, nil

default_config :box_arch, nil

default_config :boot_timeout, nil

default_config :customize, {}
Expand Down Expand Up @@ -125,7 +127,7 @@ def create(state)
# @return [String,nil] the Vagrant box for this Instance
def default_box
if bento_box?(instance.platform.name)
"bento/#{instance.platform.name}#{"-arm64" if RbConfig::CONFIG["host_cpu"].eql?("arm64")}"
"bento/#{instance.platform.name}"
else
instance.platform.name
end
Expand Down Expand Up @@ -225,7 +227,7 @@ def cache_directory
protected

WEBSITE = "https://www.vagrantup.com/downloads.html".freeze
tas50 marked this conversation as resolved.
Show resolved Hide resolved
MIN_VER = "1.1.0".freeze
MIN_VER = "2.4.0".freeze

class << self

Expand Down Expand Up @@ -313,14 +315,21 @@ def finalize_ca_cert!
def finalize_box_auto_update!
return if config[:box_auto_update].nil?

config[:box_auto_update] = "vagrant box update #{"--insecure " if config[:box_download_insecure]}--box #{config[:box]} --provider #{config[:provider]}"
cmd = "#{config[:vagrant_binary]} box update --box #{config[:box]}"
cmd += " --architecture #{config[:box_arch]}" if config[:box_arch]
cmd += " --provider #{config[:provider]}" if config[:provider]
cmd += " --insecure" if config[:box_download_insecure]
config[:box_auto_update] = cmd
end

# Create vagrant command to remove older versions of the box
def finalize_box_auto_prune!
return if config[:box_auto_prune].nil?

config[:box_auto_prune] = "vagrant box prune --force --keep-active-boxes --name #{config[:box]} --provider #{config[:provider]}"
cmd = "#{config[:vagrant_binary]} box prune --force --keep-active-boxes --name #{config[:box]}"
cmd += " --architecture #{config[:box_arch]}" if config[:box_arch]
cmd += " --provider #{config[:provider]}" if config[:provider]
config[:box_auto_prune] = cmd
end

# Replaces any `{{vagrant_root}}` tokens in the pre create command.
Expand Down
6 changes: 3 additions & 3 deletions spec/kitchen/driver/vagrant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def run_command(_cmd, options = {})
with_unsupported_vagrant

expect { driver.verify_dependencies }.to raise_error(
Kitchen::UserError, /Please upgrade to version 1.1.0 or higher/
Kitchen::UserError, /Please upgrade to version 2.4.0 or higher/
)
end

Expand All @@ -551,7 +551,7 @@ def run_command(_cmd, options = {})
.with("vagrant --version", any_args).and_raise(Errno::ENOENT)

expect { driver.verify_dependencies }.to raise_error(
Kitchen::UserError, /Vagrant 1.1.0 or higher is not installed/
Kitchen::UserError, /Vagrant 2.4.0 or higher is not installed/
)
end
end
Expand Down Expand Up @@ -2139,7 +2139,7 @@ def debug_lines
end

def with_modern_vagrant
with_vagrant("1.7.2")
with_vagrant("2.4.1")
end

def with_unsupported_vagrant
Expand Down
4 changes: 4 additions & 0 deletions templates/Vagrantfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Vagrant.configure("2") do |c|
c.vm.box_version = "<%= config[:box_version] %>"
<% end %>
<% if config[:box_arch] %>
c.vm.box_architecture = "<%= config[:box_arch] %>"
<% end %>
<% if !config[:box_check_update].nil? %>
c.vm.box_check_update = <%= config[:box_check_update] %>
<% end %>
Expand Down