diff --git a/builder/oracle/classic/builder.go b/builder/oracle/classic/builder.go index 11c969273..425487ff5 100644 --- a/builder/oracle/classic/builder.go +++ b/builder/oracle/classic/builder.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/go-oracle-terraform/opc" ocommon "github.com/hashicorp/packer/builder/oracle/common" "github.com/hashicorp/packer/common" - "github.com/hashicorp/packer/common/uuid" "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" @@ -61,13 +60,14 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe return nil, fmt.Errorf("Error creating OPC Compute Client: %s", err) } + runID := os.Getenv("PACKER_RUN_UUID") // Populate the state bag state := new(multistep.BasicStateBag) state.Put("config", b.config) state.Put("hook", hook) state.Put("ui", ui) state.Put("client", client) - runID := uuid.TimeOrderedUUID() + state.Put("run_id", runID) var steps []multistep.Step if b.config.IsPV() { diff --git a/builder/oracle/classic/pv_config.go b/builder/oracle/classic/pv_config.go index 4ac48ac1a..e335371b3 100644 --- a/builder/oracle/classic/pv_config.go +++ b/builder/oracle/classic/pv_config.go @@ -42,7 +42,7 @@ chmod u+x jq # Create manifest file ( for i in segment_*; do - ./jq -n --arg path "compute_images_segments/{{.ImageName}}/$i" \ + ./jq -n --arg path "{{.SegmentPath}}/$i" \ --arg etag $(md5sum $i | cut -f1 -d' ') \ --arg size_bytes $(stat --printf "%s" $i) \ '{path: $path, etag: $etag, size_bytes: $size_bytes}' @@ -59,25 +59,25 @@ export AUTH_TOKEN=$(awk 'BEGIN {FS=": "; RS="\r\n"}/^X-Auth-Token/{print $2}' au export STORAGE_URL=$(awk 'BEGIN {FS=": "; RS="\r\n"}/^X-Storage-Url/{print $2}' auth-headers) # Create segment directory -curl -v -X PUT -H "X-Auth-Token: $AUTH_TOKEN" ${STORAGE_URL}/compute_images_segments/{{.ImageName}} +curl -v -X PUT -H "X-Auth-Token: $AUTH_TOKEN" ${STORAGE_URL}/{{.SegmentPath}} # Upload segments for i in segment_*; do curl -v -X PUT -T $i \ -H "X-Auth-Token: $AUTH_TOKEN" \ - ${STORAGE_URL}/compute_images_segments/{{.ImageName}}/$i; + ${STORAGE_URL}/{{.SegmentPath}}/$i; done # Create machine image from manifest curl -v -X PUT \ -H "X-Auth-Token: $AUTH_TOKEN" \ - "${STORAGE_URL}/compute_images/{{.ImageName}}.tar.gz?multipart-manifest=put" \ + "${STORAGE_URL}/compute_images/{{.ImageFile}}?multipart-manifest=put" \ -T ./manifest.json # Get uploaded image description curl -I -X HEAD \ -H "X-Auth-Token: $AUTH_TOKEN" \ - "${STORAGE_URL}/compute_images/{{.ImageName}}.tar.gz" + "${STORAGE_URL}/compute_images/{{.ImageFile}}" ` } /* diff --git a/builder/oracle/classic/step_create_image.go b/builder/oracle/classic/step_create_image.go index 34f0ef23d..d2d19f4a6 100644 --- a/builder/oracle/classic/step_create_image.go +++ b/builder/oracle/classic/step_create_image.go @@ -18,10 +18,11 @@ type stepCreateImage struct { } type uploadCmdData struct { - Username string - Password string - AccountID string - ImageName string + Username string + Password string + AccountID string + ImageFile string + SegmentPath string } func (s *stepCreateImage) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { @@ -30,12 +31,16 @@ func (s *stepCreateImage) Run(_ context.Context, state multistep.StateBag) multi comm := state.Get("communicator").(packer.Communicator) client := state.Get("client").(*compute.ComputeClient) config := state.Get("config").(*Config) + runID := state.Get("run_id").(string) + + imageFile := fmt.Sprintf("%s.tar.gz", s.imageName) config.ctx.Data = uploadCmdData{ - Username: config.Username, - Password: config.Password, - AccountID: config.IdentityDomain, - ImageName: s.imageName, + Username: config.Username, + Password: config.Password, + AccountID: config.IdentityDomain, + ImageFile: imageFile, + SegmentPath: fmt.Sprintf("compute_images_segments/%s/_segment_/%s", imageFile, runID), } uploadImageCmd, err := interpolate.Render(s.uploadImageCommand, &config.ctx) if err != nil { @@ -86,7 +91,7 @@ func (s *stepCreateImage) Run(_ context.Context, state multistep.StateBag) multi // The three-part name of the object Name: s.imageName, // 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), + File: imageFile, } log.Printf("CreateMachineImageInput: %+v", createMI) mi, err := machineImageClient.CreateMachineImage(createMI)