Merge pull request #7957 from milescrabill/fix-vagrant-builder-basebox-sourcebox

vagrant builder: fix provisioning boxes, define source and output boxes
This commit is contained in:
Megan Marsh 2019-08-19 13:25:54 -07:00 committed by GitHub
commit dd97435d42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 4 deletions

View File

@ -199,6 +199,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
&StepCreateVagrantfile{
Template: b.config.Template,
SyncedFolder: b.config.SyncedFolder,
SourceBox: b.config.SourceBox,
BoxName: b.config.BoxName,
OutputDir: b.config.OutputDir,
GlobalID: b.config.GlobalID,

View File

@ -17,11 +17,18 @@ type StepCreateVagrantfile struct {
OutputDir string
SyncedFolder string
GlobalID string
SourceBox string
BoxName string
}
var DEFAULT_TEMPLATE = `Vagrant.configure("2") do |config|
config.vm.box = "{{.BoxName}}"
config.vm.define "source", autostart: false do |source|
source.vm.box = "{{.SourceBox}}"
end
config.vm.define "output" do |output|
output.vm.box = "{{.BoxName}}"
output.vm.box_url = "file://package.box"
end
{{ if ne .SyncedFolder "" -}}
config.vm.synced_folder "{{.SyncedFolder}}", "/vagrant"
{{- else -}}
@ -31,6 +38,7 @@ end`
type VagrantfileOptions struct {
SyncedFolder string
SourceBox string
BoxName string
}
@ -57,6 +65,7 @@ func (s *StepCreateVagrantfile) createVagrantfile() (string, error) {
opts := &VagrantfileOptions{
SyncedFolder: s.SyncedFolder,
BoxName: s.BoxName,
SourceBox: s.SourceBox,
}
err = tpl.Execute(templateFile, opts)

View File

@ -20,6 +20,7 @@ func TestStepCreateVagrantfile_Impl(t *testing.T) {
func TestCreateFile(t *testing.T) {
testy := StepCreateVagrantfile{
OutputDir: "./",
SourceBox: "apples",
BoxName: "bananas",
}
templatePath, err := testy.createVagrantfile()
@ -30,7 +31,13 @@ func TestCreateFile(t *testing.T) {
contents, err := ioutil.ReadFile(templatePath)
actual := string(contents)
expected := `Vagrant.configure("2") do |config|
config.vm.box = "bananas"
config.vm.define "source", autostart: false do |source|
source.vm.box = "apples"
end
config.vm.define "output" do |output|
output.vm.box = "bananas"
output.vm.box_url = "file://package.box"
end
config.vm.synced_folder ".", "/vagrant", disabled: true
end`
if ok := strings.Compare(actual, expected); ok != 0 {
@ -51,7 +58,13 @@ func TestCreateFile_customSync(t *testing.T) {
contents, err := ioutil.ReadFile(templatePath)
actual := string(contents)
expected := `Vagrant.configure("2") do |config|
config.vm.box = ""
config.vm.define "source", autostart: false do |source|
source.vm.box = ""
end
config.vm.define "output" do |output|
output.vm.box = ""
output.vm.box_url = "file://package.box"
end
config.vm.synced_folder "myfolder/foldertimes", "/vagrant"
end`
if ok := strings.Compare(actual, expected); ok != 0 {

View File

@ -20,7 +20,8 @@ func (s *StepUp) Run(ctx context.Context, state multistep.StateBag) multistep.St
ui.Say("Calling Vagrant Up...")
var args []string
// start only the source box
args := []string{"source"}
if s.GlobalID != "" {
args = append(args, s.GlobalID)
}