Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Hendry committed Sep 17, 2019
0 parents commit 0dabf77
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM mongo
RUN apt-get update && apt-get install -y mysql-client python3-pip curl
RUN pip3 install awscli --upgrade --user
RUN ln -s ~/.local/bin/aws /usr/local/bin/aws
ADD * /
CMD ["/start"]
53 changes: 53 additions & 0 deletions connect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

STAGE=dev

domain() {
case $1 in
prod) echo auroradb.unee-t.com
;;
*) echo auroradb.$1.unee-t.com
;;
esac
}

show_help() {
cat << EOF
Usage: ${0##*/} [-p]
By default, deploy to dev environment on AWS account 812644853088
-p PRODUCTION 192458993663
-d DEMO 915001051872
EOF
}

while getopts "pd" opt
do
case $opt in
p)
echo "PRODUCTION" >&2
STAGE=prod
;;
d)
echo "DEMO" >&2
STAGE=demo
;;
*)
show_help >&2
exit 1
;;
esac
done
AWS_PROFILE=uneet-$STAGE
shift "$((OPTIND-1))" # Discard the options and sentinel --

echo Connecting to ${STAGE^^} $(domain $STAGE)

MYSQL_PASSWORD=$(aws --profile $AWS_PROFILE ssm get-parameters --names MYSQL_ROOT_PASSWORD --with-decryption --query Parameters[0].Value --output text)
MYSQL_USER=$(aws --profile $AWS_PROFILE ssm get-parameters --names MYSQL_USER --with-decryption --query Parameters[0].Value --output text)

echo $STAGE
echo mysql -s -h $(domain $STAGE) -P 3306 -u root --password=$MYSQL_PASSWORD bugzilla
mysql -s -h $(domain $STAGE) -P 3306 -u root --password=$MYSQL_PASSWORD bugzilla
6 changes: 6 additions & 0 deletions reset-mongo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
AWS_PROFILE=uneet-demo

MONGO_PASSWORD=$(aws --profile $AWS_PROFILE ssm get-parameters --names MONGO_PASSWORD --with-decryption --query Parameters[0].Value --output text)
MONGO_CONNECT=$(aws --profile $AWS_PROFILE ssm get-parameters --names MONGO_CONNECT --query Parameters[0].Value --output text)
mongo "mongodb://root:$MONGO_PASSWORD@$MONGO_CONNECT" --eval "db.dropDatabase()"
50 changes: 50 additions & 0 deletions restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

STAGE=demo

show_help() {
cat << EOF
Usage: ${0##*/} [-p]
By default, deploy to dev environment on AWS account 812644853088
-p PRODUCTION 192458993663
-d DEMO 915001051872
-l localhost
EOF
}

while getopts "pdl" opt
do
case $opt in
d)
echo "DEMO" >&2
STAGE=demo
;;
l)
echo "localhost" >&2
STAGE=localhost
;;
*)
show_help >&2
exit 1
;;
esac
done
AWS_PROFILE=uneet-$STAGE
shift "$((OPTIND-1))" # Discard the options and sentinel --

test -f "$1" || exit

if test $STAGE == "localhost"
then
export PASSWORD=funfunfun
export MYSQL_HOST=db
else
export PASSWORD=$(aws --profile $AWS_PROFILE ssm get-parameters --names MYSQL_ROOT_PASSWORD --with-decryption --query Parameters[0].Value --output text)
export MYSQL_HOST=$(aws --profile $AWS_PROFILE ssm get-parameters --names MYSQL_HOST --with-decryption --query Parameters[0].Value --output text)
fi

echo Restoring $1 to $STAGE $MYSQL_HOST
mysql -h $MYSQL_HOST -P 3306 -u root --password=$PASSWORD < $1
4 changes: 4 additions & 0 deletions run-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export AWS_PROFILE=uneet-demo
docker build -t uneet/reset-demo .
docker run -e "AWS_ACCESS_KEY_ID=$(aws configure get aws_access_key_id --profile $AWS_PROFILE)" \
-e "AWS_SECRET_ACCESS_KEY=$(aws configure get aws_secret_access_key --profile $AWS_PROFILE)" uneet/reset-demo
32 changes: 32 additions & 0 deletions start
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash -xe

demossm() {
aws --profile uneet-demo ssm get-parameters --names $1 --with-decryption --query Parameters[0].Value --output text
}

mongo --version
mysql --version
aws configure set profile.uneet-demo.aws_access_key_id $AWS_ACCESS_KEY_ID &&
aws configure set profile.uneet-demo.aws_secret_access_key $AWS_SECRET_ACCESS_KEY &&
aws configure set profile.uneet-demo.region ap-southeast-1 &&
aws configure --profile uneet-demo list

export AWS_PROFILE=uneet-demo

echo "select login_name from profiles;" | ./connect.sh -d
./stop-services.sh

./reset-mongo.sh

curl -o demo-baseline.sql -O $(demossm DEMO_BASELINE_SQL)
md5sum demo-baseline.sql
./restore.sh -d demo-baseline.sql

demossm BUGZILLA_ADMIN_KEY_SQL > demo-BUGZILLA_ADMIN_KEY.sql

cat demo-BUGZILLA_ADMIN_KEY.sql

./restore.sh -d demo-BUGZILLA_ADMIN_KEY.sql

./start-services.sh
echo "select login_name from profiles;" | ./connect.sh -d
4 changes: 4 additions & 0 deletions start-services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
for s in meteor bugzilla
do
aws ecs --profile uneet-demo update-service --cluster master --service ecscompose-service-$s --desired-count 2
done
4 changes: 4 additions & 0 deletions stop-services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
for s in meteor bugzilla
do
aws ecs --profile uneet-demo update-service --cluster master --service ecscompose-service-$s --desired-count 0
done

0 comments on commit 0dabf77

Please sign in to comment.