Skip to content

Instantly share code, notes, and snippets.

@thehelvetian
Created October 6, 2016 07:13
Show Gist options
  • Select an option

  • Save thehelvetian/c26561566ffd50cd7aadc1c86ab06d8f to your computer and use it in GitHub Desktop.

Select an option

Save thehelvetian/c26561566ffd50cd7aadc1c86ab06d8f to your computer and use it in GitHub Desktop.
Envoyer-style Git post-commit deployment
#!/usr/bin/env bash
# Set up the PATH var
PATH="/home/[user]/bin":$PATH
export PATH
# Git directories
GIT_WORK_DIR="/home/[user]/public_html"
GIT_REPO_DIR="/home/[user]/repos/[laravel_app].git"
# Revision
REVISION="$(git rev-parse HEAD)"
# Now
DATENOW="$(date +%Y%m%d%H%M%S)"
# Make sure the directories exist
echo -e "Deploying Revision: ${REVISION} ...\n"
mkdir -p ${GIT_WORK_DIR}/releases
mkdir -p ${GIT_WORK_DIR}/releases/v${DATENOW}
# CD into the new release directory
cd ${GIT_WORK_DIR}/releases/v${DATENOW}
# Re-link .env
echo -e "Re-linking .env ...\n"
ln -s ${GIT_WORK_DIR}/.env .env
# Check the repo out
echo -e "Checking out ...\n"
git --work-tree=${GIT_WORK_DIR}/releases/v${DATENOW} --git-dir=${GIT_REPO_DIR} checkout -f
# Run composer
echo -e "Running composer update ...\n"
composer update
# Re-link the storage folder
echo -e "Re-linking storage/ ...\n"
rm -rf storage/
ln -s ${GIT_WORK_DIR}/storage storage
# Optimize
echo -e "Optimizing ...\n"
php artisan config:cache
php artisan route:cache
# Publish it
echo -e "Publishing new version (v${DATENOW}) ...\n"
cd ${GIT_WORK_DIR}
rm -rf current
ln -s ${GIT_WORK_DIR}/releases/v${DATENOW} current
# @todo Add old releases cleanup routine
# Done
echo -e "Done!\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment