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

LCH-5000: Enhance Content Hub Farm to recreate a local customer environment #4

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ lines:
- ACH_HOSTNAME=https://plexus-dev.content-hub.acquia.com
# These are your Xdebug parameters.
- PHP_IDE_CONFIG=serverName=content-hub-farm_subscriber1_2
- XDEBUG_CONFIG=remote_port=9000 remote_autostart=1
- XDEBUG_CONFIG=remote_port=9003 remote_autostart=1
volumes:
- html:/var/www/html
ports:
Expand Down
4 changes: 4 additions & 0 deletions backups/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Please put all database backups inside this directory.
*
# Ignore (but don't delete) this line
!.gitignore
27 changes: 19 additions & 8 deletions bin/commands/container/export-db.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#!/bin/bash

# Finding the DOCROOT...
# @TODO: Find a better way to find out the docroot.
if [ -d "html/docroot" ]
then
echo "Using directory 'docroot' as the DOCROOT..."
DOCROOT='docroot';
else
echo "Using directory 'web' as the DOCROOT..."
DOCROOT='web';
fi

# Provide help if "--help" is requested.
if [[ $2 == "--help" ]]; then
echo ""
Expand Down Expand Up @@ -40,9 +51,9 @@ case "${FILE}" in
# If it's gzipped.
export_cmd() {
if [ $PV ] ; then
docker exec -t -w /var/www/html/web ${CONTAINER} /usr/local/bin/drush.sh sql-dump | pv | gzip > ${TARGET_FILE}
docker exec -t -w /var/www/html/${DOCROOT} ${CONTAINER} /usr/local/bin/drush.sh sql-dump | pv | gzip > ${TARGET_FILE}
else
docker exec -t -w /var/www/html/web ${CONTAINER} /usr/local/bin/drush.sh sql-dump | gzip > ${TARGET_FILE}
docker exec -t -w /var/www/html/${DOCROOT} ${CONTAINER} /usr/local/bin/drush.sh sql-dump | gzip > ${TARGET_FILE}
fi
}
;;
Expand All @@ -51,19 +62,19 @@ case "${FILE}" in
TARGET_FILE="${FILE%.*}.sql.gz"
export_cmd() {
if [ $PV ] ; then
docker exec -t -w /var/www/html/web ${CONTAINER} /usr/local/bin/drush.sh sql-dump | pv | gzip > ${TARGET_FILE}
docker exec -t -w /var/www/html/${DOCROOT} ${CONTAINER} /usr/local/bin/drush.sh sql-dump | pv | gzip > ${TARGET_FILE}
else
docker exec -t -w /var/www/html/web ${CONTAINER} /usr/local/bin/drush.sh sql-dump | gzip > ${TARGET_FILE}
docker exec -t -w /var/www/html/${DOCROOT} ${CONTAINER} /usr/local/bin/drush.sh sql-dump | gzip > ${TARGET_FILE}
fi
}
;;
*.sql )
# it's a normal sql.
export_cmd() {
if [ $PV ] ; then
docker exec -t -w /var/www/html/web ${CONTAINER} /usr/local/bin/drush.sh sql-dump | pv > ${TARGET_FILE}
docker exec -t -w /var/www/html/${DOCROOT} ${CONTAINER} /usr/local/bin/drush.sh sql-dump | pv > ${TARGET_FILE}
else
docker exec -t -w /var/www/html/web ${CONTAINER} /usr/local/bin/drush.sh sql-dump > ${TARGET_FILE}
docker exec -t -w /var/www/html/${DOCROOT} ${CONTAINER} /usr/local/bin/drush.sh sql-dump > ${TARGET_FILE}
fi
}
;;
Expand All @@ -72,9 +83,9 @@ case "${FILE}" in
TARGET_FILE="${FILE}.sql.gz"
export_cmd() {
if [ $PV ] ; then
docker exec -t -w /var/www/html/web ${CONTAINER} /usr/local/bin/drush.sh sql-dump | pv | gzip > ${TARGET_FILE}
docker exec -t -w /var/www/html/${DOCROOT} ${CONTAINER} /usr/local/bin/drush.sh sql-dump | pv | gzip > ${TARGET_FILE}
else
docker exec -t -w /var/www/html/web ${CONTAINER} /usr/local/bin/drush.sh sql-dump | gzip > ${TARGET_FILE}
docker exec -t -w /var/www/html/${DOCROOT} ${CONTAINER} /usr/local/bin/drush.sh sql-dump | gzip > ${TARGET_FILE}
fi
}
;;
Expand Down
17 changes: 14 additions & 3 deletions bin/commands/container/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@
# Executes a phpunit test in the docker container.
CONTAINER=$1

# Finding the DOCROOT...
# @TODO: Find a better way to find out the docroot.
if [ -d "html/docroot" ]
then
echo "Using directory 'docroot' as the DOCROOT..."
DOCROOT='docroot';
else
echo "Using directory 'web' as the DOCROOT..."
DOCROOT='web';
fi

# Eliminating first argument to pass to command script.
args=""
for i in "$@" ; do
if [ "$i" != "$1" ]; then
# Removing "html/web/" from the arguments.
i=${i//html\/web\//}
# Removing "html/${DOCROOT}/" from the arguments.
i=${i//html\/${DOCROOT}\//}
args="${args} $i"
fi
done
# Executing phpunit test.
docker exec -t -w /var/www/html/web $CONTAINER /usr/local/bin/phpunit.sh $args
docker exec -t -w /var/www/html/${DOCROOT} $CONTAINER /usr/local/bin/phpunit.sh $args
6 changes: 3 additions & 3 deletions bin/commands/internal/build_code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ fi

# By default use 'public' repository.
BUILD="${1:-public}"
if [[ ! (-z "$1") && $BUILD != 'public' ]] ; then
BUILD='private'
fi
#if [[ ! (-z "$1") && $BUILD != 'public' ]] ; then
# BUILD='private'
#fi

# If provided a branch name, use it, otherwise use default 8.x-2.x
ACH_BRANCH=$2
Expand Down
12 changes: 6 additions & 6 deletions bin/commands/internal/go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ echo ""
source $SCRIPT_DIRECTORY/../../../setup_options.sh

# Building Source code.
bash $SCRIPT_DIRECTORY/build_code.sh ${CONFIG_BUILD_CODE_SOURCE} ${CONFIG_BUILD_CODE_BRANCH} ${CONFIG_BUILD_DRUPAL_CORE} ${CONFIG_BUILD_PROFILE}
#if [ "${CONFIG_BUILD_CODE_SOURCE}" == 'public' ] ; then
# sh $SCRIPT_DIRECTORY/build_code.sh
#else
# sh $SCRIPT_DIRECTORY/build_code.sh ${CONFIG_BUILD_CODE_SOURCE} ${CONFIG_BUILD_CODE_BRANCH}
#fi
if [ ${CONFIG_BUILD_PROFILE} == 'customer-environment' ]; then
bash $SCRIPT_DIRECTORY/build_code.sh ${CONFIG_BUILD_CODE_REPOSITORY} ${CONFIG_BUILD_CODE_BRANCH} DRUPAL ${CONFIG_BUILD_PROFILE}
else
# By default just use the 'default' profile.
bash $SCRIPT_DIRECTORY/build_code.sh ${CONFIG_BUILD_CODE_SOURCE} ${CONFIG_BUILD_CODE_BRANCH} ${CONFIG_BUILD_DRUPAL_CORE} ${CONFIG_BUILD_PROFILE}
fi

# Building containers.
echo "Building Docker containers."
Expand Down
13 changes: 12 additions & 1 deletion bin/commands/internal/phpcbf.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#!/bin/bash

# Finding the DOCROOT...
# @TODO: Find a better way to find out the docroot.
if [ -d "html/docroot" ]
then
echo "Using directory 'docroot' as the DOCROOT..."
DOCROOT='docroot';
else
echo "Using directory 'web' as the DOCROOT..."
DOCROOT='web';
fi

# Runs phpcs on the acquia_contenthub module.
echo "Fixing Coding Standards for 'acquia_contenthub' module..."
cd html
./vendor/bin/phpcbf --standard=Drupal web/modules/contrib/acquia_contenthub/src web/modules/contrib/acquia_contenthub/tests
./vendor/bin/phpcbf --standard=Drupal ${DOCROOT}/modules/contrib/acquia_contenthub/src ${DOCROOT}/modules/contrib/acquia_contenthub/tests
13 changes: 12 additions & 1 deletion bin/commands/internal/phpcs.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#!/bin/bash

# Finding the DOCROOT...
# @TODO: Find a better way to find out the docroot.
if [ -d "html/docroot" ]
then
echo "Using directory 'docroot' as the DOCROOT..."
DOCROOT='docroot';
else
echo "Using directory 'web' as the DOCROOT..."
DOCROOT='web';
fi

# Runs phpcs on the acquia_contenthub module.
echo "Checking Coding Standards for 'acquia_contenthub' module..."
cd html
./vendor/bin/phpcs -n --standard=Drupal web/modules/contrib/acquia_contenthub/src
./vendor/bin/phpcs -n --standard=Drupal ${DOCROOT}/modules/contrib/acquia_contenthub/src
143 changes: 86 additions & 57 deletions bin/commands/internal/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,90 @@ echo "CONFIG_MYSQL_LOCAL_PORT=\"${CONFIG_MYSQL_LOCAL_PORT}\";" >> ${SETUP_FILE}
echo "" >> ${SETUP_FILE}
echo ""

# Build code using Build Profiles.

# Obtaining list of available profiles.
PROFILE_FILES=`ls -1 ${SCRIPT_DIRECTORY}/../../profiles/ | sed -e 's/\.sh$//'`
BUILD_PROFILES=()
for i in ${PROFILE_FILES}; do
BUILD_PROFILES=("${BUILD_PROFILES[@]}" "$i")
done

echo "Select a Build Profile:"
select BUILD_PROFILE in "${BUILD_PROFILES[@]}"
do
CONFIG_BUILD_PROFILE="${BUILD_PROFILE##*/}"
if ! [[ "$REPLY" =~ ^[0-9]+$ ]]; then
echo " Incorrect Input: Select a number from the options presented."
elif [ 1 -le "$REPLY" ] && [ "$REPLY" -le $((${#BUILD_PROFILES[@]})) ]; then
echo "You selected Build Profile: \"$CONFIG_BUILD_PROFILE\"."
break;
else
echo "Incorrect Input: Select a number from the options presented."
fi
done

# If user selects customer environment the provide git repository.
case $CONFIG_BUILD_PROFILE in
"customer-environment")
# This is the "Customer Environment" Profile.
echo "To replicate a Customer Environment, please provide the Git Repository and branch/tag to clone it from."
echo "If you already have the code deployed in 'html' directory, leave 'Git Repository' and 'branch/tag' blank."
echo ""
while : ; do
read -p "Insert the Customer's Git Repository (blank if deployed in 'html'): " CONFIG_BUILD_CODE_REPOSITORY
read -p "Insert the branch/tag name (blank if deployed in 'html'): " CONFIG_BUILD_CODE_BRANCH
echo "Are the following values correct:"
echo " - Customer's Git Repository = ${CONFIG_BUILD_CODE_REPOSITORY}"
echo " - Branch/tag name = ${CONFIG_BUILD_CODE_BRANCH}"
read -p "(y/n)? " line
[[ ! $line =~ ^[Yy]$ ]] || break
done
CONFIG_BUILD_CODE_REPOSITORY="${CONFIG_BUILD_CODE_REPOSITORY:-NONE}"
CONFIG_BUILD_CODE_BRANCH="${CONFIG_BUILD_CODE_BRANCH:-NONE}"
echo "Saving Customer Environment information..."
echo "# Build Site Codebase." >> ${SETUP_FILE}
echo "CONFIG_BUILD_PROFILE=\"${CONFIG_BUILD_PROFILE}\";" >> ${SETUP_FILE}
echo "CONFIG_BUILD_CODE_REPOSITORY=\"${CONFIG_BUILD_CODE_REPOSITORY}\";" >> ${SETUP_FILE}
echo "CONFIG_BUILD_CODE_BRANCH=\"${CONFIG_BUILD_CODE_BRANCH}\";" >> ${SETUP_FILE}
;;
*)
# This is the "Default" Profile.
echo "Do you want to install Acquia Content Hub from Public or Private Repository?"
CONFIG_BUILD_CODE_SOURCE="public"
CONFIG_BUILD_CODE_BRANCH="^2"
options=("Public" "Private")
select opt in "${options[@]}"
do
case $opt in
"Public")
echo "Using latest public release of Content Hub 2.x from Drupal.org."
break;
;;
"Private")
CONFIG_BUILD_CODE_SOURCE="private"
echo "Using Acquia's Private repository."
read -p "Insert a Branch (8.x-2.x): " CONFIG_BUILD_CODE_BRANCH
CONFIG_BUILD_CODE_BRANCH="${CONFIG_BUILD_CODE_BRANCH:-"8.x-2.x"}"
break;
;;
*) echo "Invalid option $REPLY";;
esac
done
echo "Select the version of Drupal core you want to use. Default is D8 (^8). You can also select D9 (^9)."
read -p "Drupal Core (^8): " CONFIG_BUILD_DRUPAL_CORE
CONFIG_BUILD_DRUPAL_CORE="${CONFIG_BUILD_DRUPAL_CORE:-^8}"

echo "# Build Site Codebase." >> ${SETUP_FILE}
echo "CONFIG_BUILD_PROFILE=\"${CONFIG_BUILD_PROFILE}\";" >> ${SETUP_FILE}
echo "CONFIG_BUILD_CODE_SOURCE=\"${CONFIG_BUILD_CODE_SOURCE}\";" >> ${SETUP_FILE}
echo "CONFIG_BUILD_CODE_BRANCH=\"${CONFIG_BUILD_CODE_BRANCH}\";" >> ${SETUP_FILE}
echo "CONFIG_BUILD_DRUPAL_CORE=\"${CONFIG_BUILD_DRUPAL_CORE}\";" >> ${SETUP_FILE}
;;
esac
echo "" >> ${SETUP_FILE}
echo ""

# Number of Publishers/Subscribers.
echo "Number of Publishers / Subscribers."
while : ; do
Expand All @@ -83,14 +167,14 @@ echo ""
# Looping through each Publisher.
for (( i=1; i<=${CONFIG_NUM_PUBLISHERS}; i++ ))
do
bash $SCRIPT_DIRECTORY/../../include/setup_publisher.sh $i
bash $SCRIPT_DIRECTORY/../../include/setup_publisher.sh $i ${CONFIG_BUILD_PROFILE}
echo ""
done

# Looping through each Subscriber.
for (( i=1; i<=${CONFIG_NUM_SUBSCRIBERS}; i++ ))
do
bash $SCRIPT_DIRECTORY/../../include/setup_subscriber.sh $i ${CONFIG_NUM_PUBLISHERS}
bash $SCRIPT_DIRECTORY/../../include/setup_subscriber.sh $i ${CONFIG_NUM_PUBLISHERS} ${CONFIG_BUILD_PROFILE}
echo ""
done

Expand All @@ -105,61 +189,6 @@ echo "CONFIG_NGROK_TOKEN=\"${CONFIG_NGROK_TOKEN}\";" >> ${SETUP_FILE}
echo "" >> ${SETUP_FILE}
echo ""

# Build code using public or private Content Hub repository.

# Obtaining list of available profiles.
PROFILE_FILES=`ls -1 ${SCRIPT_DIRECTORY}/../../profiles/ | sed -e 's/\.sh$//'`
BUILD_PROFILES=()
for i in ${PROFILE_FILES}; do
BUILD_PROFILES=("${BUILD_PROFILES[@]}" "$i")
done

echo "Select a Build Profile:"
select BUILD_PROFILE in "${BUILD_PROFILES[@]}"
do
CONFIG_BUILD_PROFILE="${BUILD_PROFILE##*/}"
if ! [[ "$REPLY" =~ ^[0-9]+$ ]]; then
echo " Incorrect Input: Select a number from the options presented."
elif [ 1 -le "$REPLY" ] && [ "$REPLY" -le $((${#BUILD_PROFILES[@]})) ]; then
echo "You selected Build Profile: \"$CONFIG_BUILD_PROFILE\"."
break;
else
echo "Incorrect Input: Select a number from the options presented."
fi
done

echo "Do you want to install Acquia Content Hub from Public or Private Repository?"
CONFIG_BUILD_CODE_SOURCE="public"
CONFIG_BUILD_CODE_BRANCH="^2"
options=("Public" "Private")
select opt in "${options[@]}"
do
case $opt in
"Public")
echo "Using latest public release of Content Hub 2.x from Drupal.org."
break;
;;
"Private")
CONFIG_BUILD_CODE_SOURCE="private"
echo "Using Acquia's Private repository."
read -p "Insert a Branch (8.x-2.x): " CONFIG_BUILD_CODE_BRANCH
CONFIG_BUILD_CODE_BRANCH="${CONFIG_BUILD_CODE_BRANCH:-"8.x-2.x"}"
break;
;;
*) echo "Invalid option $REPLY";;
esac
done
echo "Select the version of Drupal core you want to use. Default is D8 (^8). You can also select D9 (^9)."
read -p "Drupal Core (^8): " CONFIG_BUILD_DRUPAL_CORE
CONFIG_BUILD_DRUPAL_CORE="${CONFIG_BUILD_DRUPAL_CORE:-^8}"

echo "# Build Site Codebase." >> ${SETUP_FILE}
echo "CONFIG_BUILD_PROFILE=\"${CONFIG_BUILD_PROFILE}\";" >> ${SETUP_FILE}
echo "CONFIG_BUILD_CODE_SOURCE=\"${CONFIG_BUILD_CODE_SOURCE}\";" >> ${SETUP_FILE}
echo "CONFIG_BUILD_CODE_BRANCH=\"${CONFIG_BUILD_CODE_BRANCH}\";" >> ${SETUP_FILE}
echo "CONFIG_BUILD_DRUPAL_CORE=\"${CONFIG_BUILD_DRUPAL_CORE}\";" >> ${SETUP_FILE}
echo ""

echo "Configuration Options saved in './setup_options.sh'."
echo "Creating docker-compose.yml file."

Expand Down
13 changes: 12 additions & 1 deletion bin/include/setup_publisher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CONTENT_HUB_FARM=`echo ${CONTENT_HUB_FARM_DIRECTORY} | tr - _`;

# Setting up initial definitions.
COUNT=$1
CONFIG_BUILD_PROFILE=$2
CONFIG_PUB_BINDING_PORT[${COUNT}]=$((8080+${COUNT}))
IP=$((10+${COUNT}))
CONFIG_PUB_IP_ADDRESS[${COUNT}]="192.168.1.${IP}"
Expand All @@ -19,20 +20,27 @@ while : ; do
CONFIG_PUB_HOSTNAME_DEFAULT="publisher${COUNT}.ngrok.io"
CONFIG_PUB_HOSTNAME[$COUNT]="${CONFIG_PUB_HOSTNAME[$COUNT]:-${CONFIG_PUB_HOSTNAME_DEFAULT}}"
read -p "Insert your Acquia Content Client Name: " CONFIG_PUB_ACH_CLIENT_NAME[$COUNT]
if [ ${CONFIG_BUILD_PROFILE} == 'customer-environment' ]; then
read -p "DATABASE_BACKUP (filename inside 'backups' directory): " CONFIG_PUB_DATABASE_BACKUP[$COUNT]
fi
echo "The following are Environmental variables used for PHP Debugging."
echo "If you are unsure about the values, just leave them blank and we will do our best guess to set defaults."
echo "You can always change them later."
read -p "PHP_IDE_CONFIG: " CONFIG_PUB_PHP_IDE_CONFIG[$COUNT]
PHP_IDE_CONFIG_DEFAULT="serverName=${CONTENT_HUB_FARM}_publisher${COUNT}_1"
CONFIG_PUB_PHP_IDE_CONFIG[$COUNT]="${CONFIG_PUB_PHP_IDE_CONFIG[$COUNT]:-${PHP_IDE_CONFIG_DEFAULT}}"
read -p "XDEBUG_CONFIG: " CONFIG_PUB_XDEBUG_CONFIG[$COUNT]
XDEBUG_CONFIG_DEFAULT="remote_port=9000 remote_autostart=1"
XDEBUG_CONFIG_DEFAULT="remote_port=9003 remote_autostart=1"
CONFIG_PUB_XDEBUG_CONFIG[$COUNT]="${CONFIG_PUB_XDEBUG_CONFIG[$COUNT]:-${XDEBUG_CONFIG_DEFAULT}}"


# Asking for verification.
echo "Are the following values correct:"
echo " - Publisher$COUNT Hostname: ${CONFIG_PUB_HOSTNAME[$COUNT]}"
echo " - Acquia Content Client Name: ${CONFIG_PUB_ACH_CLIENT_NAME[$COUNT]}"
if [ ${CONFIG_BUILD_PROFILE} == 'customer-environment' ]; then
echo " - DATABASE_BACKUP: \"${CONFIG_PUB_DATABASE_BACKUP[$COUNT]}\""
fi
echo " - PHP_IDE_CONFIG: ${CONFIG_PUB_PHP_IDE_CONFIG[$COUNT]}"
echo " - XDEBUG_CONFIG: \"${CONFIG_PUB_XDEBUG_CONFIG[$COUNT]}\""
read -p "(y/n)? " line
Expand All @@ -43,6 +51,9 @@ echo "Saving Publisher$COUNT configuration..."
echo "# Publisher$COUNT." >> ${SETUP_FILE}
echo "CONFIG_PUB_HOSTNAME[${COUNT}]=\"${CONFIG_PUB_HOSTNAME[${COUNT}]}\";" >> ${SETUP_FILE}
echo "CONFIG_PUB_ACH_CLIENT_NAME[${COUNT}]=\"${CONFIG_PUB_ACH_CLIENT_NAME[${COUNT}]}\";" >> ${SETUP_FILE}
if [ ${CONFIG_BUILD_PROFILE} == 'customer-environment' ]; then
echo "CONFIG_PUB_DATABASE_BACKUP[${COUNT}]=\"${CONFIG_PUB_DATABASE_BACKUP[${COUNT}]}\";" >> ${SETUP_FILE}
fi
echo "CONFIG_PUB_PHP_IDE_CONFIG[${COUNT}]=\"${CONFIG_PUB_PHP_IDE_CONFIG[${COUNT}]}\";" >> ${SETUP_FILE}
echo "CONFIG_PUB_XDEBUG_CONFIG[${COUNT}]=\"${CONFIG_PUB_XDEBUG_CONFIG[${COUNT}]}\";" >> ${SETUP_FILE}
echo "CONFIG_PUB_BINDING_PORT[${COUNT}]=\"${CONFIG_PUB_BINDING_PORT[${COUNT}]}\";" >> ${SETUP_FILE}
Expand Down
Loading