Skip to content

Instantly share code, notes, and snippets.

@olivertappin
Created January 31, 2019 10:44
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/8a0e6abc79c6ac1e88a348d555756dee to your computer and use it in GitHub Desktop.
Save olivertappin/8a0e6abc79c6ac1e88a348d555756dee to your computer and use it in GitHub Desktop.
Atomic symlinked deployments
BASE="/var/www/project"
RELEASES="$BASE/releases"
RELEASE="$RELEASES/`date +%s`"
SHARED="$BASE/shared"
CACHE="$BASE/deploy-cache"
cp -a $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