Skip to content

Instantly share code, notes, and snippets.

@adrianorsouza
Last active July 29, 2020 01:29
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 adrianorsouza/5bb46947bf22f0a412ecb460be978a88 to your computer and use it in GitHub Desktop.
Save adrianorsouza/5bb46947bf22f0a412ecb460be978a88 to your computer and use it in GitHub Desktop.
Laravel production script that run after git post-update hooks
#!/bin/sh
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, rename this file to "post-update".
echo "--initializing @@SITE_NAME@@ hook--"
git --git-dir @@GIT_DIR@@/.git --work-tree @@GIT_DIR@@ pull @@GIT_REMOTE_NAME@@ @@GIT_BRANCH_NAME@@
if [ -f /var/www/@@SITE_NAME@@/scripts/post-update-hook.sh ]; then
echo "--executing bash command---"
bash /var/www/@@SITE_NAME@@/scripts/post-update-hook.sh
echo "--executing bash command done---"
fi
echo "--update @@SITE_NAME@@ completed--"
#!/usr/bin/env bash
#
# Post-Update Hook script executed after git push origin.
#
# @autor: Adriano Rosa <https://adrianorosa.com>
#
# @updated: 2020-07-28 22:20
#
# @usage: ./scripts/command Configure git post-update to run every time the repository gets updated.
#
# @source: https://gist.github.com/adrianorsouza/5bb46947bf22f0a412ecb460be978a88
#
# Laravel has a problem when using artisan optimize command
# First we need to clear all caches then run artisan optimize command
# prior to avoid Page Not Found Error causing the application reset the
# environment variables.
SITE_PATH=$(cd -P -- "$(dirname -- "$1")" && pwd -P)
echo "Executing POST-UPDATE script:"
echo $SITE_PATH/command
COMPOSER=`which composer`
# Make sure composer exists and run on every release
# this ensure that missing packages runs and error due
# the push to the production server
if [[ $COMPOSER ]]; then
composer install --working-dir=$SITE_PATH --optimize-autoloader --no-interaction --no-dev
fi
# NOTE: The optimize:clear is the same as:
# artisan view:clear
# artisan cache:clear
# artisan route:clear
# artisan config:clear
# artisan clear-compiled
php $SITE_PATH/artisan optimize:clear
# NOTE: The optimize is the same as:
# artisan config:clear
# artisan cache:clear
php $SITE_PATH/artisan optimize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment