Add box if not found in box collection

This commit is contained in:
sophia 2021-11-16 11:56:34 -06:00 committed by Paul Hinze
parent a233cbefbb
commit d786649e03
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
3 changed files with 12 additions and 14 deletions

2
Vagrantfile vendored
View File

@ -44,7 +44,7 @@ Vagrant.configure("2") do |config|
config.vm.define "one" do |c|
c.vm.hostname = "one"
c.vm.usable_port_range = 8070..8090
c.vm.box = "bento/ubuntu"
c.vm.box = "bento/ubuntu-16.04"
c.vm.provision "shell", inline: "echo hello world"
c.vm.provision "shell" do |s|
s.inline = "echo goodbye"

View File

@ -207,6 +207,7 @@ func (b *Basis) Boxes() (bc *BoxCollection, err error) {
b.boxCollection = &BoxCollection{
basis: b,
directory: filepath.Join(b.dir.DataDir().String(), "boxes"),
logger: b.logger,
}
}
return b.boxCollection, nil

View File

@ -4,7 +4,6 @@ import (
"context"
"errors"
"os"
"path/filepath"
"strings"
"sync"
@ -440,21 +439,19 @@ func (p *Project) InitTargets() (err error) {
// TODO: get provider info here too/generate full machine config?
// We know that these are machines so, save the Machine record
machineRecord := &vagrant_server.Target_Machine{}
// TODO: create a new box for now. This should be querying the box collection
// for a box that matches the provided provider and name
doxDir := filepath.Join(p.basis.dir.DataDir().String(), "boxes/hashicorp-VAGRANTSLASH-bionic64/1.0.282/virtualbox/")
b, erro := NewBox(
BoxWithBasis(p.basis),
BoxWithName(t.ConfigVm.Box),
// TODO: need to get this box info from the vagrantfile/provider
BoxWithProvider("virtualbox"),
BoxWithVersion("1.0.282"),
BoxWithDirectory(doxDir),
)
boxes, _ := p.Boxes()
b, erro := boxes.Find(t.ConfigVm.Box, "")
if erro != nil {
return erro
}
machineRecord.Box = b.ToProto()
if b == nil {
// Add the box
b, erro = addBox(t.ConfigVm.Box, "virtualbox", p.basis)
if erro != nil {
return nil
}
}
machineRecord.Box = b.(*Box).ToProto()
machineRecordAny, erro := anypb.New(machineRecord)
if err != nil {
p.logger.Debug("Error generating machine record for target",