我尝试使用 git hooks post-receive 进行简单的自动部署,我发现了这个 link .那个链接给了我想法并自己修改了它。 当 BRANCH 变量为“master”时,它运行良好。但是当我将其更改为其他分支时,比如说“phase2”,在运行 artisan 命令时它始终保留在“master”分支中。所以我的缓存路由来自master分支。
这是我的接收后 Hook 文件:
#!/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
当我尝试导航到我的目标目录时。它停留在第二阶段分支,但当我尝试“git status”时,有很多变化。这些改变来自master。
基本上,我想要的只是每次从本地“git Push”时自动进行部署,而无需登录到远程服务器来运行以下命令:
- cd 到/项目/路径
- git pull origin 第 2 阶段
- php artisan 缓存:清除
- php artisan 配置:缓存
- php artisan 路由:缓存
- php artisan 优化
我唯一认为可以做到的就是通过 GIT HOOKS
最佳答案
经过一番努力并在@VonC的帮助下
我完成我的钩子(Hook)很简单:
#!/bin/sh
unset $(git rev-parse --local-env-vars)
cd /usr/local/apache2/htdocs/project_uat
env -i git reset --hard
env -i git clean -f -d
env -i git pull
php artisan cache:clear
php artisan config:cache
php artisan route:cache
php artisan optimize
我还不知道缺点。
关于bash - 使用 git hooks + laravel artisan 命令创建简单的自动部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46901295/