Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5162 cant publish using ec2 script #5174

Merged
merged 6 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions doc/sphinx-guides/source/developers/deployment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ Then update the file and replace the values for "aws_access_key_id" and "aws_sec

If you are having trouble configuring the files manually as described above, see https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html which documents the ``aws configure`` command.

Configure ~/.dataverse/ec2.env
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In order to publish datasets you must configure a file at ``~/.dataverse/ec2.env`` and contact DataCite at support@datacite.org to ask for a test username and password.

Create a ``.dataverse`` directory in your home directory like this:

``mkdir ~/.dataverse``

Download :download:`ec2.env <../../../../scripts/installer/ec2.env>` and put it in the directory at ``~/.dataverse`` that you just created. From the command line, you can try the command below to move the file into place:

``mv ~/Downloads/ec2.env ~/.dataverse``

Edit the file at ``~/.dataverse/ec2.env`` and fill in username and password from DataCite into the following fields:

- dataverse_doi_username
- dataverse_doi_password

Download and Run the "Create Instance" Script
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
71 changes: 52 additions & 19 deletions scripts/installer/ec2-create-instance.sh
Original file line number Diff line number Diff line change
@@ -1,45 +1,75 @@
#!/bin/bash
#!/bin/bash -e

# For docs, see the "Deployment" page in the Dev Guide.

SUGGESTED_REPO_URL='https://github.com/IQSS/dataverse.git'
SUGGESTED_BRANCH='develop'
# repo and branch defaults
REPO_URL='https://github.com/IQSS/dataverse.git'
BRANCH='develop'

usage() {
echo "Usage: $0 -r $REPO_URL -b $SUGGESTED_BRANCH" 1>&2
echo "Usage: $0 -b <branch> -r <repo> -e <environment file>" 1>&2
echo "default branch is develop"
echo "default repo is https://github.com/IQSS/dataverse"
echo "default conf file is ~/.dataverse/ec2.env"
exit 1
}

REPO_URL=$SUGGESTED_REPO_URL

while getopts ":r:b:" o; do
while getopts ":r:b:e:" o; do
case "${o}" in
r)
REPO_URL=${OPTARG}
;;
b)
BRANCH_NAME=${OPTARG}
BRANCH=${OPTARG}
;;
e)
EC2ENV=${OPTARG}
;;
*)
usage
;;
esac
done

# test for user-supplied conf files
if [ ! -z "$EC2ENV" ]; then
CONF=$EC2ENV
elif [ -f ~/.dataverse/ec2.env ]; then
echo "using environment variables specified in ~/.dataverse/ec2.env."
echo "override with -e <conf file>"
CONF="$HOME/.dataverse/ec2.env"
else
echo "no conf file supplied (-e <file>) or found at ~/.dataverse/ec2.env."
echo "running script with defaults. this may or may not be what you want."
fi

# read environment variables from conf file
if [ ! -z "$CONF" ];then
set -a
echo "reading $CONF"
source $CONF
set +a
fi

# now build extra-vars string from dataverse_* env variables
NL=$'\n'
extra_vars="dataverse_branch=$BRANCH dataverse_repo=$REPO_URL"
while IFS='=' read -r name value; do
if [[ $name == *'dataverse'* ]]; then
extra_var="$name"=${!name}
extra_var=${extra_var%$NL}
extra_vars="$extra_vars $extra_var"
fi
done < <(env)

AWS_CLI_VERSION=$(aws --version)
if [[ "$?" -ne 0 ]]; then
echo 'The "aws" program could not be executed. Is it in your $PATH?'
exit 1
fi

if [ "$BRANCH_NAME" = "" ]; then
echo "No branch name provided. You could try adding \"-b $SUGGESTED_BRANCH\" or other branches listed at $SUGGESTED_REPO_URL"
usage
exit 1
fi

if [[ $(git ls-remote --heads $REPO_URL $BRANCH_NAME | wc -l) -eq 0 ]]; then
echo "Branch \"$BRANCH_NAME\" does not exist at $REPO_URL"
if [[ $(git ls-remote --heads $REPO_URL $BRANCH | wc -l) -eq 0 ]]; then
echo "Branch \"$BRANCH\" does not exist at $REPO_URL"
usage
exit 1
fi
Expand Down Expand Up @@ -83,6 +113,8 @@ echo "Creating EC2 instance"
# TODO: Add some error checking for "ec2 run-instances".
INSTANCE_ID=$(aws ec2 run-instances --image-id $AMI_ID --security-groups $SECURITY_GROUP --count 1 --instance-type $SIZE --key-name $KEY_NAME --query 'Instances[0].InstanceId' --block-device-mappings '[ { "DeviceName": "/dev/sda1", "Ebs": { "DeleteOnTermination": true } } ]' | tr -d \")
echo "Instance ID: "$INSTANCE_ID
echo "giving instance 15 seconds to wake up..."
sleep 15
echo "End creating EC2 instance"

PUBLIC_DNS=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query "Reservations[*].Instances[*].[PublicDnsName]" --output text)
Expand All @@ -92,7 +124,7 @@ USER_AT_HOST="centos@${PUBLIC_DNS}"
echo "New instance created with ID \"$INSTANCE_ID\". To ssh into it:"
echo "ssh -i $PEM_FILE $USER_AT_HOST"

echo "Please wait at least 15 minutes while the branch \"$BRANCH_NAME\" from $REPO_URL is being deployed."
echo "Please wait at least 15 minutes while the branch \"$BRANCH\" from $REPO_URL is being deployed."

# epel-release is installed first to ensure the latest ansible is installed after
# TODO: Add some error checking for this ssh command.
Expand All @@ -101,7 +133,8 @@ sudo yum -y install epel-release
sudo yum -y install git nano ansible
git clone https://github.com/IQSS/dataverse-ansible.git dataverse
export ANSIBLE_ROLES_PATH=.
ansible-playbook -i dataverse/inventory dataverse/dataverse.pb --connection=local --extra-vars "dataverse_branch=$BRANCH_NAME dataverse_repo=$REPO_URL"
echo $extra_vars
ansible-playbook -v -i dataverse/inventory dataverse/dataverse.pb --connection=local --extra-vars "$extra_vars"
EOF

# Port 8080 has been added because Ansible puts a redirect in place
Expand All @@ -110,6 +143,6 @@ EOF
CLICKABLE_LINK="http://${PUBLIC_DNS}:8080"
echo "To ssh into the new instance:"
echo "ssh -i $PEM_FILE $USER_AT_HOST"
echo "Branch \"$BRANCH_NAME\" from $REPO_URL has been deployed to $CLICKABLE_LINK"
echo "Branch \"$BRANCH\" from $REPO_URL has been deployed to $CLICKABLE_LINK"
echo "When you are done, please terminate your instance with:"
echo "aws ec2 terminate-instances --instance-ids $INSTANCE_ID"
5 changes: 5 additions & 0 deletions scripts/installer/ec2.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dataverse_doi_baseurl="https://mds.test.datacite.org/"
dataverse_doi_username="demo.dataverse"
dataverse_doi_password="notmypassword"
dataverse_doi_authority="10.5072"
dataverse_doi_shoulder="FK2/"