From 96e62236ec6306a5e34d6f3f2abf6cf07dfc5662 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Wed, 17 Oct 2018 20:16:23 -0700 Subject: [PATCH] upload volume WIP check upload for error increase builder volume size to account for chunking --- builder/oracle/classic/builder.go | 5 ++++- builder/oracle/classic/pv_config.go | 25 ++++++++++++++++++++- builder/oracle/classic/step_create_image.go | 9 +++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/builder/oracle/classic/builder.go b/builder/oracle/classic/builder.go index bab170e3e..1db9ca84b 100644 --- a/builder/oracle/classic/builder.go +++ b/builder/oracle/classic/builder.go @@ -79,7 +79,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe bootable: true, }, &stepCreatePersistentVolume{ - volumeSize: fmt.Sprintf("%d", b.config.PersistentVolumeSize*2), + // We multiple the master volume size by 3, because we need to + // copy the original data 3 times: the data itself, the + // tarball, and the chunks + volumeSize: fmt.Sprintf("%d", b.config.PersistentVolumeSize*3), volumeName: fmt.Sprintf("builder-storage_%s", runID), }, &ocommon.StepKeyPair{ diff --git a/builder/oracle/classic/pv_config.go b/builder/oracle/classic/pv_config.go index db5599386..76471cd85 100644 --- a/builder/oracle/classic/pv_config.go +++ b/builder/oracle/classic/pv_config.go @@ -28,7 +28,30 @@ func (c *PVConfig) Prepare(ctx *interpolate.Context) (errs *packer.MultiError) { } if c.BuilderUploadImageCommand == "" { - c.BuilderUploadImageCommand = `curl --connect-timeout 5 \ + c.BuilderUploadImageCommand = `split -b 10m diskimage.tar.gz segment_ + +curl -D auth-headers -s -X GET -H "X-Storage-User: Storage-a459477:jake@hashicorp.com" -H "X-Storage-Pass: ***REMOVED***" https://a459477.storage.oraclecloud.com/auth/v1.0 + +export AUTH_TOKEN=$(awk 'BEGIN {FS=": "; RS="\r\n"}/^X-Auth-Token/{print $2}' auth-headers) +export STORAGE_URL=$(awk 'BEGIN {FS=": "; RS="\r\n"}/^X-Storage-Url/{print $2}' auth-headers) + +curl -v -X PUT -H "X-Auth-Token: $AUTH_TOKEN" ${STORAGE_URL}/mwhooker-test-1 + +for i in segment_*; do + curl -v -X PUT -T $i \ + -H "X-Auth-Token: $AUTH_TOKEN" \ + ${STORAGE_URL}/mwhooker-test-1/$i; +done + +( +echo [ +for i in segment_*; do + printf '{"path": "%s", "etag": "%s", "size_bytes": %s},\n' "mwhooker-test-1/$i" $(md5sum $i | cut -f1 -d' ') $(stat --printf "%s" $i) +done +echo ] +) > manifest.json + +curl --connect-timeout 5 \ --max-time 3600 \ --retry 5 \ --retry-delay 0 \ diff --git a/builder/oracle/classic/step_create_image.go b/builder/oracle/classic/step_create_image.go index 8162b6629..113ba6040 100644 --- a/builder/oracle/classic/step_create_image.go +++ b/builder/oracle/classic/step_create_image.go @@ -52,7 +52,14 @@ func (s *stepCreateImage) Run(_ context.Context, state multistep.StateBag) multi Command: fmt.Sprintf("sudo /bin/sh %s", dest), } if err := cmd.StartWithUi(comm, ui); err != nil { - err = fmt.Errorf("Problem creating volume: %s", err) + err = fmt.Errorf("Problem creating image`: %s", err) + ui.Error(err.Error()) + state.Put("error", err) + return multistep.ActionHalt + } + + if cmd.ExitStatus != 0 { + err = fmt.Errorf("Create Disk Image command failed with exit code %d", cmd.ExitStatus) ui.Error(err.Error()) state.Put("error", err) return multistep.ActionHalt