diff --git a/README.md b/README.md index 1263b39..1be82b4 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/backups/.gitignore b/backups/.gitignore new file mode 100644 index 0000000..6af79d9 --- /dev/null +++ b/backups/.gitignore @@ -0,0 +1,4 @@ +# Please put all database backups inside this directory. +* +# Ignore (but don't delete) this line +!.gitignore diff --git a/bin/commands/container/export-db.sh b/bin/commands/container/export-db.sh index 84c577a..2d43b92 100755 --- a/bin/commands/container/export-db.sh +++ b/bin/commands/container/export-db.sh @@ -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 "" @@ -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 } ;; @@ -51,9 +62,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 } ;; @@ -61,9 +72,9 @@ case "${FILE}" in # 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 } ;; @@ -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 } ;; diff --git a/bin/commands/container/test.sh b/bin/commands/container/test.sh index a69c8f1..9b32850 100755 --- a/bin/commands/container/test.sh +++ b/bin/commands/container/test.sh @@ -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 diff --git a/bin/commands/internal/build_code.sh b/bin/commands/internal/build_code.sh index 69fcb2d..3af77ad 100755 --- a/bin/commands/internal/build_code.sh +++ b/bin/commands/internal/build_code.sh @@ -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 diff --git a/bin/commands/internal/go.sh b/bin/commands/internal/go.sh index 0242872..cdb35fb 100755 --- a/bin/commands/internal/go.sh +++ b/bin/commands/internal/go.sh @@ -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." diff --git a/bin/commands/internal/phpcbf.sh b/bin/commands/internal/phpcbf.sh index 6d68a76..adb164e 100755 --- a/bin/commands/internal/phpcbf.sh +++ b/bin/commands/internal/phpcbf.sh @@ -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 diff --git a/bin/commands/internal/phpcs.sh b/bin/commands/internal/phpcs.sh index 37dfc71..685d61b 100755 --- a/bin/commands/internal/phpcs.sh +++ b/bin/commands/internal/phpcs.sh @@ -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 diff --git a/bin/commands/internal/setup.sh b/bin/commands/internal/setup.sh index a7ce082..8a85df7 100755 --- a/bin/commands/internal/setup.sh +++ b/bin/commands/internal/setup.sh @@ -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 @@ -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 @@ -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." diff --git a/bin/include/setup_publisher.sh b/bin/include/setup_publisher.sh index f6fdde7..e174fef 100755 --- a/bin/include/setup_publisher.sh +++ b/bin/include/setup_publisher.sh @@ -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}" @@ -19,6 +20,9 @@ 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." @@ -26,13 +30,17 @@ while : ; do 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 @@ -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} diff --git a/bin/include/setup_subscriber.sh b/bin/include/setup_subscriber.sh index 03d47c2..cd2b540 100755 --- a/bin/include/setup_subscriber.sh +++ b/bin/include/setup_subscriber.sh @@ -8,6 +8,7 @@ CONTENT_HUB_FARM=`echo ${CONTENT_HUB_FARM_DIRECTORY} | tr - _`; # Setting up initial definitions. COUNT=$1 NUM_PUBLISHERS=$2 +CONFIG_BUILD_PROFILE=$3 CONFIG_SUB_BINDING_PORT[${COUNT}]=$((8080+${NUM_PUBLISHERS}+${COUNT})) IP=$((10+${NUM_PUBLISHERS}+${COUNT})) CONFIG_SUB_IP_ADDRESS[${COUNT}]="192.168.1.${IP}" @@ -20,6 +21,9 @@ while : ; do CONFIG_SUB_HOSTNAME_DEFAULT="subscriber${COUNT}.ngrok.io" CONFIG_SUB_HOSTNAME[$COUNT]="${CONFIG_SUB_HOSTNAME[$COUNT]:-${CONFIG_SUB_HOSTNAME_DEFAULT}}" read -p "Insert your Acquia Content Client Name: " CONFIG_SUB_ACH_CLIENT_NAME[$COUNT] + if [ ${CONFIG_BUILD_PROFILE} == 'customer-environment' ]; then + read -p "DATABASE_BACKUP (filename inside 'backups' directory): " CONFIG_SUB_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." @@ -27,13 +31,16 @@ while : ; do PHP_IDE_CONFIG_DEFAULT="serverName=${CONTENT_HUB_FARM}_subscriber${COUNT}_1" CONFIG_SUB_PHP_IDE_CONFIG[$COUNT]="${CONFIG_SUB_PHP_IDE_CONFIG[$COUNT]:-${PHP_IDE_CONFIG_DEFAULT}}" read -p "XDEBUG_CONFIG: " CONFIG_SUB_XDEBUG_CONFIG[$COUNT] - XDEBUG_CONFIG_DEFAULT="remote_port=9000 remote_autostart=1" + XDEBUG_CONFIG_DEFAULT="remote_port=9003 remote_autostart=1" CONFIG_SUB_XDEBUG_CONFIG[$COUNT]="${CONFIG_SUB_XDEBUG_CONFIG[$COUNT]:-${XDEBUG_CONFIG_DEFAULT}}" # Asking for verification. echo "Are the following values correct:" echo " - Subscriber$COUNT Hostname: ${CONFIG_SUB_HOSTNAME[$COUNT]}" echo " - Acquia Content Client Name: ${CONFIG_SUB_ACH_CLIENT_NAME[$COUNT]}" + if [ ${CONFIG_BUILD_PROFILE} == 'customer-environment' ]; then + echo " - DATABASE_BACKUP: \"${CONFIG_SUB_DATABASE_BACKUP[$COUNT]}\"" + fi echo " - PHP_IDE_CONFIG: ${CONFIG_SUB_PHP_IDE_CONFIG[$COUNT]}" echo " - XDEBUG_CONFIG: \"${CONFIG_SUB_XDEBUG_CONFIG[$COUNT]}\"" read -p "(y/n)? " line @@ -44,6 +51,9 @@ echo "Saving Subscriber$COUNT configuration..." echo "# Subscriber$COUNT." >> ${SETUP_FILE} echo "CONFIG_SUB_HOSTNAME[${COUNT}]=\"${CONFIG_SUB_HOSTNAME[${COUNT}]}\";" >> ${SETUP_FILE} echo "CONFIG_SUB_ACH_CLIENT_NAME[${COUNT}]=\"${CONFIG_SUB_ACH_CLIENT_NAME[${COUNT}]}\";" >> ${SETUP_FILE} +if [ ${CONFIG_BUILD_PROFILE} == 'customer-environment' ]; then + echo "CONFIG_SUB_DATABASE_BACKUP[${COUNT}]=\"${CONFIG_SUB_DATABASE_BACKUP[${COUNT}]}\";" >> ${SETUP_FILE} +fi echo "CONFIG_SUB_PHP_IDE_CONFIG[${COUNT}]=\"${CONFIG_SUB_PHP_IDE_CONFIG[${COUNT}]}\";" >> ${SETUP_FILE} echo "CONFIG_SUB_XDEBUG_CONFIG[${COUNT}]=\"${CONFIG_SUB_XDEBUG_CONFIG[${COUNT}]}\";" >> ${SETUP_FILE} echo "CONFIG_SUB_BINDING_PORT[${COUNT}]=\"${CONFIG_SUB_BINDING_PORT[${COUNT}]}\";" >> ${SETUP_FILE} diff --git a/bin/profiles/customer-environment.sh b/bin/profiles/customer-environment.sh new file mode 100644 index 0000000..e768182 --- /dev/null +++ b/bin/profiles/customer-environment.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +SCRIPT_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +# Build Code base. + +# Project Document Base Root Folder. +BASE_ROOT=html + +# Gathering data to build the code base. +GIT_REPOSITORY="${1:-'NONE'}" +GIT_BRANCH="${2:-'NONE'}" + +if [ $GIT_REPOSITORY == 'NONE' ] || [ $GIT_BRANCH == 'NONE' ] ; then + echo "Using existing codebase from '${BASE_ROOT}'." + echo "---------------------------------------------------" +else + echo "Building Codebase from Customer Repository using GIT REPOSITORY = '${GIT_REPOSITORY}' and GIT BRANCH = '${GIT_BRANCH}'." + echo "---------------------------------------------------" + if [ -d "$BASE_ROOT" ]; then + echo "Cleaning up existing directory $BASE_ROOT" + chmod -R 777 $BASE_ROOT + rm -Rf $BASE_ROOT + else + echo "Creating directory $BASE_ROOT" + mkdir $BASE_ROOT + fi + echo "Done." + echo "Building Drupal project in folder '${BASE_ROOT}'..." + git clone --branch ${GIT_BRANCH} --single-branch --depth=1 ${GIT_REPOSITORY} ${BASE_ROOT} + echo "Done." +fi +# echo "Adding Drupal contrib modules..." +cd $BASE_ROOT || exit + +# DO NOT MODIFY THIS LIST OF PACKAGES. +# COMPOSER_MEMORY_LIMIT=-1 composer require drupal/environment_indicator \ +# drupal/admin_toolbar \ + +# ------------------------------------------------------------- +# echo "Done." + +# Finding the DOCROOT... +# @TODO: Find a better way to find out the docroot. +if [ -d "./docroot" ] +then + echo "Using directory 'docroot' as the DOCROOT..." + DOCROOT='docroot'; +else + echo "Using directory 'web' as the DOCROOT..." + DOCROOT='web'; +fi + +chmod -R 777 ${DOCROOT}/sites + +# Apply Content Hub patch. +PATCH_FILE="${SCRIPT_DIRECTORY}/../../config/patches/no-client-cdf-update.patch" +ACH_FOLDER=`find ./ -iname acquia_contenthub` +cd ${ACH_FOLDER} || exit + +echo "Applying patch 'config/patches/no-client-cdf-update.patch'..." +patch -p1 < $PATCH_FILE + +# Configure Coding Standards +# ./vendor/bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer +echo "Done." diff --git a/bin/templates/_examples/docker-compose-nfs-disabled.yml b/bin/templates/_examples/docker-compose-nfs-disabled.yml index 0363d95..c7b50a2 100644 --- a/bin/templates/_examples/docker-compose-nfs-disabled.yml +++ b/bin/templates/_examples/docker-compose-nfs-disabled.yml @@ -31,7 +31,7 @@ services: - PERSISTENT=true - ACH_CLIENT_NAME=publisher1-docker - PHP_IDE_CONFIG="serverName=content-hub-farm_publisher_1" - - XDEBUG_CONFIG=remote_port=9000 remote_autostart=1 + - XDEBUG_CONFIG=remote_port=9003 remote_autostart=1 volumes: - ./html:/var/www/html ports: @@ -51,7 +51,7 @@ services: - PERSISTENT=true - ACH_CLIENT_NAME=subscriber1-docker - PHP_IDE_CONFIG=serverName=content-hub-farm_subscriber1_1 - - XDEBUG_CONFIG=remote_port=9000 remote_autostart=1 + - XDEBUG_CONFIG=remote_port=9003 remote_autostart=1 volumes: - ./html:/var/www/html ports: diff --git a/bin/templates/_examples/docker-compose-nfs_enabled.yml b/bin/templates/_examples/docker-compose-nfs_enabled.yml index 5925382..4867ccd 100644 --- a/bin/templates/_examples/docker-compose-nfs_enabled.yml +++ b/bin/templates/_examples/docker-compose-nfs_enabled.yml @@ -31,7 +31,7 @@ services: - PERSISTENT=true - ACH_CLIENT_NAME=publisher1-docker - PHP_IDE_CONFIG="serverName=content-hub-farm_publisher_1" - - XDEBUG_CONFIG=remote_port=9000 remote_autostart=1 + - XDEBUG_CONFIG=remote_port=9003 remote_autostart=1 volumes: - type: volume source: nfsmount @@ -55,7 +55,7 @@ services: - PERSISTENT=true - ACH_CLIENT_NAME=subscriber1-docker - PHP_IDE_CONFIG=serverName=content-hub-farm_subscriber1_1 - - XDEBUG_CONFIG=remote_port=9000 remote_autostart=1 + - XDEBUG_CONFIG=remote_port=9003 remote_autostart=1 volumes: - type: volume source: nfsmount diff --git a/bin/templates/default/database.tpl.sh b/bin/templates/default/database.tpl.sh index 10fd7bc..d5d6f46 100644 --- a/bin/templates/default/database.tpl.sh +++ b/bin/templates/default/database.tpl.sh @@ -14,7 +14,7 @@ services: hostname: database.docker build: context: ./database - command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci + command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --max_allowed_packet=64MB restart: always environment: MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD diff --git a/bin/templates/default/publisher.tpl.sh b/bin/templates/default/publisher.tpl.sh index 1d45e34..5195cfd 100644 --- a/bin/templates/default/publisher.tpl.sh +++ b/bin/templates/default/publisher.tpl.sh @@ -18,10 +18,12 @@ cat << EOF - SITE_ROLE=publisher - PERSISTENT=true - ACH_CLIENT_NAME=${CONFIG_PUB_ACH_CLIENT_NAME[$COUNT]} + - DATABASE_BACKUP=${CONFIG_PUB_DATABASE_BACKUP[$COUNT]} - PHP_IDE_CONFIG=${CONFIG_PUB_PHP_IDE_CONFIG[$COUNT]} - XDEBUG_CONFIG=${CONFIG_PUB_XDEBUG_CONFIG[$COUNT]} volumes: - ./html:/var/www/html + - ./backups:/var/www/backups ports: - ${CONFIG_PUB_BINDING_PORT[${COUNT}]}:80 networks: diff --git a/bin/templates/default/subscriber.tpl.sh b/bin/templates/default/subscriber.tpl.sh index 453e204..a1187d7 100644 --- a/bin/templates/default/subscriber.tpl.sh +++ b/bin/templates/default/subscriber.tpl.sh @@ -18,10 +18,12 @@ cat << EOF - SITE_ROLE=subscriber - PERSISTENT=true - ACH_CLIENT_NAME=${CONFIG_SUB_ACH_CLIENT_NAME[$COUNT]} + - DATABASE_BACKUP=${CONFIG_SUB_DATABASE_BACKUP[$COUNT]} - PHP_IDE_CONFIG=${CONFIG_SUB_PHP_IDE_CONFIG[$COUNT]} - XDEBUG_CONFIG=${CONFIG_SUB_XDEBUG_CONFIG[$COUNT]} volumes: - ./html:/var/www/html + - ./backups:/var/www/backups ports: - ${CONFIG_SUB_BINDING_PORT[${COUNT}]}:80 networks: diff --git a/bin/templates/nfs/database.tpl.sh b/bin/templates/nfs/database.tpl.sh index 75bce6c..4f62f68 100644 --- a/bin/templates/nfs/database.tpl.sh +++ b/bin/templates/nfs/database.tpl.sh @@ -15,7 +15,7 @@ services: hostname: database.docker build: context: ./database - command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci + command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --max_allowed_packet=64MB restart: always environment: MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD diff --git a/bin/templates/nfs/network_volume.tpl.sh b/bin/templates/nfs/network_volume.tpl.sh index b2d0932..3b42900 100644 --- a/bin/templates/nfs/network_volume.tpl.sh +++ b/bin/templates/nfs/network_volume.tpl.sh @@ -21,4 +21,10 @@ volumes: type: "nfs" o: "addr=host.docker.internal,hard,nolock,rw" device: ":/System/Volumes/Data/${CONFIG_VOLUME_DEVICE_PATH}/html" + backups: + driver: local + driver_opts: + type: "nfs" + o: "addr=host.docker.internal,hard,nolock,rw" + device: ":/System/Volumes/Data/${CONFIG_VOLUME_DEVICE_PATH}/backups" EOF \ No newline at end of file diff --git a/bin/templates/nfs/publisher.tpl.sh b/bin/templates/nfs/publisher.tpl.sh index 56fa1bf..f7bf685 100644 --- a/bin/templates/nfs/publisher.tpl.sh +++ b/bin/templates/nfs/publisher.tpl.sh @@ -18,6 +18,7 @@ cat << EOF - SITE_ROLE=publisher - PERSISTENT=true - ACH_CLIENT_NAME=${CONFIG_PUB_ACH_CLIENT_NAME[$COUNT]} + - DATABASE_BACKUP=${CONFIG_PUB_DATABASE_BACKUP[$COUNT]} - PHP_IDE_CONFIG=${CONFIG_PUB_PHP_IDE_CONFIG[$COUNT]} - XDEBUG_CONFIG=${CONFIG_PUB_XDEBUG_CONFIG[$COUNT]} volumes: @@ -26,6 +27,11 @@ cat << EOF target: /var/www/html volume: nocopy: true + - type: volume + source: backups + target: /var/www/backups + volume: + nocopy: true ports: - ${CONFIG_PUB_BINDING_PORT[${COUNT}]}:80 networks: diff --git a/bin/templates/nfs/subscriber.tpl.sh b/bin/templates/nfs/subscriber.tpl.sh index a2a3c0c..c2735a6 100644 --- a/bin/templates/nfs/subscriber.tpl.sh +++ b/bin/templates/nfs/subscriber.tpl.sh @@ -18,6 +18,7 @@ cat << EOF - SITE_ROLE=subscriber - PERSISTENT=true - ACH_CLIENT_NAME=${CONFIG_SUB_ACH_CLIENT_NAME[$COUNT]} + - DATABASE_BACKUP=${CONFIG_SUB_DATABASE_BACKUP[$COUNT]} - PHP_IDE_CONFIG=${CONFIG_SUB_PHP_IDE_CONFIG[$COUNT]} - XDEBUG_CONFIG=${CONFIG_SUB_XDEBUG_CONFIG[$COUNT]} volumes: @@ -26,6 +27,11 @@ cat << EOF target: /var/www/html volume: nocopy: true + - type: volume + source: backups + target: /var/www/backups + volume: + nocopy: true ports: - ${CONFIG_SUB_BINDING_PORT[${COUNT}]}:80 networks: diff --git a/config/00_xdebug.conf b/config/00_xdebug.conf index 995cc3e..667a914 100644 --- a/config/00_xdebug.conf +++ b/config/00_xdebug.conf @@ -16,7 +16,7 @@ xdebug.remote_addr_header = host.docker.internal # --------------------------------------------------------------------------------------------------------------------- # If values are changed, you would need to rebuild the containers. -xdebug.remote_port = 9000 +xdebug.remote_port = 9003 # Setting up remote session to a max of 20min. Also check PHP and Nginx timeouts. xdebug.remote_timeout = 1200 diff --git a/config/patches/no-client-cdf-update.patch b/config/patches/no-client-cdf-update.patch new file mode 100644 index 0000000..8b9d297 --- /dev/null +++ b/config/patches/no-client-cdf-update.patch @@ -0,0 +1,12 @@ +diff --git a/src/Client/ClientFactory.php b/src/Client/ClientFactory.php +index 7cca5507..d2c947ee 100755 +--- a/src/Client/ClientFactory.php ++++ b/src/Client/ClientFactory.php +@@ -254,6 +254,7 @@ class ClientFactory { + * @throws \ReflectionException + */ + public function updateClientCdf() { ++ return true; + /** @var \Acquia\ContentHubClient\CDF\ClientCDFObject $remote_cdf */ + $remote_cdf = $this->client->getEntity($this->settings->getUuid()); + // Don't update the ClientCDF if the remote object matches the local one. diff --git a/scripts/phpunit.sh b/scripts/phpunit.sh index 3af4b19..874499e 100755 --- a/scripts/phpunit.sh +++ b/scripts/phpunit.sh @@ -1,16 +1,27 @@ #!/bin/bash +# Finding the DOCROOT... +# @TODO: Find a better way to find out the docroot. +if [ -d "/var/www/html/docroot" ] +then + echo "Using directory 'docroot' as the DOCROOT..." + DOCROOT='docroot'; +else + echo "Using directory 'web' as the DOCROOT..." + DOCROOT='web'; +fi + # Setting up variables. DB_NAME=$(echo "${HOSTNAME//[-._]}" | awk -F'.' '{print $1}') #PHPUNIT=/var/www/html/vendor/bin/phpunit PHPUNIT=../vendor/bin/phpunit -#PHPUNIT_XML="/var/www/html/web/core/phpunit-${DB_NAME}.xml" +#PHPUNIT_XML="/var/www/html/${DOCROOT}/core/phpunit-${DB_NAME}.xml" PHPUNIT_XML="./core/phpunit-${DB_NAME}.xml" # Executing PHPUnit tests. -echo "Running test from DOCROOT=\"/var/www/html/web\":" +echo "Running test from DOCROOT=\"/var/www/html/${DOCROOT}\":" command="$PHPUNIT --color=always --stop-on-failure -c $PHPUNIT_XML $@" echo "Executing: \$$command" echo "" -cd /var/www/html/web || return +cd /var/www/html/${DOCROOT} || return $PHPUNIT --color=always --stop-on-failure -c $PHPUNIT_XML "$@" diff --git a/scripts/publisher_install.sh b/scripts/publisher_install.sh index 5faf685..37ccff5 100755 --- a/scripts/publisher_install.sh +++ b/scripts/publisher_install.sh @@ -2,6 +2,17 @@ DRUSH="/var/www/html/vendor/bin/drush -l ${HOSTNAME}" +# Finding the DOCROOT... +# @TODO: Find a better way to find out the docroot. +if [ -d "/var/www/html/docroot" ] +then + echo "Using directory 'docroot' as the DOCROOT..." + DOCROOT='docroot'; +else + echo "Using directory 'web' as the DOCROOT..." + DOCROOT='web'; +fi + # ------------------------------------------------------------- # Enable additional contrib/custom modules for publishers. echo "Enabling additional contributed modules for publishers..." @@ -17,7 +28,7 @@ $DRUSH pm-enable -y acquia_contenthub \ echo "Done." # Adding additional configuration to settings.php. -SETTINGS_PHP=/var/www/html/web/sites/${HOSTNAME}/settings.php +SETTINGS_PHP=/var/www/html/${DOCROOT}/sites/${HOSTNAME}/settings.php echo "Adding additional publisher configuration to settings.php ..." chmod u+w ${SETTINGS_PHP} echo " diff --git a/scripts/site_installation.sh b/scripts/site_installation.sh index f078c26..6bc5e99 100755 --- a/scripts/site_installation.sh +++ b/scripts/site_installation.sh @@ -12,80 +12,104 @@ DB_PASS='db'; DB_HOST='database'; DB_NAME=`echo ${HOSTNAME//[-._]} | awk -F'.' '{print $1}'` +# Finding the DOCROOT... +# @TODO: Find a better way to find out the docroot. +if [ -d "/var/www/html/docroot" ] +then + echo "Using directory 'docroot' as the DOCROOT..." + DOCROOT='docroot'; +else + echo "Using directory 'web' as the DOCROOT..." + DOCROOT='web'; +fi + # Use the hostname as database name. Create it if it does not exist yet. mysql -u${DB_USER} -p${DB_PASS} -h${DB_HOST} -s -N -e "CREATE DATABASE IF NOT EXISTS ${DB_NAME};" DB_URL="mysql://${DB_USER}:${DB_PASS}@${DB_HOST}:3306/${DB_NAME}" # If the site is not persistent then delete it and start over. if [ ${PERSISTENT} = false ]; then - chmod -R 777 /var/www/html/web/sites/${HOSTNAME} - rm -Rf /var/www/html/web/sites/${HOSTNAME} + chmod -R 777 /var/www/html/${DOCROOT}/sites/${HOSTNAME} + rm -Rf /var/www/html/${DOCROOT}/sites/${HOSTNAME} fi # Verifying if site is installed. -FILE=/var/www/html/web/sites/${HOSTNAME}/settings.php +FILE=/var/www/html/${DOCROOT}/sites/${HOSTNAME}/settings.php echo "Checking file: ${FILE}" if [ -f "$FILE" ]; then echo "Site ${HOSTNAME} is already installed." else echo "Installing Drupal for site ${HOSTNAME}." - mkdir /var/www/html/web/sites/${HOSTNAME} - chmod -R 777 /var/www/html/web/sites/${HOSTNAME} - # chown -R nginx:nginx /var/www/html/web/sites/${HOSTNAME} + mkdir /var/www/html/${DOCROOT}/sites/${HOSTNAME} + chmod -R 777 /var/www/html/${DOCROOT}/sites/${HOSTNAME} - cd /var/www/html/web || return; + cd /var/www/html/${DOCROOT} || return; mkdir -p ./sites/${HOSTNAME}/files - cp /var/www/html/web/sites/default/default.settings.php ./sites/${HOSTNAME}/settings.php + cp /var/www/html/${DOCROOT}/sites/default/default.settings.php ./sites/${HOSTNAME}/settings.php chmod 777 ./sites/${HOSTNAME}/settings.php # Site installation. + if [ "${DATABASE_BACKUP}" ]; then + # If we are provided a backup then install the minimal profile as we will override with db backup. + profile='minimal' + fi ../vendor/drush/drush/drush si -y $profile install_configure_form.enable_update_status_emails=NULL -y --account-name=${site_admin} --account-pass=${site_password} --account-mail=${site_mail} --site-mail=${site_mail} --site-name=${HOSTNAME} --sites-subdir=${HOSTNAME} --db-url=${DB_URL} DRUSH="/var/www/html/vendor/bin/drush -l ${HOSTNAME}" echo "Done." # Enabling PHPUnit XML. - PHPUNIT_XML="/var/www/html/web/core/phpunit-${DB_NAME}.xml" + PHPUNIT_XML="/var/www/html/${DOCROOT}/core/phpunit-${DB_NAME}.xml" echo "Configuring PHPUnit: ${PHPUNIT_XML}..." - cp /var/www/html/web/core/phpunit.xml.dist $PHPUNIT_XML + cp /var/www/html/${DOCROOT}/core/phpunit.xml.dist $PHPUNIT_XML DB_URL="mysql:\/\/${DB_USER}:${DB_PASS}@${DB_HOST}:3306\/${DB_NAME}" sed -i "s/