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

Commit 4e7848d

Browse files
dmiusDmitry
authored andcommitted
Use i3 nvme0n1p1 volume or create+attach ebs for non i3
1 parent 8a785a5 commit 4e7848d

File tree

1 file changed

+48
-5
lines changed

1 file changed

+48
-5
lines changed

nancy_run.sh

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ function checkParams() {
475475

476476
checkParams;
477477

478-
479478
# Determine dump file size
480479
if [ ! -z ${DB_DUMP_PATH+x} ]; then
481480
dumpFileSize=0
@@ -502,8 +501,6 @@ if [ ! -z ${DB_DUMP_PATH+x} ]; then
502501
[ $DEBUG -eq 1 ] && echo "EBS Size: $EBS_SIZE Gb"
503502
fi
504503

505-
exit 1
506-
507504
set -ueo pipefail
508505
[ $DEBUG -eq 1 ] && set -ueox pipefail # to debug
509506
shopt -s expand_aliases
@@ -544,8 +541,6 @@ function createDockerMachine() {
544541
--amazonec2-instance-type=$AWS_EC2_TYPE \
545542
--amazonec2-spot-price=$EC2_PRICE \
546543
$DOCKER_MACHINE &
547-
548-
# --block-device-mappings "[{\"DeviceName\": \"/dev/sda1\",\"Ebs\":{\"VolumeSize\":$EBS_SIZE}}]" \
549544
}
550545

551546
if [[ "$RUN_ON" = "localhost" ]]; then
@@ -613,10 +608,47 @@ elif [[ "$RUN_ON" = "aws" ]]; then
613608

614609
echo "Docker $DOCKER_MACHINE is running."
615610

611+
if [ ${AWS_EC2_TYPE:0:2} == 'i3' ]
612+
then
613+
# Init i3 storage, just mount existing volume
614+
docker-machine ssh $DOCKER_MACHINE df -h
615+
docker-machine ssh $DOCKER_MACHINE sudo add-apt-repository -y ppa:sbates
616+
docker-machine ssh $DOCKER_MACHINE sudo apt-get update || :
617+
docker-machine ssh $DOCKER_MACHINE sudo apt-get install -y nvme-cli
618+
619+
docker-machine ssh $DOCKER_MACHINE echo "# partition table of /dev/nvme0n1" > /tmp/nvme.part
620+
docker-machine ssh $DOCKER_MACHINE echo "unit: sectors " >> /tmp/nvme.part
621+
docker-machine ssh $DOCKER_MACHINE echo "/dev/nvme0n1p1 : start= 2048, size=1855466702, Id=83 " >> /tmp/nvme.part
622+
docker-machine ssh $DOCKER_MACHINE echo "/dev/nvme0n1p2 : start= 0, size= 0, Id= 0 " >> /tmp/nvme.part
623+
docker-machine ssh $DOCKER_MACHINE echo "/dev/nvme0n1p3 : start= 0, size= 0, Id= 0 " >> /tmp/nvme.part
624+
docker-machine ssh $DOCKER_MACHINE echo "/dev/nvme0n1p4 : start= 0, size= 0, Id= 0 " >> /tmp/nvme.part
625+
626+
docker-machine ssh $DOCKER_MACHINE sudo sfdisk /dev/nvme0n1 < /tmp/nvme.part
627+
docker-machine ssh $DOCKER_MACHINE sudo mkfs -t ext4 /dev/nvme0n1p1
628+
docker-machine ssh $DOCKER_MACHINE "sudo sh -c \"mkdir /home/storage\""
629+
docker-machine ssh $DOCKER_MACHINE sudo mount /dev/nvme0n1p1 /home/storage
630+
# docker-machine ssh $DOCKER_MACHINE "sudo sh -c \"echo 'Check mount storage TEST' > /home/storage/nvme0n1p1-test.txt\""
631+
docker-machine ssh $DOCKER_MACHINE df -h
632+
else
633+
# Create new volume and attach them for non i3 instances if need
634+
[ $DEBUG -eq 1 ] && echo "Create volume with size: $EBS_SIZE Gb"
635+
VOLUME_ID=$(aws ec2 create-volume --size 10 --region us-east-1 --availability-zone us-east-1a --volume-type gp2 | jq -r .VolumeId)
636+
INSTANCE_ID=$(docker-machine ssh $DOCKER_MACHINE curl -s http://169.254.169.254/latest/meta-data/instance-id)
637+
echo "Instance id: $INSTANCE_ID Volume with size: $EBS_SIZE created. Volume id: $VOLUME_ID"
638+
sleep 10 # wait to volume will ready
639+
attachResult=$(aws ec2 attach-volume --device /dev/xvdf --volume-id $VOLUME_ID --instance-id $INSTANCE_ID --region us-east-1)
640+
echo "ATTACH RESULT: $attachResult"
641+
docker-machine ssh $DOCKER_MACHINE sudo mkfs.ext4 /dev/xvdf
642+
docker-machine ssh $DOCKER_MACHINE "sudo sh -c \"mkdir /home/storage\""
643+
docker-machine ssh $DOCKER_MACHINE sudo mount /dev/xvdf /home/storage
644+
# docker-machine ssh $DOCKER_MACHINE "sudo sh -c \"echo 'Check mount storage TEST' > /home/storage/xvdf-test.txt\""
645+
fi
646+
616647
containerHash=$( \
617648
docker `docker-machine config $DOCKER_MACHINE` run \
618649
--name="pg_nancy_${CURRENT_TS}" \
619650
-v /home/ubuntu:/machine_home \
651+
-v /home/storage:/storage \
620652
-dit "postgresmen/postgres-with-stuff:pg${PG_VERSION}"
621653
)
622654
dockerConfig=$(docker-machine config $DOCKER_MACHINE)
@@ -640,18 +672,29 @@ function cleanup {
640672
elif [ "$RUN_ON" = "aws" ]; then
641673
cmdout=$(docker-machine rm --force $DOCKER_MACHINE)
642674
echo "Finished working with machine $DOCKER_MACHINE, termination requested, current status: $cmdout"
675+
if [ ! -z ${VOLUME_ID+x} ]; then
676+
echo "Wait and delete volume $VOLUME_ID"
677+
sleep 60 # wait to machine removed
678+
delvolout=$(aws ec2 delete-volume --volume-id $VOLUME_ID)
679+
echo "Volume $VOLUME_ID deleted"
680+
fi
643681
else
644682
>&2 echo "ASSERT: must not reach this point"
645683
exit 1
646684
fi
647685
}
648686
trap cleanup EXIT
649687

688+
650689
alias docker_exec='docker $dockerConfig exec -i ${containerHash} '
651690

652691
MACHINE_HOME="/machine_home/nancy_${containerHash}"
653692
docker_exec sh -c "mkdir $MACHINE_HOME && chmod a+w $MACHINE_HOME"
654693

694+
#docker_exec bash -c "ls -al /storage/"
695+
696+
exit 1
697+
655698
function copyFile() {
656699
if [ "$1" != '' ]; then
657700
if [[ "$1" =~ "s3://" ]]; then # won't work for .s3cfg!

0 commit comments

Comments
 (0)