gpt4 book ai didi

laravel - 自动部署到 azure linux webapp 后获取 .sh 文件的正确方法是什么?

转载 作者:行者123 更新时间:2023-12-03 03:44:01 25 4
gpt4 key购买 nike

我的 azure webapp (linux) 上有一个 laravel 应用程序。我正在尝试在部署后运行一些 php 命令。

我正在使用本地 Git 部署到我的 azure 的 web 应用程序。

并按照this guide ,我设置“POST_BUILD_SCRIPT_PATH”来运行名为“postbuild.sh”的脚本

(请注意,我使用的是 .sh 文件,因为我使用的是基于 Linux 的 Web 应用程序。)

问题是我的 postbuild.sh 位置位于“wwwroot”(我的 laravel 根应用程序所在的位置)。但我不断得到

Could not open input file: artisan

当我尝试运行任何 artisan 命令时的消息

php artisan cache:clear

查找后,我发现脚本是从tmp位置执行的。

我应该使用采购在正确的位置运行脚本,但它仍然不起作用。

所以我在“wwwroot”中创建了另一个 .sh 文件,并命名为“clearcache.sh”,并尝试在“postbuild.sh”中获取它,但仍然无法正常工作。

我的 postbuild.sh 是

echo "Post Build .sh"
echo "Script executed from: ${PWD}"
BASEDIR=$(dirname $0)
echo "Script location: ${BASEDIR}"
echo "===================="
source ./home/site/wwwroot/refresh.sh

我的refresh.sh是

echo "Refresh script"
echo "Script executed from: ${PWD}"
BASEDIR=$(dirname $0)
echo "Script location: ${BASEDIR}"
php artisan cache:clear

我在推送到azure repo时遇到的错误是:

remote: Detecting platforms...
remote: Detected following platforms:
remote: php: 7.4.24
remote:
remote: Using intermediate directory '/tmp/8d9a71074a40f5b'.
remote:
remote: Copying files to the intermediate directory...
remote: Done in 0 sec(s).
remote: /home/site/wwwroot/postbuild.sh: line 6: ./home/site/wwwroot/refresh.sh
remote:
remote: : No such file or directory
remote: Source directory : /tmp/8d9a71074a40f5b
remote: Destination directory: /home/site/wwwroot
remote:
remote: Executing pre-build command...
remote: Pre Build
remote: Finished executing pre-build command.
remote: PHP executable: /tmp/oryx/platforms/php/7.4.24/bin/php
remote: No 'composer.json' file found; not running 'composer install'.
remote:
remote: Executing post-build command...
remote: Post Build .sh
remote: Script executed from: /tmp/8d9a71074a40f5b
remote: Script location: /home/site/wwwroot
remote:
remote: ====================

请注意以下事项:

  • Laravel 根目录不包含“index.php”文件,但我添加了一个无论如何,虚拟“index.php”文件,因为 Azure 需要它验证构建。
  • 我从本地 git 中删除了“composer.json”文件,因为我没有需要运行composer安装。我只是想复制应用程序和路线文件夹从 repo 文件夹到“wwwroot”

最佳答案

你实际上从未通过执行例如以下操作来切换到BASEDIR: cd $BASEDIR 所以你的工作目录实际上永远不会改变,所以这是解决这个问题的一种方法:

echo "Refresh script"
echo "Script executed from: ${PWD}"
BASEDIR=$(dirname $0)
echo "Script location: ${BASEDIR}"
$(
cd $BASEDIR
php artisan cache:clear
)

请注意,多行 $(...) 用于执行内容,但完成后保留原始工作目录。

或者你可以这样做:

echo "Refresh script"
echo "Script executed from: ${PWD}"
BASEDIR=$(dirname $0)
echo "Script location: ${BASEDIR}"
php $BASEDIR/artisan cache:clear

关于laravel - 自动部署到 azure linux webapp 后获取 .sh 文件的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69959700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com