I think it depends on how you run the rysnc command:
rsync -az --force --delete --progress --exclude-from=rsync_exclude.txt -e "ssh -p22" ./public/ user@domain.com:/var/www/vhosts/yoursitefolder`
the important bit is:
./public/
- this gives the starting folder, in this case anything inside the public folder. You don’t need the absolute paths. The dot at the start means start from where the command is run.
Hint: I do it with a bash script (deploy.sh
) in my project root (remember to make it executable) and kick it off with NPM scripts.
#!/bin/bash
ERRORSTRING="Whoops! That didn't work. Please check the command you ran."
if [ $# -eq 0 ]
then
echo "$ERRORSTRING";
elif [[ "$1" == "live" ]]
then
if [[ -z $2 ]]
then
echo "Running live dry-run"
rsync --dry-run -az --force --delete --progress --exclude-from=rsync_exclude.txt -e "ssh -p22" ./public/ user@domain.com:/var/www/vhosts/yoursitefolder
elif [[ "$2" == "go" ]]
then
echo "Running live actual deploy"
rsync -az --force --delete --progress --exclude-from=rsync_exclude.txt -e "ssh -p22" ./public/ user@domain.com:/var/www/vhosts/yoursitefolder
else
echo "$ERRORSTRING";
fi
elif [[ "$1" == "staging" ]]
then
if [[ -z $2 ]]
then
echo "Running staging dry-run"
rsync --dry-run -az --force --delete --progress --exclude-from=rsync_exclude.txt -e "ssh -p22" ./public/ user@domain.com:/var/www/vhosts/yoursitefolder
elif [[ "$2" == "go" ]]
then
echo "Running staging actual deploy"
rsync -az --force --delete --progress --exclude-from=rsync_exclude.txt -e "ssh -p22" ./public/ user@domain.com:/var/www/vhosts/yoursitefolder
else
echo "$ERRORSTRING";
fi
elif [[ "$1" == "sync" ]]
then
if [[ -z $2 ]]
then
echo "Running sync dry-run"
rsync --dry-run -az --force --delete --progress --exclude-from=rsync_exclude.txt -e "ssh -p22" user@domain.com:/var/www/vhosts/yoursitefolder/content ./public/content
elif [[ "$2" == "go" ]]
then
echo "Running sync actual deploy"
rsync -az --force --delete --progress --exclude-from=rsync_exclude.txt -e "ssh -p22" user@domain.com:/var/www/vhosts/yoursitefolder/content ./public/content
else
echo "$ERRORSTRING";
fi
fi
NPM scripts in my package.json:
"deploy:live:sim": "./deploy live",
"deploy:live": "./deploy live go",
"deploy:staging:sim": "./deploy staging",
"deploy:staging": "./deploy staging go",
My exclude file looks like this:
.git
.gitignore
.gitkeep
.DS_Store
fonts.txt
To simulate the deploy without the deploy actually happening just do npm deploy:live:sim
. You get the idea
It wouldn’t take much to extend that script a little so it pulls down content from live.