From 7a35e2408fbcbf3c791d708e233d25339127b27d Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Thu, 18 Oct 2018 00:39:41 -0700 Subject: [PATCH] fix pty, some todo and refactor of bash scri[t --- builder/oracle/classic/builder.go | 5 +++- builder/oracle/classic/pv_config.go | 31 ++++++++++----------- builder/oracle/classic/step_create_image.go | 3 ++ 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/builder/oracle/classic/builder.go b/builder/oracle/classic/builder.go index da7975dd4..bb449cfbb 100644 --- a/builder/oracle/classic/builder.go +++ b/builder/oracle/classic/builder.go @@ -71,6 +71,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe var steps []multistep.Step if b.config.IsPV() { + builderCommConfig := b.config.Comm + builderCommConfig.SSHPty = true + steps = []multistep.Step{ &stepCreatePersistentVolume{ volumeSize: fmt.Sprintf("%d", b.config.PersistentVolumeSize), @@ -114,7 +117,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe instanceInfoKey: "builder_instance_info", }, &communicator.StepConnect{ - Config: &b.config.Comm, + Config: &builderCommConfig, Host: ocommon.CommHost, SSHConfig: b.config.Comm.SSHConfigFunc(), }, diff --git a/builder/oracle/classic/pv_config.go b/builder/oracle/classic/pv_config.go index 28123a883..960a2b0da 100644 --- a/builder/oracle/classic/pv_config.go +++ b/builder/oracle/classic/pv_config.go @@ -34,6 +34,21 @@ func (c *PVConfig) Prepare(ctx *interpolate.Context) (errs *packer.MultiError) { # Split diskimage in to 100mb chunks split -b 100m diskimage.tar.gz segment_ +# Download jq tool +curl -OL https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 +mv jq-linux64 jq +chmod u+x jq + +# Create manifest file +( +for i in segment_*; do + ./jq -n --arg path "{{.Container}}/$i" \ + --arg etag $(md5sum $i | cut -f1 -d' ') \ + --arg size_bytes $(stat --printf "%s" $i) \ + '{path: $path, etag: $etag, size_bytes: $size_bytes}' +done +) | ./jq -s . > manifest.json + # Authenticate curl -D auth-headers -s -X GET \ -H "X-Storage-User: Storage-{{.AccountID}}:{{.Username}}" \ @@ -53,21 +68,6 @@ for i in segment_*; do ${STORAGE_URL}/{{.Container}}/$i; done -# Download jq tool -curl -OL https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 -mv jq-linux64 jq -chmod u+x jq - -# Create manifest file -( -for i in segment_*; do - ./jq -n --arg path "{{.Container}}/$i" \ - --arg etag $(md5sum $i | cut -f1 -d' ') \ - --arg size_bytes $(stat --printf "%s" $i) \ - '{path: $path, etag: $etag, size_bytes: $size_bytes}' -done -) | ./jq -s . > manifest.json - # Create machine image from manifest curl -v -X PUT \ -H "X-Auth-Token: $AUTH_TOKEN" \ @@ -79,7 +79,6 @@ curl -I -X HEAD \ -H "X-Auth-Token: $AUTH_TOKEN" \ "${STORAGE_URL}/compute_images/{{.ImageName}}.tar.gz" - # Delete {{.Container}} # following https://docs.oracle.com/en/cloud/iaas/storage-cloud/cssto/deleting-multiple-objects-single-operation.html diff --git a/builder/oracle/classic/step_create_image.go b/builder/oracle/classic/step_create_image.go index 1500fb908..6ae3e75f4 100644 --- a/builder/oracle/classic/step_create_image.go +++ b/builder/oracle/classic/step_create_image.go @@ -50,6 +50,7 @@ func (s *stepCreateImage) Run(_ context.Context, state multistep.StateBag) multi command := fmt.Sprintf(`#!/bin/sh set -e + set -x mkdir /builder mkfs -t ext3 /dev/xvdb mount /dev/xvdb /builder @@ -90,6 +91,7 @@ func (s *stepCreateImage) Run(_ context.Context, state multistep.StateBag) multi // image_file.tar.gz, where image_file is the .tar.gz name of the machine image file that you have uploaded to Oracle Cloud Infrastructure Object Storage Classic. File: fmt.Sprintf("%s.tar.gz", s.imageName), } + log.Printf("CreateMachineImageInput: %+v", createMI) mi, err := machineImageClient.CreateMachineImage(createMI) if err != nil { err = fmt.Errorf("Error creating machine image: %s", err) @@ -106,6 +108,7 @@ func (s *stepCreateImage) Run(_ context.Context, state multistep.StateBag) multi 5. Configuration (master/builder images & entry, destination stuff, etc) 6. split master/builder image/connection config. i.e. build anything, master only linux 7. correct artifact + 8. hide password from logs */ //machineImageClient.CreateMachineImage()