From d7d5b1a7e6cab4c46951a100fcf106f987b6fb15 Mon Sep 17 00:00:00 2001 From: Christine Seeman Date: Tue, 26 Nov 2024 14:21:21 -0600 Subject: [PATCH] [CICD-761] Removing make remote relative method With the help of Michael, it was determined that the easiest way to make sure that the excludes files is fully used for the rsynch command, is to make sure to use the file name, but not the full file path. This will make sure the files are excluded, no matter which folder location you attempt to deploy to. So default base of the wordpress install will work, or if you use within wp-content or other folder locations. Removing out the testing calls for now too, until we can get a better mocking framework in place to make sure synch_files can be full tested. Co-authored-By: Michael Day --- Dockerfile | 1 - Makefile | 6 ++-- entrypoint.sh | 5 --- exclude.txt | 48 ++++++++++++------------- functions.sh | 25 ------------- tests/test-make-relative-remote/test.sh | 38 +++++++++++++------- 6 files changed, 53 insertions(+), 70 deletions(-) diff --git a/Dockerfile b/Dockerfile index c12b5f4..d2939ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,4 +11,3 @@ ADD functions.sh /functions.sh ADD entrypoint.sh /entrypoint.sh ADD exclude.txt /exclude.txt ENTRYPOINT ["/entrypoint.sh"] - diff --git a/Makefile b/Makefile index 0ba5101..2f785df 100644 --- a/Makefile +++ b/Makefile @@ -26,5 +26,7 @@ test-unit: ./tests/test_functions.sh test-integration: - @echo ๐Ÿงช Executing Relative Remote Tests... - docker compose up test \ No newline at end of file + # TODO: Currently commenting out the integration tests as they are not ready yet + # this was setup for the relative remote work, and is not currently working with + # testing sync_files function. + # docker compose up test diff --git a/entrypoint.sh b/entrypoint.sh index c479367..90edf79 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -106,10 +106,6 @@ check_cache() { fi } -check_folder() { - make_relative_remote "$SRC_PATH" "$REMOTE_PATH" -} - sync_files() { #create multiplex connection ssh -nNf -v -i "${WPE_SSHG_KEY_PRIVATE_PATH}" -o StrictHostKeyChecking=no -o ControlMaster=yes -o ControlPath="$SSH_PATH/ctl/%C" "$WPE_FULL_HOST" @@ -150,5 +146,4 @@ setup_env setup_ssh_dir check_lint check_cache -check_folder sync_files diff --git a/exclude.txt b/exclude.txt index 9d376d4..ddc9548 100644 --- a/exclude.txt +++ b/exclude.txt @@ -18,17 +18,17 @@ Thumbs.db # NOTE: # These files are excluded from the deploy so as to prevent unwanted errors from occurring, # such as accidentally deploying a local version of wp-config.php or accidentally deleting -# wp-content/uploads/ if a --delete flag is passed while deploying root. Most paths here +# uploads/ if a --delete flag is passed while deploying root. Most paths here # are ingnored in the WPE sample .gitignore per best practice. wp-config.php -wp-content/uploads/ -wp-content/blogs.dir/ -wp-content/upgrade/* -wp-content/backup-db/* -wp-content/advanced-cache.php -wp-content/wp-cache-config.php -wp-content/cache/* -wp-content/cache/supercache/* +uploads/ +blogs.dir/ +upgrade/* +backup-db/* +advanced-cache.php +wp-cache-config.php +cache/* +cache/supercache/* # WP Engine specific files # NOTE: @@ -44,20 +44,20 @@ wp-content/cache/supercache/* .wpe-devkit/ .wpengine-conf/ _wpeprivate -wp-content/object-cache.php -wp-content/mu-plugins/mu-plugin.php -wp-content/mu-plugins/slt-force-strong-passwords.php -wp-content/mu-plugins/wpengine-security-auditor.php -wp-content/mu-plugins/stop-long-comments.php -wp-content/mu-plugins/force-strong-passwords* -wp-content/mu-plugins/wpengine-common* -wp-content/mu-plugins/wpe-wp-sign-on-plugin* -wp-content/mu-plugins/wpe-elasticpress-autosuggest-logger* -wp-content/mu-plugins/wpe-cache-plugin* -wp-content/mu-plugins/wp-cache-memcached* -wp-content/drop-ins/ -wp-content/drop-ins/wp-cache-memcached* -wp-content/mysql.sql +object-cache.php +mu-plugin.php +slt-force-strong-passwords.php +wpengine-security-auditor.php +stop-long-comments.php +force-strong-passwords* +wpengine-common* +wpe-wp-sign-on-plugin* +wpe-elasticpress-autosuggest-logger* +wpe-cache-plugin* +wp-cache-memcached* +drop-ins/ +drop-ins/wp-cache-memcached* +mysql.sql # Local specific -wp-content/mu-plugins/local-by-flywheel-live-link-helper.php +local-by-flywheel-live-link-helper.php diff --git a/functions.sh b/functions.sh index 51e9246..58b9b2d 100644 --- a/functions.sh +++ b/functions.sh @@ -26,30 +26,5 @@ print_deployment_info() { done } -# Function to check REMOTE_PATH and move contents of SRC_PATH -make_relative_remote() { - if [[ -z "$REMOTE_PATH" && "$SRC_PATH" == "." ]]; then - echo "Default usage, no moving relative paths needed ๐Ÿ‘‹" - return - fi - - if [[ "$SRC_PATH" == "$REMOTE_PATH" ]]; then - echo "SRC_PATH and REMOTE_PATH are the same, no moving relative paths needed ๐Ÿ‘‹" - return - fi - - if [ "$SRC_PATH" == "." ]; then - # Use a temporary directory to avoid moving REMOTE_PATH into itself - TMP_DIR=$(mktemp -d) - mv "$SRC_PATH"/* "$TMP_DIR" - mkdir -p "$REMOTE_PATH" - mv "$TMP_DIR"/* "$REMOTE_PATH" - rmdir "$TMP_DIR" - else - mkdir -p "$REMOTE_PATH" - mv "$SRC_PATH"/* "$REMOTE_PATH" - fi -} - diff --git a/tests/test-make-relative-remote/test.sh b/tests/test-make-relative-remote/test.sh index cfa49c6..7889511 100755 --- a/tests/test-make-relative-remote/test.sh +++ b/tests/test-make-relative-remote/test.sh @@ -5,6 +5,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${SCRIPT_DIR}/../common.sh" source "${SCRIPT_DIR}/../../functions.sh" +source "${SCRIPT_DIR}/../../entrypoint.sh" setup() { rm -rf /workspace/* @@ -13,21 +14,32 @@ setup() { # Works like GitHub action, checking out the workspace directory cp -r "${test_data_dir}"* /workspace/ fi + ssh-keygen -t rsa -b 2048 -f /workspace/mock_ssh_key -N "" + chmod 600 /workspace/mock_ssh_key + cd /workspace } -# Test resulting directory structure from calling make_relative_remote -# Expected output is the directory structure after moving the contents of SRC_PATH to REMOTE_PATH -# e.g. make_relative_remote "/home/user/website" "/var/www/html" should return "/var/www/html/website" -# 1st argument: SRC_PATH, 2nd argument: REMOTE_PATH -# How can I make sure the make test is not caching the docker and creating it fresh -test_make_relative_remote() { +# Test resulting directory structure from calling sync_files +test_sync_files() { setup "$1" SRC_PATH=$2 REMOTE_PATH=$3 + WPE_SSHG_KEY_PRIVATE=$(cat /workspace/mock_ssh_key) + echo -e "${GREEN}REMOTE_PATH='$REMOTE_PATH' SRC_PATH='$SRC_PATH'${NC}" - make_relative_remote + + # Assign flag values to FLAGS_ARRAY + FLAGS_ARRAY=("-azvr" "--dry-run" "--inplace" "--exclude='.*'") + + # Print the flags for debugging + echo "Using the following rsync flags:" + for flag in "${FLAGS_ARRAY[@]}"; do + echo "$flag" + done + + sync_files # Only compare the expected directory structure if REMOTE_PATH is not empty and REMOTE_PATH is not equal to SRC_PATH if [[ -n "$REMOTE_PATH" && "$REMOTE_PATH" != "$SRC_PATH" ]]; then @@ -54,9 +66,9 @@ test_make_relative_remote() { } # Test cases, make remote directory relative to to the tests directory -test_make_relative_remote "1" "." "" -test_make_relative_remote "2" "./wp-content" "./wp-content" -test_make_relative_remote "3" "." "wp-content/" -test_make_relative_remote "4" "." "wp-content/themes/beautiful-pro" -test_make_relative_remote "5" "my-awesome-plugins" "wp-content/plugins" -test_make_relative_remote "6" "my-awesome-plugins/blues-brothers" "wp-content/plugins" \ No newline at end of file +#test_sync_files "1" "." "" +#test_sync_files "2" "./wp-content" "./wp-content" +#test_sync_files "3" "." "wp-content/" +#test_sync_files "4" "." "wp-content/themes/beautiful-pro" +#test_sync_files "5" "my-awesome-plugins" "wp-content/plugins" +#test_sync_files "6" "my-awesome-plugins/blues-brothers" "wp-content/plugins"