-
-
Save qtmg/2115deae61b6b7ed443c4b4a5c5006c6 to your computer and use it in GitHub Desktop.
Revisions
-
actionm created this gist
Feb 28, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ # Deployment with zero downtime # By default keeps 2 last deployments in KEEP_DEPLOYMENTS_DIR and current deployment # Project domain PROJECT_NAME=test.com # Project directory PROJECT_DIR=/home/forge/test.com # Deployments directory KEEP_DEPLOYMENTS_DIR=/home/forge/deploy KEEP_DEPLOYMENTS=2 DEPLOY_DIR_NAME=$(date +'%d%m%Y_%H%M%S') DEPLOY_DIR_PROJECT=${KEEP_DEPLOYMENTS_DIR}/${PROJECT_NAME} DEPLOY_DIR=${DEPLOY_DIR_PROJECT}/${DEPLOY_DIR_NAME} echo "Initialize deployment directory '"${DEPLOY_DIR}"'" [ -d ${DEPLOY_DIR} ] || mkdir -p ${DEPLOY_DIR} echo "Copying '"${PROJECT_DIR}/"' to '"${DEPLOY_DIR}"'" rsync -a $PROJECT_DIR/ $DEPLOY_DIR echo "Execute commands in deployment directory" cd ${DEPLOY_DIR} git pull origin master composer install --no-interaction --prefer-dist --optimize-autoloader if [ -f artisan ] then php artisan storage:link php artisan migrate --force php artisan queue:restart fi # Atomic, zero downtime echo "Update symlink '"${DEPLOY_DIR}"' to '"${PROJECT_DIR}.tmp"'" ln -s $DEPLOY_DIR ${PROJECT_DIR}.tmp # Remove current project directory if not symlink if [ ! -h $PROJECT_DIR ]; then rm -rf $PROJECT_DIR fi echo "Update symlink '"${DEPLOY_DIR}.tmp"' to '"${PROJECT_DIR}"'" mv -Tf $PROJECT_DIR.tmp $PROJECT_DIR echo "Clear old deployments in '"${DEPLOY_DIR_PROJECT}" keep last '"${KEEP_DEPLOYMENTS}"'" cd ${DEPLOY_DIR_PROJECT} rm -rf $(ls ${DEPLOY_DIR_PROJECT} -t | grep -v ${DEPLOY_DIR_NAME} | tail -n +$((KEEP_DEPLOYMENTS+1)))