Skip to content

Instantly share code, notes, and snippets.

@jonathanstanley
Last active July 23, 2019 20:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanstanley/836c4a86476349927a283c5aa8586207 to your computer and use it in GitHub Desktop.
Save jonathanstanley/836c4a86476349927a283c5aa8586207 to your computer and use it in GitHub Desktop.
Enable DELETE on fortrabbit Universal Apps
#!/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 FORTRABBITAPP@tunnel.us1.frbit.com:~
# 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/ FORTRABBITAPP@deploy.us1.frbit.com:~/ --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
@jonathanstanley
Copy link
Author

For simple cases, can do something like:

rsync --existing --ignore-existing --delete-after --recursive --exclude="/public/app/uploads/" ~/SOURCEDIR/ FORTRABBITAPP@deploy.us1.frbit.com:~/ --log-file="log.txt" -vv > /dev/null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment