From cd60f3286645d711c8437c924acaafa50bbde194 Mon Sep 17 00:00:00 2001 From: "Viktor A. Danilov" <49490318+zaglossus@users.noreply.github.com> Date: Wed, 26 Aug 2020 13:41:05 +0300 Subject: [PATCH] fix yandex-export aws: (#9814) 1. move aws validation before disk image creation 2. add `--region` option --- post-processor/yandex-export/script.go | 48 +++++++++++++------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/post-processor/yandex-export/script.go b/post-processor/yandex-export/script.go index d118babe1..8ff3063d0 100644 --- a/post-processor/yandex-export/script.go +++ b/post-processor/yandex-export/script.go @@ -43,7 +43,7 @@ Exit () { for i in ${PATHS}; do LOGDEST="${i}.exporter.log" echo "Uploading exporter log to ${LOGDEST}..." - aws s3 --endpoint-url=https://storage.yandexcloud.net cp /var/log/syslog ${LOGDEST} + aws s3 --region ru-central1 --endpoint-url=https://storage.yandexcloud.net cp /var/log/syslog ${LOGDEST} done exit $1 } @@ -58,6 +58,28 @@ echo "Disk name - ${DISKNAME}" echo "Export paths - ${PATHS}" echo "####################################" +echo "Detect Service Account ID..." +SERVICE_ACCOUNT_ID=$(GetServiceAccountId) +echo "Use Service Account ID: ${SERVICE_ACCOUNT_ID}" + +echo "Create static access key..." +SEC_json=$(yc iam access-key create --service-account-id ${SERVICE_ACCOUNT_ID} \ + --description "this key is for export image to storage" --format json) + +if [ $? -ne 0 ]; then + echo "Failed to create static access key." + exit 1 +fi + +echo "Setup env variables to access storage..." +eval "$(jq -r '@sh "export YC_SK_ID=\(.access_key.id); export AWS_ACCESS_KEY_ID=\(.access_key.key_id); export AWS_SECRET_ACCESS_KEY=\(.secret)"' <<<${SEC_json} )" + +echo "Check access to storage..." +if ! aws s3 --region ru-central1 --endpoint-url=https://storage.yandexcloud.net ls > /dev/null ; then + echo "Failed to access storage." + exit 1 +fi + echo "Creating disk from image to be exported..." if ! yc compute disk create --name ${DISKNAME} --source-image-id ${IMAGE_ID} --zone ${ZONE}; then echo "Failed to create disk." @@ -81,28 +103,6 @@ if ! yc compute instance detach-disk ${INSTANCE_ID} --disk-name ${DISKNAME} ; t echo "Failed to detach disk." fi -echo "Detect Service Account ID..." -SERVICE_ACCOUNT_ID=$(GetServiceAccountId) -echo "Use Service Account ID: ${SERVICE_ACCOUNT_ID}" - -echo "Create static access key..." -SEC_json=$(yc iam access-key create --service-account-id ${SERVICE_ACCOUNT_ID} \ - --description "this key is for export image to storage" --format json) - -if [ $? -ne 0 ]; then - echo "Failed to create static access key." - exit 1 -fi - -echo "Setup env variables to access storage..." -eval "$(jq -r '@sh "export YC_SK_ID=\(.access_key.id); export AWS_ACCESS_KEY_ID=\(.access_key.key_id); export AWS_SECRET_ACCESS_KEY=\(.secret)"' <<<${SEC_json} )" - -echo "Check access to storage..." -if ! aws s3 --endpoint-url=https://storage.yandexcloud.net ls > /dev/null ; then - echo "Failed to access storage." - exit 1 -fi - FAIL=0 echo "Deleting disk..." if ! yc compute disk delete --name ${DISKNAME} ; then @@ -111,7 +111,7 @@ if ! yc compute disk delete --name ${DISKNAME} ; then fi for i in ${PATHS}; do echo "Uploading qcow2 disk image to ${i}..." - if ! aws s3 --endpoint-url=https://storage.yandexcloud.net cp disk.qcow2 ${i}; then + if ! aws s3 --region ru-central1 --endpoint-url=https://storage.yandexcloud.net cp disk.qcow2 ${i}; then echo "Failed to upload image to ${i}." FAIL=1 fi