move upload script to const
This commit is contained in:
parent
7331d6fc7f
commit
e2a0cbf7df
|
@ -11,6 +11,57 @@ import (
|
|||
const imageListDefault = "/oracle/public/OL_7.2_UEKR4_x86_64"
|
||||
const usernameDefault = "opc"
|
||||
const shapeDefault = "oc3"
|
||||
const uploadImageCommandDefault = `
|
||||
# https://www.oracle.com/webfolder/technetwork/tutorials/obe/cloud/objectstorage/upload_files_gt_5GB_REST_API/upload_files_gt_5GB_REST_API.html
|
||||
|
||||
# Split diskimage in to 100mb chunks
|
||||
split -b 100m diskimage.tar.gz segment_
|
||||
printf "Split diskimage into %s segments\n" $(ls segment_* | wc -l)
|
||||
|
||||
# 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 "{{.SegmentPath}}/$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}}" \
|
||||
-H "X-Storage-Pass: {{.Password}}" \
|
||||
https://{{.AccountID}}.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)
|
||||
|
||||
# Upload segments
|
||||
for i in segment_*; do
|
||||
echo "Uploading segment $i"
|
||||
|
||||
curl -s -X PUT -T $i \
|
||||
-H "X-Auth-Token: $AUTH_TOKEN" \
|
||||
${STORAGE_URL}/{{.SegmentPath}}/$i;
|
||||
done
|
||||
|
||||
# Create machine image from manifest
|
||||
curl -s -X PUT \
|
||||
-H "X-Auth-Token: $AUTH_TOKEN" \
|
||||
"${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/{{.ImageFile}}"
|
||||
`
|
||||
|
||||
type PVConfig struct {
|
||||
// PersistentVolumeSize lets us control the volume size by using persistent boot storage
|
||||
|
@ -76,57 +127,7 @@ func (c *PVConfig) Prepare(ctx *interpolate.Context) (errs *packer.MultiError) {
|
|||
}
|
||||
|
||||
if c.BuilderUploadImageCommand == "" {
|
||||
c.BuilderUploadImageCommand = `
|
||||
# https://www.oracle.com/webfolder/technetwork/tutorials/obe/cloud/objectstorage/upload_files_gt_5GB_REST_API/upload_files_gt_5GB_REST_API.html
|
||||
|
||||
# Split diskimage in to 100mb chunks
|
||||
split -b 100m diskimage.tar.gz segment_
|
||||
printf "Split diskimage into %s segments\n" $(ls segment_* | wc -l)
|
||||
|
||||
# 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 "{{.SegmentPath}}/$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}}" \
|
||||
-H "X-Storage-Pass: {{.Password}}" \
|
||||
https://{{.AccountID}}.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)
|
||||
|
||||
# Upload segments
|
||||
for i in segment_*; do
|
||||
echo "Uploading segment $i"
|
||||
|
||||
curl -s -X PUT -T $i \
|
||||
-H "X-Auth-Token: $AUTH_TOKEN" \
|
||||
${STORAGE_URL}/{{.SegmentPath}}/$i;
|
||||
done
|
||||
|
||||
# Create machine image from manifest
|
||||
curl -s -X PUT \
|
||||
-H "X-Auth-Token: $AUTH_TOKEN" \
|
||||
"${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/{{.ImageFile}}"
|
||||
`
|
||||
c.BuilderUploadImageCommand = uploadImageCommandDefault
|
||||
}
|
||||
|
||||
if es := c.BuilderComm.Prepare(ctx); len(es) > 0 {
|
||||
|
|
Loading…
Reference in New Issue