Skip to content

Commit

Permalink
[CICD-761] Removing make remote relative method
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cseeman and mike-day committed Nov 26, 2024
1 parent 841bd05 commit 4f7574b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 73 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ ADD functions.sh /functions.sh
ADD entrypoint.sh /entrypoint.sh
ADD exclude.txt /exclude.txt
ENTRYPOINT ["/entrypoint.sh"]

6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ test-unit:
./tests/test_functions.sh

test-integration:
@echo 🧪 Executing Relative Remote Tests...
docker compose up test
# 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
5 changes: 0 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -150,5 +146,4 @@ setup_env
setup_ssh_dir
check_lint
check_cache
check_folder
sync_files
48 changes: 24 additions & 24 deletions exclude.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
28 changes: 0 additions & 28 deletions functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,3 @@ print_deployment_info() {
echo -e "\t$flag"
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
}



38 changes: 25 additions & 13 deletions tests/test-make-relative-remote/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand All @@ -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
Expand All @@ -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"
#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"

0 comments on commit 4f7574b

Please sign in to comment.