Skip to content

Instantly share code, notes, and snippets.

@cedricziel
Created January 7, 2016 20:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cedricziel/6418424dc561b9b1184a to your computer and use it in GitHub Desktop.
Save cedricziel/6418424dc561b9b1184a to your computer and use it in GitHub Desktop.
Uberspace Laravel 5.2 Zero downtime deployments as a post-receive hook.
#!/bin/bash
source ~/.bash_profile
VERSION=$(date +%Y%m%d%H%M%S)
BASE_DIRECTORY=/var/www/virtual/foxyzor/html/application
SOURCE_ROOT=$BASE_DIRECTORY/versions/$VERSION
SHARED_FOLDER=$BASE_DIRECTORY/shared
STORAGE_FOLDER=$BASE_DIRECTORY/shared/storage
CURRENT_LINK=$BASE_DIRECTORY/current
PHP=/package/host/localhost/php-7.0/bin/php
NODE=/package/host/localhost/nodejs-5/bin/node
NPM=/package/host/localhost/nodejs-5/bin/npm
echo "---> Creating Deployment directory for Version $VERSION"
mkdir -p $SOURCE_ROOT
mkdir -p $STORAGE_FOLDER
mkdir -p $STORAGE_FOLDER/app
mkdir -p $STORAGE_FOLDER/framework/cache
mkdir -p $STORAGE_FOLDER/framework/views
mkdir -p $STORAGE_FOLDER/framework/sessions
echo "---> Checking out source"
GIT_WORK_TREE=$SOURCE_ROOT git checkout -f
cd $SOURCE_ROOT
echo "---> Downloading composer"
curl -sS https://getcomposer.org/installer | php
# Check if a composer.json file is present
if [ -f composer.json ]; then
# Install or update packages specified in the lock file
$PHP composer.phar install
fi
mkdir -p $STORAGE_FOLDER
rm -Rf storage
ln -s $STORAGE_FOLDER storage
ln -s $SHARED_FOLDER/.env .env
cp $SHARED_FOLDER/htaccess public/.htaccess
# install packages, this also regenerates the autoloader
$PHP composer.phar install --no-scripts --no-dev --no-interaction --prefer-dist --no-ansi
echo "---> Installing node dependencies"
npm install
echo "---> Run gulp build script"
./node_modules/.bin/gulp
# display the environment
$PHP artisan env
# run any outstanding migrations
$PHP artisan migrate --force
# optimize autoloader and compile common classes
$PHP artisan optimize --force
rm $CURRENT_LINK
ln -s $SOURCE_ROOT $CURRENT_LINK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment