nixos ec2/create-amis.sh: shellcheck: quote region references
This commit is contained in:
parent
4512dac960
commit
c76692192a
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env nix-shell
|
#!/usr/bin/env nix-shell
|
||||||
#!nix-shell -p awscli -p jq -p qemu -i bash
|
#!nix-shell -p awscli -p jq -p qemu -i bash
|
||||||
|
# shellcheck shell=bash
|
||||||
|
|
||||||
# Uploads and registers NixOS images built from the
|
# Uploads and registers NixOS images built from the
|
||||||
# <nixos/release.nix> amazonImage attribute. Images are uploaded and
|
# <nixos/release.nix> amazonImage attribute. Images are uploaded and
|
||||||
|
@ -111,7 +112,7 @@ wait_for_import() {
|
||||||
log "Waiting for import task $task_id to be completed"
|
log "Waiting for import task $task_id to be completed"
|
||||||
while true; do
|
while true; do
|
||||||
read state progress snapshot_id < <(
|
read state progress snapshot_id < <(
|
||||||
aws ec2 describe-import-snapshot-tasks --region $region --import-task-ids "$task_id" | \
|
aws ec2 describe-import-snapshot-tasks --region "$region" --import-task-ids "$task_id" | \
|
||||||
jq -r '.ImportSnapshotTasks[].SnapshotTaskDetail | "\(.Status) \(.Progress) \(.SnapshotId)"'
|
jq -r '.ImportSnapshotTasks[].SnapshotTaskDetail | "\(.Status) \(.Progress) \(.SnapshotId)"'
|
||||||
)
|
)
|
||||||
log " ... state=$state progress=$progress snapshot_id=$snapshot_id"
|
log " ... state=$state progress=$progress snapshot_id=$snapshot_id"
|
||||||
|
@ -139,7 +140,7 @@ wait_for_image() {
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
read state < <(
|
read state < <(
|
||||||
aws ec2 describe-images --image-ids "$ami_id" --region $region | \
|
aws ec2 describe-images --image-ids "$ami_id" --region "$region" | \
|
||||||
jq -r ".Images[].State"
|
jq -r ".Images[].State"
|
||||||
)
|
)
|
||||||
log " ... state=$state"
|
log " ... state=$state"
|
||||||
|
@ -163,7 +164,7 @@ make_image_public() {
|
||||||
local region=$1
|
local region=$1
|
||||||
local ami_id=$2
|
local ami_id=$2
|
||||||
|
|
||||||
wait_for_image $region "$ami_id"
|
wait_for_image "$region" "$ami_id"
|
||||||
|
|
||||||
log "Making image $ami_id public"
|
log "Making image $ami_id public"
|
||||||
|
|
||||||
|
@ -185,7 +186,7 @@ upload_image() {
|
||||||
log "Checking for image on S3"
|
log "Checking for image on S3"
|
||||||
if ! aws s3 ls --region "$region" "s3://${bucket}/${aws_path}" >&2; then
|
if ! aws s3 ls --region "$region" "s3://${bucket}/${aws_path}" >&2; then
|
||||||
log "Image missing from aws, uploading"
|
log "Image missing from aws, uploading"
|
||||||
aws s3 cp --region $region "$image_file" "s3://${bucket}/${aws_path}" >&2
|
aws s3 cp --region "$region" "$image_file" "s3://${bucket}/${aws_path}" >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log "Importing image from S3 path s3://$bucket/$aws_path"
|
log "Importing image from S3 path s3://$bucket/$aws_path"
|
||||||
|
@ -197,7 +198,7 @@ upload_image() {
|
||||||
\"S3Bucket\": \"$bucket\",
|
\"S3Bucket\": \"$bucket\",
|
||||||
\"S3Key\": \"$aws_path\"
|
\"S3Key\": \"$aws_path\"
|
||||||
}
|
}
|
||||||
}" --region $region | jq -r '.ImportTaskId')
|
}" --region "$region" | jq -r '.ImportTaskId')
|
||||||
|
|
||||||
write_state "$state_key" task_id "$task_id"
|
write_state "$state_key" task_id "$task_id"
|
||||||
fi
|
fi
|
||||||
|
@ -230,7 +231,7 @@ upload_image() {
|
||||||
aws ec2 register-image \
|
aws ec2 register-image \
|
||||||
--name "$image_name" \
|
--name "$image_name" \
|
||||||
--description "$image_description" \
|
--description "$image_description" \
|
||||||
--region $region \
|
--region "$region" \
|
||||||
--architecture $amazon_arch \
|
--architecture $amazon_arch \
|
||||||
--block-device-mappings "${block_device_mappings[@]}" \
|
--block-device-mappings "${block_device_mappings[@]}" \
|
||||||
"${extra_flags[@]}" \
|
"${extra_flags[@]}" \
|
||||||
|
@ -240,7 +241,7 @@ upload_image() {
|
||||||
write_state "$state_key" ami_id "$ami_id"
|
write_state "$state_key" ami_id "$ami_id"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
make_image_public $region "$ami_id"
|
make_image_public "$region" "$ami_id"
|
||||||
|
|
||||||
echo "$ami_id"
|
echo "$ami_id"
|
||||||
}
|
}
|
||||||
|
@ -268,7 +269,7 @@ copy_to_region() {
|
||||||
write_state "$state_key" ami_id "$ami_id"
|
write_state "$state_key" ami_id "$ami_id"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
make_image_public $region "$ami_id"
|
make_image_public "$region" "$ami_id"
|
||||||
|
|
||||||
echo "$ami_id"
|
echo "$ami_id"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue