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

[CICD-761] Generate dynamic excludes for rsync (part deux) #42

Merged
merged 10 commits into from
Jan 8, 2025

Conversation

mike-day
Copy link
Contributor

@mike-day mike-day commented Dec 18, 2024

JIRA Ticket

CICD-761

Bug description

Customer reports that mu-plugins are being deleted when deploying with the GitHub Action. The plugins that are mentioned as being deleted are already part of our global excludes list in wpengine/site-deploy.

Reported in: wpengine/github-action-wpe-site-deploy#91

Background

This PR is another implementation idea after having worked through several other options for the ticket.

In #37, we tried forcing files to adhere to a specific structure expected by the remote target (making a relative remote), but felt the approach ended up being a bit risky with re-writing directory structure on each sync.

In #39, we tried removing relative path prepending in the exclude.txt file, but the approach was deemed a risk for affecting users that deploy to the root directory of a site (the paths in exclude.txt were treated like globs, meaning custom files could be unintentionally excluded).

In #40, we tried dynamically generating the paths used for exclusion, but the solution still relies on relative pathing. This can lead to certain paths (like cache/*) being excluded unintentionally.

What Are We Doing Here

Like #40, this approach creates an exclusion lists for rsync on the fly, also relying on the REMOTE_PATH. The main differences are with the testing approach, which was refined in this PR.

Note: Initially, we tried creating separate exclusion rules (one for the source, and one for the remote). Some commits in this PR will show a path taken with that approach before it was refined in the last few commits.

Resolves a warning about unused variables in the common file.
Also moves common.sh to new utils dir.
Outputs the list to stdout, which is called with process substitution in the initial rsync command.

Also disables debug mode for the block calling the generate function. This prevents unwanted debug output
(specific to the excludes list generation) from being shown.
@mike-day mike-day requested a review from a team as a code owner December 18, 2024 19:18
Copy link

changeset-bot bot commented Dec 18, 2024

🦋 Changeset detected

Latest commit: 63be915

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@wpengine/site-deploy Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mike-day mike-day force-pushed the CICD-761-try-dynamic-src-and-rem-excludes branch from 9643529 to bdd52b4 Compare December 18, 2024 19:22
utils/print_mount_paths.sh Outdated Show resolved Hide resolved
Simplifies the logic for determining what files were copied to workdir by globbing for certain dirs instead of parsing proc/self/mountinfo.

This is also better for other mounted dir structures (such as when a GHA runner mounts the image); we are simply checking what is in the current dir instead of inferring the structure based off mounted source path.
The goal of the excludes list is to prevent users from accidentally
breaking their site by overwriting or deleting important files on
the server.

While there are many files that could be deemed important, we explicily
want to exclude a handful of files from the site root, some from wp-content,
and some from wp-content/mu-plugins.

In order to determine if a deploy is at risk of overwriting or deleting an
important file on the server, we just need to look at the REMOTE_PATH.

If REMOTE_PATH is unset, we know the destination is the site root.
If REMOTE_PATH ends in wp-content, we know the destination is wp-content.
If REMOTE_PATH ends in wp-content/mu-plugins, we know the destination is
 wp-content/mu-plugins.

All three of these cases carry the risk of overwritting or deleting
important files. In order to prevent this, we need to make the exclude
rules relative to the REMOTE_PATH.

SRC_PATH no longer matters because rsync assumes it to be identical to
REMOTE_PATH for the sake of determining transfer/deletion deltas.
Tests how different REMOTE_PATHS affect the generated exclude
rule output.
@apmatthews apmatthews force-pushed the CICD-761-try-dynamic-src-and-rem-excludes branch from 0f40e85 to 63be915 Compare January 7, 2025 23:18
Copy link
Member

@apmatthews apmatthews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woo, dynamic excludes! 🚀

@mike-day mike-day changed the title [CICD-761] Generate unique dynamic excludes for rsync source and remote [CICD-761] Generate dynamic excludes for rsync (part deux) Jan 8, 2025
@mike-day
Copy link
Contributor Author

mike-day commented Jan 8, 2025

Woo, dynamic excludes! 🚀

Thanks for the help with bringing this one home, @apmatthews!

@mike-day mike-day merged commit 54ec5ce into main Jan 8, 2025
4 checks passed
@mike-day mike-day deleted the CICD-761-try-dynamic-src-and-rem-excludes branch January 8, 2025 16:53
@cseeman
Copy link

cseeman commented Jan 9, 2025

Congrats on getting this all done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants