Skip to content

Instantly share code, notes, and snippets.

@jeroenherczeg
Last active January 27, 2017 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeroenherczeg/3069269fe56b9996c309a2c0b4b974f7 to your computer and use it in GitHub Desktop.
Save jeroenherczeg/3069269fe56b9996c309a2c0b4b974f7 to your computer and use it in GitHub Desktop.
Zero Deployment script for my Laravel project
#!/bin/sh
# Author : Jeroen Herczeg <jeroen@herczeg.be> HASSELT, LIMBURG, BELGIUM, EUROPE, EARTH
#
# Hello. My name is Jeroen Herczeg and I can help you or your team with my broad knowledge
# of frontend & backend web technologies and tools. I'm an eager learner and easily adapt to
# new environments. Work remotely? I like that. Need me on location? I'm sure we'll figure something out!
#
# http://herczeg.be
# Stop the script if there is an error
set -e
BRANCH=${1:-master}
TIMESTAMP=$(date +"%Y%m%d%H%M%S")
HOME_DIR="/var/www/herczeg.be"
PUBLIC_DIR="$HOME_DIR/public"
STORAGE_DIR="$HOME_DIR/storage"
RELEASES_DIR="$HOME_DIR/releases"
RELEASE_DIR=$RELEASES_DIR/$TIMESTAMP
# Clone the release in the releases directory
cd $RELEASES_DIR
git clone git@bitbucket.org:socialseeder/socialseeder-admin.git --branch=$BRANCH --depth=1 $TIMESTAMP
# Remove the storage directory from the release and link the main storage directory
rm -rf $RELEASE_DIR/storage
ln -s $STORAGE_DIR $RELEASE_DIR/storage
# Copy the new images from the release to the main images directory
# Remove the image directory from the release and link the main images directory
cp -r $RELEASE_DIR/public/images/* $PUBLIC_DIR/images
rm -rf $RELEASE_DIR/public/images
ln -s $PUBLIC_DIR/images $RELEASE_DIR/public/images
# Link the main env file to the current release
ln -s $HOME_DIR/.env $RELEASE_DIR/.env
# Install the composer packages
cd $RELEASE_DIR
composer install --no-interaction
# Migrate the database
php artisan migrate --force --no-interaction
# Install the NPM packages
npm install
# Run Gulp task runner
gulp --production
# Change the ownership and permissions of the files for NGINX
chgrp -R nginx $RELEASE_DIR
chmod -R ug+rwx $RELEASE_DIR
# Activate the release
rm $HOME_DIR/current
ln -s $RELEASE_DIR $HOME_DIR/current
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment