Skip to content

Commit

Permalink
Merge pull request #7039 from OdumInstitute/7038_ansible_to_GDCC
Browse files Browse the repository at this point in the history
ansible repo has moved to GDCC org
  • Loading branch information
kcondon authored Jun 30, 2020
2 parents 8bbc7ce + 5b92433 commit fc37fac
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 221 deletions.
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
puts "https://github.com/IQSS/dataverse/issues/6849"
puts
puts "You can also try the Vagrant environment at"
puts "https://github.com/IQSS/dataverse-ansible"
puts "https://github.com/GlobalDataverseCommunityConsortium/dataverse-ansible"
exit 1

config.vm.provider "virtualbox" do |vbox|
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinx-guides/source/api/external-tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ If you've thought to yourself that there ought to be an app store for Dataverse
Demoing Your External Tool
++++++++++++++++++++++++++

https://demo.dataverse.org is the place to play around with Dataverse and your tool can be included. Please email [email protected] to start the conversation about adding your tool. Additionally, you are welcome to open an issue at https://github.com/IQSS/dataverse-ansible which already includes a number of the tools listed above.
https://demo.dataverse.org is the place to play around with Dataverse and your tool can be included. Please email [email protected] to start the conversation about adding your tool. Additionally, you are welcome to open an issue at https://github.com/GlobalDataverseCommunityConsortium/dataverse-ansible which already includes a number of the tools listed above.

Announcing Your External Tool
+++++++++++++++++++++++++++++
Expand Down
6 changes: 3 additions & 3 deletions doc/sphinx-guides/source/developers/deployment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ If you are having trouble configuring the files manually as described above, see
Configure Ansible File (Optional)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In order to configure Dataverse settings such as the password of the dataverseAdmin user, download https://raw.githubusercontent.com/IQSS/dataverse-ansible/master/defaults/main.yml and edit the file to your liking.
In order to configure Dataverse settings such as the password of the dataverseAdmin user, download https://raw.githubusercontent.com/GlobalDataverseCommunityConsortium/dataverse-ansible/master/defaults/main.yml and edit the file to your liking.

You can skip this step if you're fine with the values in the "main.yml" file in the link above.

Expand All @@ -82,9 +82,9 @@ Download and Run the "Create Instance" Script

Once you have done the configuration above, you are ready to try running the "ec2-create-instance.sh" script to spin up Dataverse in AWS.

Download :download:`ec2-create-instance.sh<https://raw.githubusercontent.com/IQSS/dataverse-ansible/master/ec2/ec2-create-instance.sh>` and put it somewhere reasonable. For the purpose of these instructions we'll assume it's in the "Downloads" directory in your home directory.
Download :download:`ec2-create-instance.sh<https://raw.githubusercontent.com/GlobalDataverseCommunityConsortium/dataverse-ansible/master/ec2/ec2-create-instance.sh>` and put it somewhere reasonable. For the purpose of these instructions we'll assume it's in the "Downloads" directory in your home directory.

To run it with default values you just need the script, but you may also want a current copy of the ansible :download:`group vars<https://raw.githubusercontent.com/IQSS/dataverse-ansible/master/defaults/main.yml>`_ file.
To run it with default values you just need the script, but you may also want a current copy of the ansible :download:`group vars<https://raw.githubusercontent.com/GlobalDataverseCommunityConsortium/dataverse-ansible/master/defaults/main.yml>`_ file.

ec2-create-instance accepts a number of command-line switches, including:

Expand Down
14 changes: 7 additions & 7 deletions doc/sphinx-guides/source/developers/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ Running the Full API Test Suite Using EC2

To run the API test suite in an EC2 instance you should first follow the steps in the :doc:`deployment` section to get set up for AWS in general and EC2 in particular.

You may always retrieve a current copy of the ec2-create-instance.sh script and accompanying group_var.yml file from the `dataverse-ansible repo<https://github.com/IQSS/dataverse-ansible/>`_:
You may always retrieve a current copy of the ec2-create-instance.sh script and accompanying group_var.yml file from the `dataverse-ansible repo<https://github.com/GlobalDataverseCommunityConsortium/dataverse-ansible/>`_:

- `ec2-create-instance.sh<https://raw.githubusercontent.com/IQSS/dataverse-ansible/master/ec2/ec2-create-instance.sh>`_
- `main.yml<https://raw.githubusercontent.com/IQSS/dataverse-ansible/master/defaults/main.yml>`_
- `ec2-create-instance.sh<https://raw.githubusercontent.com/GlobalDataverseCommunityConsortium/dataverse-ansible/master/ec2/ec2-create-instance.sh>`_
- `main.yml<https://raw.githubusercontent.com/GlobalDataverseCommunityConsortium/dataverse-ansible/master/defaults/main.yml>`_

Edit ``main.yml`` to set the desired GitHub repo, branch, and to ensure that the API test suite is enabled:

Expand All @@ -149,15 +149,15 @@ Edit ``main.yml`` to set the desired GitHub repo, branch, and to ensure that the
- ``dataverse.api.test_suite: true``
- ``dataverse.sampledata.enabled: true``

If you wish, you may pass the local path of a logging directory, which will tell ec2-create-instance.sh to `grab various logs <https://github.com/IQSS/dataverse-ansible/blob/master/ec2/ec2-create-instance.sh#L185>`_ for your review.
If you wish, you may pass the local path of a logging directory, which will tell ec2-create-instance.sh to `grab various logs <https://github.com/GlobalDataverseCommunityConsortium/dataverse-ansible/blob/master/ec2/ec2-create-instance.sh#L185>`_ for your review.

Finally, run the script:

.. code-block:: bash
$ ./ec2-create-instance.sh -g main.yml -l log_dir
Near the beginning and at the end of the ec2-create-instance.sh output you will see instructions for connecting to the instance via SSH. If you are actively working on a branch and want to refresh the warfile after each commit, you may wish to call a `redeploy.sh <https://github.com/IQSS/dataverse-ansible/blob/master/templates/redeploy.sh.j2>`_ script placed by the Ansible role, which will do a "git pull" against your branch, build the warfile, deploy the warfile, then restart the app server. By default this script is written to /tmp/dataverse/redeploy.sh. You may invoke the script by appending it to the SSH command in ec2-create's output:
Near the beginning and at the end of the ec2-create-instance.sh output you will see instructions for connecting to the instance via SSH. If you are actively working on a branch and want to refresh the warfile after each commit, you may wish to call a `redeploy.sh <https://github.com/GlobalDataverseCommunityConsortium/dataverse-ansible/blob/master/templates/redeploy.sh.j2>`_ script placed by the Ansible role, which will do a "git pull" against your branch, build the warfile, deploy the warfile, then restart the app server. By default this script is written to /tmp/dataverse/redeploy.sh. You may invoke the script by appending it to the SSH command in ec2-create's output:

.. code-block:: bash
Expand Down Expand Up @@ -502,7 +502,7 @@ Installation Testing

- Run `vagrant up` on a server to test the installer: http://guides.dataverse.org/en/latest/developers/tools.html#vagrant . We haven't been able to get this working in Travis: https://travis-ci.org/IQSS/dataverse/builds/96292683 . Perhaps it would be possible to use AWS as a provider from Vagrant judging from https://circleci.com/gh/critical-alert/circleci-vagrant/6 .
- Work with @lwo to automate testing of https://github.com/IQSS/dataverse-puppet . Consider using Travis: https://github.com/IQSS/dataverse-puppet/issues/10
- Work with @donsizemore to automate testing of https://github.com/IQSS/dataverse-ansible with Travis or similar.
- Work with @donsizemore to automate testing of https://github.com/GlobalDataverseCommunityConsortium/dataverse-ansible with Travis or similar.

Future Work on Load/Performance Testing
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -514,7 +514,7 @@ Future Work on Load/Performance Testing
Future Work on Accessibility Testing
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- Using https://github.com/IQSS/dataverse-ansible and hooks available from accessibily testing tools, automate the running of accessibility tools on PRs so that developers will receive quicker feedback on proposed code changes that reduce the accessibility of the application.
- Using https://github.com/GlobalDataverseCommunityConsortium/dataverse-ansible and hooks available from accessibility testing tools, automate the running of accessibility tools on PRs so that developers will receive quicker feedback on proposed code changes that reduce the accessibility of the application.

----

Expand Down
2 changes: 1 addition & 1 deletion doc/sphinx-guides/source/installation/prep.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Advanced Installation

There are some community-lead projects to use configuration management tools such as Ansible and Puppet to automate Dataverse installation and configuration, but support for these solutions is limited to what the Dataverse community can offer as described in each project's webpage:

- https://github.com/IQSS/dataverse-ansible
- https://github.com/GlobalDataverseCommunityConsortium/dataverse-ansible
- https://github.com/IQSS/dataverse-puppet

(Please note that the "dataverse-ansible" repo is used in a script that allows Dataverse to be installed on Amazon Web Services (AWS) from arbitrary GitHub branches as described in the :doc:`/developers/deployment` section of the Developer Guide.)
Expand Down
208 changes: 3 additions & 205 deletions scripts/installer/ec2-create-instance.sh
Original file line number Diff line number Diff line change
@@ -1,206 +1,4 @@
#!/bin/bash -e
#!/bin/sh

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

# repo and branch defaults
REPO_URL_DEFAULT='https://github.com/IQSS/dataverse.git'
BRANCH_DEFAULT='develop'
PEM_DEFAULT=${HOME}
AWS_AMI_DEFAULT='ami-9887c6e7'

usage() {
echo "Usage: $0 -b <branch> -r <repo> -p <pem_dir> -g <group_vars> -a <dataverse-ansible branch> -i aws_image -s aws_size -t aws_tag -l local_log_path" 1>&2
echo "default branch is develop"
echo "default repo is https://github.com/IQSS/dataverse"
echo "default .pem location is ${HOME}"
echo "example group_vars may be retrieved from https://raw.githubusercontent.com/IQSS/dataverse-ansible/master/defaults/main.yml"
echo "default AWS AMI ID is $AWS_AMI_DEFAULT"
echo "default AWS size is t2.medium"
echo "local log path"
exit 1
}

while getopts ":a:r:b:g:p:i:s:t:l:" o; do
case "${o}" in
a)
DA_BRANCH=${OPTARG}
;;
r)
REPO_URL=${OPTARG}
;;
b)
BRANCH=${OPTARG}
;;
g)
GRPVRS=${OPTARG}
;;
p)
PEM_DIR=${OPTARG}
;;
i)
AWS_IMAGE=${OPTARG}
;;
s)
AWS_SIZE=${OPTARG}
;;
t)
TAG=${OPTARG}
;;
l)
LOCAL_LOG_PATH=${OPTARG}
;;
*)
usage
;;
esac
done

# test for ansible group_vars
if [ ! -z "$GRPVRS" ]; then
GVFILE=$(basename "$GRPVRS")
GVARG="-e @$GVFILE"
echo "using $GRPVRS for extra vars"
fi

# test for CLI args
if [ ! -z "$REPO_URL" ]; then
GVARG+=" -e dataverse_repo=$REPO_URL"
echo "using repo $REPO_URL"
fi

if [ ! -z "$BRANCH" ]; then
GVARG+=" -e dataverse_branch=$BRANCH"
echo "building branch $BRANCH"
fi

# The AMI ID may change in the future and the way to look it up is with the following command, which takes a long time to run:
# aws ec2 describe-images --owners 'aws-marketplace' --filters 'Name=product-code,Values=aw0evgkw8e5c1q413zgy5pjce' --query 'sort_by(Images, &CreationDate)[-1].[ImageId]' --output 'text'
# To use an AMI, one must subscribe to it via the AWS GUI.
# AMI IDs are specific to the region.

if [ ! -z "$AWS_IMAGE" ]; then
AMI_ID=$AWS_IMAGE
else
AMI_ID="$AWS_AMI_DEFAULT"
fi
echo "using $AMI_ID"

if [ ! -z "$AWS_SIZE" ]; then
SIZE=$AWS_SIZE
else
SIZE="t2.medium"
fi
echo "using $SIZE"

if [ ! -z "$TAG" ]; then
TAGARG="--tag-specifications ResourceType=instance,Tags=[{Key=name,Value=$TAG}]"
echo "using tag $TAG"
fi

# default to dataverse-ansible/master
if [ -z "$DA_BRANCH" ]; then
DA_BRANCH="master"
fi

# ansible doesn't care about pem_dir (yet)
if [ -z "$PEM_DIR" ]; then
PEM_DIR="$PEM_DEFAULT"
fi

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 [[ $(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

SECURITY_GROUP='dataverse-sg'
GROUP_CHECK=$(aws ec2 describe-security-groups --group-name $SECURITY_GROUP)
if [[ "$?" -ne 0 ]]; then
echo "Creating security group \"$SECURITY_GROUP\"."
aws ec2 create-security-group --group-name $SECURITY_GROUP --description "security group for Dataverse"
aws ec2 authorize-security-group-ingress --group-name $SECURITY_GROUP --protocol tcp --port 22 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-name $SECURITY_GROUP --protocol tcp --port 80 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-name $SECURITY_GROUP --protocol tcp --port 443 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-name $SECURITY_GROUP --protocol tcp --port 8080 --cidr 0.0.0.0/0
fi

RANDOM_STRING="$(uuidgen | cut -c-8)"
KEY_NAME="key-$USER-$RANDOM_STRING"

PRIVATE_KEY=$(aws ec2 create-key-pair --key-name $PEM_DIR/$KEY_NAME --query 'KeyMaterial' --output text)
if [[ $PRIVATE_KEY == '-----BEGIN RSA PRIVATE KEY-----'* ]]; then
PEM_FILE="$PEM_DIR/$KEY_NAME.pem"
printf -- "$PRIVATE_KEY" >$PEM_FILE
chmod 400 $PEM_FILE
echo "Your newly created private key file is \"$PEM_FILE\". Keep it secret. Keep it safe."
else
echo "Could not create key pair. Exiting."
exit 1
fi

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 $TAGARG --count 1 --instance-type $SIZE --key-name $PEM_DIR/$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 60 seconds to wake up..."
sleep 60
echo "End creating EC2 instance"

PUBLIC_DNS=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query "Reservations[*].Instances[*].[PublicDnsName]" --output text)
PUBLIC_IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query "Reservations[*].Instances[*].[PublicIpAddress]" --output text)

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\" from $REPO_URL is being deployed."

if [ ! -z "$GRPVRS" ]; then
scp -i $PEM_FILE -o 'StrictHostKeyChecking no' -o 'UserKnownHostsFile=/dev/null' -o 'ConnectTimeout=300' $GRPVRS $USER_AT_HOST:$GVFILE
fi

# epel-release is installed first to ensure the latest ansible is installed after
# TODO: Add some error checking for this ssh command.
ssh -T -i $PEM_FILE -o 'StrictHostKeyChecking no' -o 'UserKnownHostsFile=/dev/null' -o 'ConnectTimeout=300' $USER_AT_HOST <<EOF
sudo yum -y install epel-release
sudo yum -y install https://releases.ansible.com/ansible/rpm/release/epel-7-x86_64/ansible-2.7.9-1.el7.ans.noarch.rpm
sudo yum -y install git nano
git clone -b $DA_BRANCH https://github.com/IQSS/dataverse-ansible.git dataverse
export ANSIBLE_ROLES_PATH=.
ansible-playbook -v -i dataverse/inventory dataverse/dataverse.pb --connection=local $GVARG
EOF

if [ ! -z "$LOCAL_LOG_PATH" ]; then
echo "copying logs to $LOCAL_LOG_PATH."
# 1 accept SSH keys
ssh-keyscan ${PUBLIC_DNS} >> ~/.ssh/known_hosts
# 2 logdir should exist
mkdir -p $LOCAL_LOG_PATH
# 3 grab logs for local processing in jenkins
rsync -av -e "ssh -i $PEM_FILE" --ignore-missing-args centos@$PUBLIC_DNS:/tmp/dataverse/target/site $LOCAL_LOG_PATH/
rsync -av -e "ssh -i $PEM_FILE" --ignore-missing-args centos@$PUBLIC_DNS:/tmp/dataverse/target/surefire-reports $LOCAL_LOG_PATH/
rsync -av -e "ssh -i $PEM_FILE" centos@$PUBLIC_DNS:/usr/local/glassfish4/glassfish/domains/domain1/logs/server* $LOCAL_LOG_PATH/
# 4 grab mvn.out
rsync -av -e "ssh -i $PEM_FILE" --ignore-missing-args centos@$PUBLIC_DNS:/tmp/dataverse/mvn.out $LOCAL_LOG_PATH/
# 5 jacoco
rsync -av -e "ssh -i $PEM_FILE" --ignore-missing-args centos@$PUBLIC_DNS:/tmp/dataverse/target/coverage-it $LOCAL_LOG_PATH/
rsync -av -e "ssh -i $PEM_FILE" --ignore-missing-args centos@$PUBLIC_DNS:/tmp/dataverse/target/*.exec $LOCAL_LOG_PATH/
rsync -av -e "ssh -i $PEM_FILE" --ignore-missing-args centos@$PUBLIC_DNS:/tmp/dataverse/target/classes $LOCAL_LOG_PATH/
rsync -av -e "ssh -i $PEM_FILE" --ignore-missing-args centos@$PUBLIC_DNS:/tmp/dataverse/src $LOCAL_LOG_PATH/
fi

# Port 8080 has been added because Ansible puts a redirect in place
# from HTTP to HTTPS and the cert is invalid (self-signed), forcing
# the user to click through browser warnings.
CLICKABLE_LINK="http://${PUBLIC_DNS}"
echo "To ssh into the new instance:"
echo "ssh -i $PEM_FILE $USER_AT_HOST"
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"
echo "The current copy of this script has been moved to https://github.com/GlobalDataverseCommunityConsortium/dataverse-ansible/tree/master/ec2"
echo "You may call it directly: https://raw.githubusercontent.com/GlobalDataverseCommunityConsortium/dataverse-ansible/master/ec2/ec2-create-instance.sh"
2 changes: 1 addition & 1 deletion scripts/tests/ec2-memory-benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ In order to run the benchmark test you will need the following:
* Have your AWS credentials configured, so that you can spin up EC2 instances.

All the other pieces will be downloaded automatically (from the
`IQSS/dataverse-ansible` and `IQSS/dataverse-sample-data` GitHub repos),
`GlobalDataverseCommunityConsortium/dataverse-ansible` and `IQSS/dataverse-sample-data` GitHub repos),
either locally, where you're running the script, or on the newly
created instance.

Expand Down
4 changes: 2 additions & 2 deletions scripts/tests/ec2-memory-benchmark/ec2-memory-benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ then
fi

# download the ec2-create-instance script:
curl -O https://raw.githubusercontent.com/IQSS/dataverse-ansible/master/ec2/ec2-create-instance.sh
curl -O https://raw.githubusercontent.com/GlobalDataverseCommunityConsortium/dataverse-ansible/master/ec2/ec2-create-instance.sh
chmod 755 ec2-create-instance.sh

# download the sample data ec2 config:
Expand Down Expand Up @@ -91,4 +91,4 @@ echo
echo "Please do not forget to TERMINATE THE INSTANCE once you have downloaded all the results above,"
echo "with the following command:"
echo "aws ec2 terminate-instances --instance-ids ${EC2_INSTANCE_ID}"
echo
echo

0 comments on commit fc37fac

Please sign in to comment.