Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 7377af3

Browse files
dmiusDmitry
authored andcommitted
Spot live time duration option added
1 parent 28acb2f commit 7377af3

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

nancy_run.sh

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ KEEP_ALIVE=0
1616
VERBOSE_OUTPUT_REDIRECT=" > /dev/null"
1717
EBS_SIZE_MULTIPLIER=15
1818
POSTGRES_VERSION_DEFAULT=10
19+
AWS_BLOCK_DURATION=0 # by default no time limit
1920

2021
#######################################
2122
# Print an error/warning/notice message to STDERR
@@ -339,6 +340,8 @@ while true; do
339340
AWS_SSH_KEY_PATH="$2"; shift 2 ;;
340341
--aws-ebs-volume-size )
341342
AWS_EBS_VOLUME_SIZE="$2"; shift 2 ;;
343+
--aws-block-duration )
344+
AWS_BLOCK_DURATION=$2; shift 2 ;;
342345

343346
--s3cfg-path )
344347
S3_CFG_PATH="$2"; shift 2 ;;
@@ -405,6 +408,7 @@ function checkPath() {
405408
return 1
406409
fi
407410
eval path=\$$1
411+
408412
if [[ $path =~ "s3://" ]]; then
409413
dbg "$1 looks like a S3 file path. Warning: Its presence will not be checked!"
410414
return 0 # we do not actually check S3 paths at the moment
@@ -420,7 +424,7 @@ function checkPath() {
420424
exit 1
421425
fi
422426
else
423-
dbg "Value of $2 is not a file path. Use its value as a content."
427+
dbg "Value of $1 is not a file path. Use its value as a content."
424428
return -1 #
425429
fi
426430
}
@@ -441,6 +445,19 @@ if [[ "$RUN_ON" == "aws" ]]; then
441445
err "ERROR: AWS EC2 Instance type not given."
442446
exit 1
443447
fi
448+
if [[ -z ${AWS_BLOCK_DURATION+x} ]]; then
449+
err "NOTICE: Container live time duration is not given."
450+
else
451+
case $AWS_BLOCK_DURATION in
452+
0|60|120|240|300|360)
453+
dbg "Container live time duration is $AWS_BLOCK_DURATION. "
454+
;;
455+
*)
456+
err "Container live time duration (--aws-block-duration) has wrong value: $AWS_BLOCK_DURATION. Available values of AWS spot instance duration in minutes is 60, 120, 180, 240, 300, or 360)."
457+
exit 1
458+
;;
459+
esac
460+
fi
444461
elif [[ "$RUN_ON" == "localhost" ]]; then
445462
if [[ ! -z ${AWS_KEYPAIR_NAME+x} ]] || [[ ! -z ${AWS_SSH_KEY_PATH+x} ]] ; then
446463
err "ERROR: options '--aws-keypair-name' and '--aws-ssh-key-path' must be used with '--run on aws'."
@@ -454,6 +471,10 @@ elif [[ "$RUN_ON" == "localhost" ]]; then
454471
err "ERROR: option '--aws-ebs-volume-size' must be used with '--run on aws'."
455472
exit 1
456473
fi
474+
if [[ "$AWS_BLOCK_DURATION" != "0" ]]; then
475+
err "ERROR: option '--aws-block-duration' must be used with '--run on aws'."
476+
exit 1
477+
fi
457478
else
458479
err "ERROR: incorrect value for option --run-on"
459480
exit 1
@@ -522,7 +543,7 @@ else
522543
if [[ "$?" -ne "0" ]]; then # TODO(NikolayS) support file:// and s3://
523544
#err "WARNING: Value given as pg_config: '$PG_CONFIG' not found as file will use as content"
524545
echo "$PG_CONFIG" > $TMP_PATH/pg_config_tmp.sql
525-
WORKLOAD_CUSTOM_SQL="$TMP_PATH/pg_config_tmp.sql" ## TODO(NikolayS) <<< bug/typo?
546+
PG_CONFIG="$TMP_PATH/pg_config_tmp.sql"
526547
fi
527548
fi
528549

@@ -694,6 +715,7 @@ function waitEC2Ready() {
694715
# 4) duration (minutes)
695716
# 5) key pair name
696717
# 6) key path
718+
# 7) zone
697719
function createDockerMachine() {
698720
msg "Attempt to create a docker machine..."
699721
docker-machine create --driver=amazonec2 \
@@ -702,9 +724,9 @@ function createDockerMachine() {
702724
--amazonec2-ssh-keypath="$6" \
703725
--amazonec2-instance-type=$2 \
704726
--amazonec2-spot-price=$3 \
705-
--amazonec2-zone $7 \
727+
--amazonec2-block-duration-minutes=$4 \
728+
--amazonec2-zone=$7 \
706729
$1 2> >(grep -v "failed waiting for successful resource state" >&2) &
707-
# --amazonec2-block-duration-minutes=$4 \
708730
}
709731

710732
function destroyDockerMachine() {
@@ -786,7 +808,7 @@ elif [[ "$RUN_ON" == "aws" ]]; then
786808
fi
787809

788810
createDockerMachine $DOCKER_MACHINE $AWS_EC2_TYPE $EC2_PRICE \
789-
60 $AWS_KEYPAIR_NAME $AWS_SSH_KEY_PATH $zone;
811+
$AWS_BLOCK_DURATION $AWS_KEYPAIR_NAME $AWS_SSH_KEY_PATH $zone;
790812
status=$(waitEC2Ready "docker-machine create" "$DOCKER_MACHINE" 1)
791813
if [[ "$status" == "price-too-low" ]]; then
792814
msg "Price $price is too low for $AWS_EC2_TYPE instance. Getting the up-to-date value from the error message..."
@@ -815,7 +837,7 @@ elif [[ "$RUN_ON" == "aws" ]]; then
815837
#try start docker machine name with new price
816838
msg "Attempt to create a new docker machine: $DOCKER_MACHINE with price: $EC2_PRICE."
817839
createDockerMachine $DOCKER_MACHINE $AWS_EC2_TYPE $EC2_PRICE \
818-
60 $AWS_KEYPAIR_NAME $AWS_SSH_KEY_PATH;
840+
$AWS_BLOCK_DURATION $AWS_KEYPAIR_NAME $AWS_SSH_KEY_PATH $zone;
819841
waitEC2Ready "docker-machine create" "$DOCKER_MACHINE" 0;
820842
else
821843
err "$(date "+%Y-%m-%d %H:%M:%S") ERROR: Cannot determine actual price for the instance $AWS_EC2_TYPE."
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
output=$(
4+
${BASH_SOURCE%/*}/../nancy run \
5+
--run-on aws \
6+
--aws-keypair-name awskey \
7+
--aws-ssh-key-path /path/.ssh/awskey.pem \
8+
--aws-ec2-type i3.large \
9+
--aws-block-duration 30 \
10+
2>&1
11+
)
12+
13+
if [[ $output =~ " Container live time duration (--aws-block-duration) has wrong value: 30. Available values of AWS spot instance duration in minutes is 60, 120, 180, 240, 300, or 360)." ]]; then
14+
echo -e "\e[36mOK\e[39m"
15+
else
16+
>&2 echo -e "\e[31mFAILED\e[39m"
17+
>&2 echo -e "Output: $output"
18+
exit 1
19+
fi

0 commit comments

Comments
 (0)