Class: VagrantPlugins::AVF::BoxPackage
- Inherits:
-
Object
- Object
- VagrantPlugins::AVF::BoxPackage
- Defined in:
- lib/vagrant_provider_avf/box_package.rb
Constant Summary collapse
- PROVIDER =
"avf".freeze
- ARCHITECTURE =
"arm64".freeze
- USERNAME =
"vagrant".freeze
Instance Attribute Summary collapse
-
#disk_image_path ⇒ Object
readonly
Returns the value of attribute disk_image_path.
-
#guest ⇒ Object
readonly
Returns the value of attribute guest.
-
#initrd_path ⇒ Object
readonly
Returns the value of attribute initrd_path.
-
#kernel_path ⇒ Object
readonly
Returns the value of attribute kernel_path.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#private_key_path ⇒ Object
readonly
Returns the value of attribute private_key_path.
-
#release ⇒ Object
readonly
Returns the value of attribute release.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #archive_name ⇒ Object
- #artifact_entries ⇒ Object
- #info ⇒ Object
- #info_json ⇒ Object
-
#initialize(name:, version:, release:, guest:, kernel_path:, initrd_path:, disk_image_path:, private_key_path:, description: nil, disk_gb: nil) ⇒ BoxPackage
constructor
A new instance of BoxPackage.
- #metadata ⇒ Object
- #metadata_json ⇒ Object
- #vagrantfile ⇒ Object
- #validate! ⇒ Object
- #write_archive(output_dir:, tar_command: "bsdtar") ⇒ Object
- #write_checksum(output_path) ⇒ Object
Constructor Details
#initialize(name:, version:, release:, guest:, kernel_path:, initrd_path:, disk_image_path:, private_key_path:, description: nil, disk_gb: nil) ⇒ BoxPackage
Returns a new instance of BoxPackage.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 16 def initialize(name:, version:, release:, guest:, kernel_path:, initrd_path:, disk_image_path:, private_key_path:, description: nil, disk_gb: nil) @name = name.to_s @version = version.to_s @release = release.to_s @guest = guest.to_sym @kernel_path = kernel_path && File.(kernel_path) @initrd_path = initrd_path && File.(initrd_path) @disk_image_path = File.(disk_image_path) @private_key_path = File.(private_key_path) @description = description @disk_gb = disk_gb && Integer(disk_gb) end |
Instance Attribute Details
#disk_image_path ⇒ Object (readonly)
Returns the value of attribute disk_image_path.
14 15 16 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 14 def disk_image_path @disk_image_path end |
#guest ⇒ Object (readonly)
Returns the value of attribute guest.
14 15 16 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 14 def guest @guest end |
#initrd_path ⇒ Object (readonly)
Returns the value of attribute initrd_path.
14 15 16 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 14 def initrd_path @initrd_path end |
#kernel_path ⇒ Object (readonly)
Returns the value of attribute kernel_path.
14 15 16 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 14 def kernel_path @kernel_path end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 14 def name @name end |
#private_key_path ⇒ Object (readonly)
Returns the value of attribute private_key_path.
14 15 16 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 14 def private_key_path @private_key_path end |
#release ⇒ Object (readonly)
Returns the value of attribute release.
14 15 16 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 14 def release @release end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
14 15 16 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 14 def version @version end |
Instance Method Details
#archive_name ⇒ Object
38 39 40 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 38 def archive_name "#{name.tr('/', '-')}-#{version}.box" end |
#artifact_entries ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 60 def artifact_entries entries = { "box/disk.img" => @disk_image_path, "box/insecure_private_key" => @private_key_path } return entries unless linux_kernel_artifacts? entries.merge( "box/vmlinuz" => @kernel_path, "box/initrd.img" => @initrd_path ) end |
#info ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 52 def info { "name" => @name, "version" => @version, "description" => description } end |
#info_json ⇒ Object
77 78 79 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 77 def info_json JSON.pretty_generate(info) << "\n" end |
#metadata ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 42 def { "provider" => PROVIDER, "architecture" => ARCHITECTURE, "guest" => @guest.to_s, "format" => format, "release" => @release } end |
#metadata_json ⇒ Object
73 74 75 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 73 def JSON.pretty_generate() << "\n" end |
#vagrantfile ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 101 def vagrantfile ( <<~RUBY Vagrant.configure("2") do |config| config.vm.communicator = "ssh" RUBY ) + default_synced_folder_vagrantfile + ssh_shell_vagrantfile + ( <<~RUBY config.ssh.username = "#{USERNAME}" config.ssh.keys_only = true config.ssh.insert_key = false config.ssh.private_key_path = File.expand_path("box/insecure_private_key", __dir__) config.vm.provider :avf do |avf| avf.headless = true avf.guest = :#{@guest} RUBY ) + kernel_vagrantfile + ( <<~RUBY #{disk_gb_vagrantfile} avf.disk_image_path = File.expand_path("box/disk.img", __dir__) end end RUBY ) end |
#validate! ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 29 def validate! raise ArgumentError, "guest must be one of: linux" unless @guest == :linux missing_paths = artifact_entries.values.reject { |path| File.file?(path) } return self if missing_paths.empty? raise ArgumentError, "missing required box artifact: #{missing_paths.join(', ')}" end |
#write_archive(output_dir:, tar_command: "bsdtar") ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 81 def write_archive(output_dir:, tar_command: "bsdtar") output_path = Pathname.new(output_dir).join(archive_name) output_path.dirname.mkpath Dir.mktmpdir("avf-box") do |staging| stage_archive(staging) build_archive(output_path, staging, tar_command) end output_path end |
#write_checksum(output_path) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/vagrant_provider_avf/box_package.rb', line 93 def write_checksum(output_path) output_path = Pathname.new(output_path) checksum_path = output_path.dirname.join("#{output_path.basename}.sha256") checksum = Digest::SHA256.file(output_path).hexdigest checksum_path.write("#{checksum} #{output_path.basename}\n") checksum_path end |