Skip to content

Instantly share code, notes, and snippets.

@lennartvdd
Last active February 27, 2021 19:35
Show Gist options
  • Save lennartvdd/e116cefd551bac9e5db2 to your computer and use it in GitHub Desktop.
Save lennartvdd/e116cefd551bac9e5db2 to your computer and use it in GitHub Desktop.
GIT Hook: post-receive - Automatically deploy a Yii2 project using GIT
#!/bin/bash
# == Settings ==
GIT_DIR=/var/repo/project.git
WORK_TREE=/var/www/domain.com
BRANCH=master
YII_ENVIRONMENT=Production
# == Script ==
echo "Checking out branch $BRANCH"
git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -q -f $BRANCH
cd $WORK_TREE
# Composer install
if [ -e ./composer.lock ]; then
echo "[Composer] composer.lock file found. Running composer install"
composer install
fi
# Yii2
if [ -e ./yii.bat ]; then
# init
echo "[Yii2] Detected Yii2 projected."
if [ ! -e ./yii ] && [ -e ./init ]; then
echo "[Yii2] Initializing project."
chmod +x ./init
./init --env=$YII_ENVIRONMENT
fi
# migrate up
echo "[Yii2] Running migrations"
./yii migrate/up --interactive=0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment