Skip to content

Instantly share code, notes, and snippets.

@olivertappin
Created November 15, 2017 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olivertappin/7c48520f9796b0f207df32bd7a58e212 to your computer and use it in GitHub Desktop.
Save olivertappin/7c48520f9796b0f207df32bd7a58e212 to your computer and use it in GitHub Desktop.
Symlink deployments to prevent any downtime whilst files are uploaded and an application is being used
BASE="/var/www/project"; RELEASES="$BASE/releases"; RELEASE="$RELEASES/1234567890"; SHARED="$BASE/shared"; CACHE="$BASE/deploy-cache"
if [[ `uname` == 'Darwin' ]]; then COPY="cp -a"; else COPY="cp -a"; fi
$COPY $CACHE $RELEASE
cd $RELEASE
####### [Pre-launch commands] #######
composer install -va
####### [/Pre-launch commands] #######
if [ $? -ne 0 ]; then echo "Pre-launch commands failed."; exit 1; fi
rm -f $RELEASES/current; ln -s $RELEASE $RELEASES/current; mv -f $RELEASES/current $BASE/
cd $RELEASE
####### [Post-launch commands] #######
####### [/Post-launch commands] #######
if [ $? -ne 0 ]; then echo "Post-launch commands failed, but the current application symlink was updated."; exit 1; fi
echo "Cleaning up old releases"
\ls -1d $RELEASES/* | \sort -rg | \tail -n +11 | \xargs /bin/rm -rf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment