builder instance now runs and is connected to
This commit is contained in:
parent
b3ffa975c3
commit
7c26ffef9c
|
@ -106,9 +106,13 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
&stepTerminatePVMaster{},
|
&stepTerminatePVMaster{},
|
||||||
&stepCreatePVBuilder{
|
&stepCreatePVBuilder{
|
||||||
name: fmt.Sprintf("builder-instance_%s", runID),
|
name: fmt.Sprintf("builder-instance_%s", runID),
|
||||||
masterVolumeName: fmt.Sprintf("master-storage_%s", runID),
|
|
||||||
builderVolumeName: fmt.Sprintf("builder-storage_%s", runID),
|
builderVolumeName: fmt.Sprintf("builder-storage_%s", runID),
|
||||||
},
|
},
|
||||||
|
&stepAttachVolume{
|
||||||
|
volumeName: fmt.Sprintf("master-storage_%s", runID),
|
||||||
|
index: 2,
|
||||||
|
instanceInfoKey: "builder_instance_info",
|
||||||
|
},
|
||||||
&communicator.StepConnect{
|
&communicator.StepConnect{
|
||||||
Config: &b.config.Comm,
|
Config: &b.config.Comm,
|
||||||
Host: ocommon.CommHost,
|
Host: ocommon.CommHost,
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
package classic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-oracle-terraform/compute"
|
||||||
|
"github.com/hashicorp/packer/helper/multistep"
|
||||||
|
"github.com/hashicorp/packer/packer"
|
||||||
|
)
|
||||||
|
|
||||||
|
type stepAttachVolume struct {
|
||||||
|
index int
|
||||||
|
volumeName string
|
||||||
|
instanceInfoKey string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepAttachVolume) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
|
client := state.Get("client").(*compute.ComputeClient)
|
||||||
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
instanceInfo := state.Get(s.instanceInfoKey).(*compute.InstanceInfo)
|
||||||
|
|
||||||
|
saClient := client.StorageAttachments()
|
||||||
|
saInput := &compute.CreateStorageAttachmentInput{
|
||||||
|
Index: s.index,
|
||||||
|
InstanceName: instanceInfo.Name + "/" + instanceInfo.ID,
|
||||||
|
StorageVolumeName: s.volumeName,
|
||||||
|
}
|
||||||
|
|
||||||
|
sa, err := saClient.CreateStorageAttachment(saInput)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("Problem attaching master volume: %s", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
state.Put("error", err)
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
|
state.Put(s.instanceInfoKey+"/attachment", sa)
|
||||||
|
|
||||||
|
ui.Message("Volume to master attached to builder instance")
|
||||||
|
return multistep.ActionContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepAttachVolume) Cleanup(state multistep.StateBag) {
|
||||||
|
sa, ok := state.GetOk(s.instanceInfoKey + "/attachment")
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
client := state.Get("client").(*compute.ComputeClient)
|
||||||
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
|
saClient := client.StorageAttachments()
|
||||||
|
saI := &compute.DeleteStorageAttachmentInput{
|
||||||
|
Name: sa.(*compute.StorageAttachmentInfo).Name,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := saClient.DeleteStorageAttachment(saI); err != nil {
|
||||||
|
err = fmt.Errorf("Problem detaching storage volume: %s", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
state.Put("error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,8 @@ package classic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/packer/helper/multistep"
|
"github.com/hashicorp/packer/helper/multistep"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
|
@ -13,31 +15,27 @@ func (s *stepCreateImage) Run(_ context.Context, state multistep.StateBag) multi
|
||||||
//hook := state.Get("hook").(packer.Hook)
|
//hook := state.Get("hook").(packer.Hook)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
comm := state.Get("communicator").(packer.Communicator)
|
comm := state.Get("communicator").(packer.Communicator)
|
||||||
commands := []string{
|
command := `#!/bin/sh
|
||||||
"mkdir ./builder",
|
set -e
|
||||||
"sudo mkfs -t ext3 /dev/xvdb",
|
mkdir /builder
|
||||||
"sudo mount /dev/xvdb ./builder",
|
mkfs -t ext3 /dev/xvdb
|
||||||
"sudo chown opc:opc ./builder",
|
mount /dev/xvdb /builder
|
||||||
"cd ./builder",
|
chown opc:opc /builder
|
||||||
"sudo dd if=/dev/xvdc bs=8M status=progress | cp --sparse=always /dev/stdin diskimage.raw",
|
cd /builder
|
||||||
"tar czSf ./diskimage.tar.gz ./diskimage.raw",
|
dd if=/dev/xvdc bs=8M status=progress | cp --sparse=always /dev/stdin diskimage.raw
|
||||||
}
|
tar czSf ./diskimage.tar.gz ./diskimage.raw`
|
||||||
for _, c := range commands {
|
|
||||||
cmd := packer.RemoteCmd{
|
|
||||||
Command: c,
|
|
||||||
}
|
|
||||||
cmd.StartWithUi(comm, ui)
|
|
||||||
}
|
|
||||||
// comm.Start("
|
|
||||||
|
|
||||||
/*
|
dest := "/tmp/create-packer-diskimage.sh"
|
||||||
// Provision
|
comm.Upload(dest, strings.NewReader(command), nil)
|
||||||
log.Println("Running the provision hook")
|
cmd := &packer.RemoteCmd{
|
||||||
if err := hook.Run(packer.HookProvision, ui, comm, nil); err != nil {
|
Command: fmt.Sprintf("sudo /bin/sh %s", dest),
|
||||||
|
}
|
||||||
|
if err := cmd.StartWithUi(comm, ui); err != nil {
|
||||||
|
err = fmt.Errorf("Problem creating volume: %s", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
|
|
||||||
type stepCreatePVBuilder struct {
|
type stepCreatePVBuilder struct {
|
||||||
name string
|
name string
|
||||||
masterVolumeName string
|
|
||||||
builderVolumeName string
|
builderVolumeName string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,22 +58,10 @@ func (s *stepCreatePVBuilder) Run(_ context.Context, state multistep.StateBag) m
|
||||||
}
|
}
|
||||||
log.Printf("Created instance %s", instanceInfo.Name)
|
log.Printf("Created instance %s", instanceInfo.Name)
|
||||||
|
|
||||||
saClient := client.StorageAttachments()
|
|
||||||
saInput := &compute.CreateStorageAttachmentInput{
|
|
||||||
Index: 3,
|
|
||||||
InstanceName: s.name,
|
|
||||||
StorageVolumeName: s.masterVolumeName,
|
|
||||||
}
|
|
||||||
if _, err := saClient.CreateStorageAttachment(saInput); err != nil {
|
|
||||||
err = fmt.Errorf("Problem attaching master volume: %s", err)
|
|
||||||
ui.Error(err.Error())
|
|
||||||
state.Put("error", err)
|
|
||||||
return multistep.ActionHalt
|
|
||||||
}
|
|
||||||
|
|
||||||
state.Put("builder_instance_info", instanceInfo)
|
state.Put("builder_instance_info", instanceInfo)
|
||||||
state.Put("builder_instance_id", instanceInfo.ID)
|
state.Put("builder_instance_id", instanceInfo.ID)
|
||||||
ui.Message(fmt.Sprintf("Created builder instance: %s.", instanceInfo.ID))
|
|
||||||
|
ui.Message(fmt.Sprintf("Created builder instance: %s.", instanceInfo.Name))
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,4 +92,5 @@ func (s *stepCreatePVBuilder) Cleanup(state multistep.StateBag) {
|
||||||
}
|
}
|
||||||
// TODO wait for instance state to change to deleted?
|
// TODO wait for instance state to change to deleted?
|
||||||
ui.Say("Terminated builder instance.")
|
ui.Say("Terminated builder instance.")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ func (s *stepCreatePVMaster) Run(_ context.Context, state multistep.StateBag) mu
|
||||||
|
|
||||||
state.Put("master_instance_info", instanceInfo)
|
state.Put("master_instance_info", instanceInfo)
|
||||||
state.Put("master_instance_id", instanceInfo.ID)
|
state.Put("master_instance_id", instanceInfo.ID)
|
||||||
ui.Message(fmt.Sprintf("Created master instance: %s.", instanceInfo.ID))
|
ui.Message(fmt.Sprintf("Created master instance: %s.", instanceInfo.Name))
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue