Last active
July 23, 2019 20:12
-
-
Save jonathanstanley/836c4a86476349927a283c5aa8586207 to your computer and use it in GitHub Desktop.
Enable DELETE on fortrabbit Universal Apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This script has 2 lines of fast code to resolve an issue with fortrabbit "universal" apps for PHP sites, but could be used for others. | |
# For background, see https://help.fortrabbit.com/git-deployment#toc-git-deployment-vs-universal-apps | |
# On reading that, I expected "overwrite but not delete" strategy meant files outside git would not be deleted. | |
# However it literally means a committed delete will not be deleted. | |
# In other words, if you change a file to be empty, it's nullified on push. But if you delete, nothing happens on push; could leave insecure code on your server. | |
# fortrabbit does not place the .gitignore but rsync requires it, so push it up | |
scp ~/SOURCEDIR/.gitignore [email protected]:~ | |
# Use rsync only for delete purposes; see rsync man with properly escaped text https://www.samba.org/ftp/rsync/rsync.html | |
# --existing --ignore-existing to ensure we don't add or modify files | |
# --delete-after --recursive to have rsync delete files AFTER determining any file/folder exclusions | |
# --filter to exclude files according .gitignore (use ensures excluded files like vendor/uploads/etc aren't deleted) | |
# this filter pattern applies any found .gitignore files (not just the root .gitignore) | |
# .gitignore patterns may not match .rsync-filter precisely; add --dry-run to test | |
# --log-file="log.txt" -vv > /dev/null to record all changes to log file and suppress screen output | |
# thanks to https://stackoverflow.com/a/15373763 for discussion on using .gitignore in place of .rsync-filter | |
rsync --existing --ignore-existing --delete-after --recursive --filter=":- .gitignore" ~/SOURCEDIR/ [email protected]:~/ --log-file="log.txt" -vv > /dev/null | |
#optionally, strip out superflous lines so that only the deleted items are logged. | |
#sed -i '' '/\*deleting /!d' log.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For simple cases, can do something like:
rsync --existing --ignore-existing --delete-after --recursive --exclude="/public/app/uploads/" ~/SOURCEDIR/ [email protected]:~/ --log-file="log.txt" -vv > /dev/null