Created
October 6, 2016 07:13
-
-
Save thehelvetian/c26561566ffd50cd7aadc1c86ab06d8f to your computer and use it in GitHub Desktop.
Envoyer-style Git post-commit deployment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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