@@ -118,7 +118,7 @@ function check_path() {
118
118
# None
119
119
# ######################################
120
120
function create_ec2_docker_machine() {
121
- msg " Attempt to create a docker machine in zone $7 with price $3 ..."
121
+ msg " Attempt to create a docker machine in region $7 with price $3 ..."
122
122
docker-machine create --driver=amazonec2 \
123
123
--amazonec2-request-spot-instance \
124
124
--amazonec2-instance-type=$2 \
@@ -571,19 +571,19 @@ if [[ "$RUN_ON" == "aws" ]]; then
571
571
fi
572
572
elif [[ " $RUN_ON " == " localhost" ]]; then
573
573
if [[ ! -z ${AWS_KEYPAIR_NAME+x} ]] || [[ ! -z ${AWS_SSH_KEY_PATH+x} ]] ; then
574
- err " ERROR: options '--aws-keypair-name' and '--aws-ssh-key-path' must be used with '--run on aws'."
574
+ err " ERROR: options '--aws-keypair-name' and '--aws-ssh-key-path' must be used with '--run- on aws'."
575
575
exit 1
576
576
fi
577
577
if [[ ! -z ${AWS_EC2_TYPE+x} ]]; then
578
- err " ERROR: option '--aws-ec2-type' must be used with '--run on aws'."
578
+ err " ERROR: option '--aws-ec2-type' must be used with '--run- on aws'."
579
579
exit 1
580
580
fi
581
581
if [[ ! -z ${AWS_EBS_VOLUME_SIZE+x} ]]; then
582
- err " ERROR: option '--aws-ebs-volume-size' must be used with '--run on aws'."
582
+ err " ERROR: option '--aws-ebs-volume-size' must be used with '--run- on aws'."
583
583
exit 1
584
584
fi
585
585
if [[ ! -z ${AWS_REGION+x} ]]; then
586
- err " ERROR: option '--aws-region' must be used with '--run on aws'."
586
+ err " ERROR: option '--aws-region' must be used with '--run- on aws'."
587
587
exit 1
588
588
fi
589
589
else
747
747
748
748
if [[ " $RUN_ON " == " aws" ]]; then
749
749
if [[ ! -z ${AWS_EBS_VOLUME_SIZE+x} ]]; then
750
- if ! [[ $AWS_EBS_VOLUME_SIZE =~ ' ^[0-9]+$' ]] ; then
751
- err " ERROR: --ebs-volume-size must be integer."
750
+ re=' ^[0-9]+$'
751
+ if ! [[ $AWS_EBS_VOLUME_SIZE =~ $re ]] ; then
752
+ err " ERROR: --aws-ebs-volume-size must be integer."
752
753
exit 1
753
754
fi
754
755
else
@@ -825,18 +826,19 @@ elif [[ "$RUN_ON" == "aws" ]]; then
825
826
region=" ${region/ \" / } "
826
827
minprice=" ${minprice/ \" / } "
827
828
minprice=" ${minprice/ \" / } "
828
- zone=${region: -1}
829
- msg " Min price from history: $minprice in $region (zone: $zone )"
829
+ AWS_ZONE=${region: -1}
830
+ AWS_REGION=${region:: -1}
831
+ msg " Min price from history: $minprice in $region (zone: $AWS_ZONE )"
830
832
multiplier=" 1.01"
831
833
price=$( echo " $minprice * $multiplier " | bc -l)
832
834
msg " Increased price: $price "
833
835
EC2_PRICE=$price
834
- if [ -z $zone ]; then
835
- zone =' a' # default zone
836
+ if [[ -z $AWS_ZONE ] ]; then
837
+ AWS_ZONE =' a' # default zone
836
838
fi
837
839
838
840
create_ec2_docker_machine $DOCKER_MACHINE $AWS_EC2_TYPE $EC2_PRICE \
839
- 60 $AWS_KEYPAIR_NAME $AWS_SSH_KEY_PATH $AWS_REGION $zone ;
841
+ 60 $AWS_KEYPAIR_NAME $AWS_SSH_KEY_PATH $AWS_REGION $AWS_ZONE ;
840
842
status=$( wait_ec2_docker_machine_ready " $DOCKER_MACHINE " true)
841
843
if [[ " $status " == " price-too-low" ]]; then
842
844
msg " Price $price is too low for $AWS_EC2_TYPE instance. Getting the up-to-date value from the error message..."
@@ -864,7 +866,7 @@ elif [[ "$RUN_ON" == "aws" ]]; then
864
866
DOCKER_MACHINE=" ${DOCKER_MACHINE// _/ -} "
865
867
# try start docker machine name with new price
866
868
create_ec2_docker_machine $DOCKER_MACHINE $AWS_EC2_TYPE $EC2_PRICE \
867
- 60 $AWS_KEYPAIR_NAME $AWS_SSH_KEY_PATH $AWS_REGION $zone
869
+ 60 $AWS_KEYPAIR_NAME $AWS_SSH_KEY_PATH $AWS_REGION $AWS_ZONE
868
870
wait_ec2_docker_machine_ready " $DOCKER_MACHINE " false ;
869
871
else
870
872
err " $( date " +%Y-%m-%d %H:%M:%S" ) ERROR: Cannot determine actual price for the instance $AWS_EC2_TYPE ."
@@ -907,7 +909,7 @@ elif [[ "$RUN_ON" == "aws" ]]; then
907
909
# Create new volume and attach them for non i3 instances if needed
908
910
if [ ! -z ${AWS_EBS_VOLUME_SIZE+x} ]; then
909
911
msg " Create and attach a new EBS volume (size: $AWS_EBS_VOLUME_SIZE GB)"
910
- VOLUME_ID=$( aws --region=$AWS_REGION ec2 create-volume --size $AWS_EBS_VOLUME_SIZE --availability-zone us-east-1a --volume-type gp2 | jq -r .VolumeId)
912
+ VOLUME_ID=$( aws --region=$AWS_REGION ec2 create-volume --size $AWS_EBS_VOLUME_SIZE --availability-zone $AWS_REGION$AWS_ZONE --volume-type gp2 | jq -r .VolumeId)
911
913
INSTANCE_ID=$( docker-machine ssh $DOCKER_MACHINE curl -s http://169.254.169.254/latest/meta-data/instance-id)
912
914
sleep 10 # wait to volume will ready
913
915
attachResult=$( aws --region=$AWS_REGION ec2 attach-volume --device /dev/xvdf --volume-id $VOLUME_ID --instance-id $INSTANCE_ID )
0 commit comments