@@ -284,18 +284,6 @@ if [[ "$RUN_ON" = "localhost" ]]; then
284
284
-dit " postgresmen/postgres-with-stuff:pg${PG_VERSION} " \
285
285
)
286
286
dockerConfig=" "
287
-
288
- function cleanup {
289
- echo " Remove docker container"
290
- docker container rm -f $containerHash
291
- echo " Remove temp files..."
292
- rm -f " $TMP_PATH /conf_$DOCKER_MACHINE .tmp"
293
- rm -f " $TMP_PATH /ddl_do_$DOCKER_MACHINE .sql"
294
- rm -f " $TMP_PATH /ddl_undo_$DOCKER_MACHINE .sql"
295
- rm -f " $TMP_PATH /queries_custom_$DOCKER_MACHINE .sql"
296
- rm -rf " $TMP_PATH /pg_nancy_home_${CURRENT_TS} "
297
- echo " Done."
298
- }
299
287
elif [[ " $RUN_ON " = " aws" ]]; then
300
288
# # Get max price from history and apply multiplier
301
289
prices=$( aws --region=us-east-1 ec2 describe-spot-price-history --instance-types $AWS_EC2_TYPE --no-paginate --start-time=$( date +%s) --product-descriptions=" Linux/UNIX (Amazon VPC)" --query ' SpotPriceHistory[*].{az:AvailabilityZone, price:SpotPrice}' )
@@ -312,54 +300,60 @@ elif [[ "$RUN_ON" = "aws" ]]; then
312
300
status=$( waitEC2Ready " docker-machine create" " $DOCKER_MACHINE " 1)
313
301
if [ " $status " == " price-too-low" ]
314
302
then
315
- echo " Price $price is too low for $AWS_EC2_TYPE instance. Try detect actual."
316
- corrrectPriceForLastFailedRequest=$( aws ec2 describe-spot-instance-requests --filters=" Name=launch.instance-type,Values=$AWS_EC2_TYPE " | jq ' .SpotInstanceRequests[] | select(.Status.Code == "price-too-low") | .Status.Message' | grep -Eo ' [0-9]+[.][0-9]+' | tail -n 1 & )
317
- if [ " $corrrectPriceForLastFailedRequest " != " " ] && [ " $corrrectPriceForLastFailedRequest " != " null" ]
318
- then
319
- EC2_PRICE=$corrrectPriceForLastFailedRequest
320
- # update docker machine name
321
- CURRENT_TS=$( date +%Y%m%d_%H%M%S%N_%Z)
322
- DOCKER_MACHINE=" nancy-$CURRENT_TS "
323
- DOCKER_MACHINE=" ${DOCKER_MACHINE// _/ -} "
324
- # try start docker machine name with new price
325
- echo " Attempt to create a new docker machine: $DOCKER_MACHINE with price: $EC2_PRICE ."
326
- createDockerMachine;
327
- waitEC2Ready " docker-machine create" " $DOCKER_MACHINE " 0;
328
- else
329
- >&2 echo " ERROR: Cannot determine actual price for the instance $AWS_EC2_TYPE ."
330
- exit 1;
331
- fi
303
+ echo " Price $price is too low for $AWS_EC2_TYPE instance. Try detect actual."
304
+ corrrectPriceForLastFailedRequest=$( aws ec2 describe-spot-instance-requests --filters=" Name=launch.instance-type,Values=$AWS_EC2_TYPE " | jq ' .SpotInstanceRequests[] | select(.Status.Code == "price-too-low") | .Status.Message' | grep -Eo ' [0-9]+[.][0-9]+' | tail -n 1 & )
305
+ if [ " $corrrectPriceForLastFailedRequest " != " " ] && [ " $corrrectPriceForLastFailedRequest " != " null" ]; then
306
+ EC2_PRICE=$corrrectPriceForLastFailedRequest
307
+ # update docker machine name
308
+ CURRENT_TS=$( date +%Y%m%d_%H%M%S%N_%Z)
309
+ DOCKER_MACHINE=" nancy-$CURRENT_TS "
310
+ DOCKER_MACHINE=" ${DOCKER_MACHINE// _/ -} "
311
+ # try start docker machine name with new price
312
+ echo " Attempt to create a new docker machine: $DOCKER_MACHINE with price: $EC2_PRICE ."
313
+ createDockerMachine;
314
+ waitEC2Ready " docker-machine create" " $DOCKER_MACHINE " 0;
315
+ else
316
+ >&2 echo " ERROR: Cannot determine actual price for the instance $AWS_EC2_TYPE ."
317
+ exit 1;
318
+ fi
332
319
fi
333
320
334
321
echo " Check a docker machine status."
335
322
res=$( docker-machine status $DOCKER_MACHINE 2>&1 & )
336
323
if [ " $res " != " Running" ]
337
324
then
338
- >&2 echo " Failed: Docker $DOCKER_MACHINE is NOT running."
339
- exit 1;
325
+ >&2 echo " Failed: Docker $DOCKER_MACHINE is NOT running."
326
+ exit 1;
340
327
fi
341
328
342
329
echo " Docker $DOCKER_MACHINE is running."
343
330
344
331
containerHash=$( docker ` docker-machine config $DOCKER_MACHINE ` run --name=" pg_nancy_${CURRENT_TS} " \
345
332
-v /home/ubuntu:/machine_home -dit " postgresmen/postgres-with-stuff:pg${PG_VERSION} " )
346
333
dockerConfig=$( docker-machine config $DOCKER_MACHINE )
347
-
348
- function cleanup {
349
- cmdout=$( docker-machine rm --force $DOCKER_MACHINE )
350
- echo " Finished working with machine $DOCKER_MACHINE , termination requested, current status: $cmdout "
351
- echo " Remove temp files..."
352
- rm -f " $TMP_PATH /conf_$DOCKER_MACHINE .tmp"
353
- rm -f " $TMP_PATH /ddl_do_$DOCKER_MACHINE .sql"
354
- rm -f " $TMP_PATH /ddl_undo_$DOCKER_MACHINE .sql"
355
- rm -f " $TMP_PATH /queries_custom_$DOCKER_MACHINE .sql"
356
- echo " Done."
357
- }
358
334
else
359
335
>&2 echo " ASSERT: must not reach this point"
360
336
exit 1
361
337
fi
362
338
339
+ function cleanup {
340
+ echo " Remove temp files..."
341
+ rm -f " $TMP_PATH /conf_$DOCKER_MACHINE .tmp"
342
+ rm -f " $TMP_PATH /ddl_do_$DOCKER_MACHINE .sql"
343
+ rm -f " $TMP_PATH /ddl_undo_$DOCKER_MACHINE .sql"
344
+ rm -f " $TMP_PATH /queries_custom_$DOCKER_MACHINE .sql"
345
+ if [ " $RUN_ON " = " localhost" ]; then
346
+ rm -rf " $TMP_PATH /pg_nancy_home_${CURRENT_TS} "
347
+ echo " Remove docker container"
348
+ docker container rm -f $containerHash
349
+ elif [ " $RUN_ON " = " aws" ]; then
350
+ cmdout=$( docker-machine rm --force $DOCKER_MACHINE )
351
+ echo " Finished working with machine $DOCKER_MACHINE , termination requested, current status: $cmdout "
352
+ else
353
+ >&2 echo " ASSERT: must not reach this point"
354
+ exit 1
355
+ fi
356
+ }
363
357
trap cleanup EXIT
364
358
365
359
alias docker_exec=' docker $dockerConfig exec -i pg_nancy_${CURRENT_TS} '
0 commit comments