【发布时间】:2018-04-04 16:56:52
【问题描述】:
我正在尝试使用 git hooks post-receive 进行简单的自动部署,我发现了这个link。那个链接给了我想法并自己修改了它。 当 BRANCH 变量为“主”时,它运行良好。但是当我将它更改为其他分支时,比如说“phase2”,当运行工匠命令时,它总是停留在“master”分支中。所以我的缓存路由来自 master 分支。
这是我的接收后挂钩文件:
#!/bin/sh
TARGET="/usr/local/apache2/htdocs/project_uat"
GIT_DIR="/home/user0001/www/project_name/.git"
BRANCH="phase2" # I want this changable to phase3,phase4 or what ever branch
while read oldrev newrev ref
do
# only checking out the master (or whatever branch you would like to deploy)
if [[ $ref = "refs/heads/${BRANCH}" ]];
then
echo "Ref $ref received. Deploying ${BRANCH} branch to UAT..."
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f
else
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
done
cd /usr/local/apache2/htdocs/project_uat
php artisan cache:clear
php artisan config:cache
php artisan route:cache
php artisan optimize
当我尝试导航到我的目标目录时。它停留在 phase2 分支,但是当我尝试“git status”时有很多变化。这些变化来自主人。
基本上,我想要的只是每次我从本地“git push”时自动化部署,而无需登录远程服务器只是为了运行以下命令:
- cd 到/项目/路径
- git pull origin phase2
- php artisan 缓存:清除
- php 工匠配置:缓存
- php artisan route:cache
- php 工匠优化
而我唯一能做到的就是通过 GIT HOOKS
【问题讨论】:
标签: bash laravel githooks laravel-artisan