Segments going into per-run subfolder
This commit is contained in:
parent
b5c6beb8a3
commit
b84c7df9da
|
@ -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() {
|
||||
|
|
|
@ -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}}"
|
||||
`
|
||||
}
|
||||
/*
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue