我正在尝试使用 CF CLI 推送 Laravel 应用程序。 我创建了一个新的 Laravel 应用程序(manifest.yml)并尝试部署它,但收到错误“无法打开输入文件:artisan”。
我所做的只是:
composer create-project --prefer-dist laravel/laravel app
manifest.yml
---
applications:
- name: laravel-test
memory: 512M
buildpacks:
- php_buildpack_v4_6_13
cf push
这是命令的结果:
Updating with these attributes...
---
applications:
- name: laravel-test
memory: 512M
+ default-route: true
buildpacks:
php_buildpack_v4_6_13
Manifest applied
Packaging files to upload...
Uploading files...
8.72 MiB / 8.72 MiB [==============================================================================================================================================================================] 100.00% 2s
Waiting for API to complete processing files...
Staging app and tracing logs...
Downloading php_buildpack_v4_6_13...
Downloaded php_buildpack_v4_6_13 (509.6M)
Cell 49e76781-b3ee-46da-b80b-b703787a9809 creating container for instance 217c9e0f-9274-4750-91d1-e6342a087455
Security group rules were updated
Cell 49e76781-b3ee-46da-b80b-b703787a9809 successfully created container for instance 217c9e0f-9274-4750-91d1-e6342a087455
Downloading app package...
Downloaded app package (24.5M)
-------> Buildpack version 4.6.13
Installing HTTPD
HTTPD 2.4.58
Downloaded [file:///tmp/buildpacks/bf04536342a2b09e39e9b4fc737b7c41/dependencies/https___buildpacks.cloudfoundry.org_dependencies_httpd_httpd_2.4.58_linux_x64_cflinuxfs4_bed46d20.tgz] to [/tmp]
Installing PHP
PHP 8.2.13
Downloaded [file:///tmp/buildpacks/bf04536342a2b09e39e9b4fc737b7c41/dependencies/https___buildpacks.cloudfoundry.org_dependencies_php_php_8.2.13_linux_x64_cflinuxfs4_300ddf44.tgz] to [/tmp]
Downloaded [file:///tmp/buildpacks/bf04536342a2b09e39e9b4fc737b7c41/dependencies/https___buildpacks.cloudfoundry.org_dependencies_php_php_8.2.13_linux_x64_cflinuxfs4_300ddf44.tgz] to [/tmp]
Downloaded [file:///tmp/buildpacks/bf04536342a2b09e39e9b4fc737b7c41/dependencies/https___buildpacks.cloudfoundry.org_dependencies_composer_composer_2.6.5_linux_noarch_any-stack_9a18e1a3.phar] to [/tmp]
Installing dependencies from lock file
Verifying lock file contents can be installed on current platform.
Package operations: 0 installs, 0 updates, 37 removals
- Removing theseer/tokenizer (1.2.2)
- Removing symfony/yaml (v6.4.0)
- Removing spatie/laravel-ignition (2.3.3)
- Removing spatie/ignition (1.11.3)
- Removing spatie/flare-client-php (1.4.3)
- Removing spatie/backtrace (1.5.3)
- Removing sebastian/version (4.0.1)
- Removing sebastian/type (4.0.0)
- Removing sebastian/recursion-context (5.0.0)
- Removing sebastian/object-reflector (3.0.0)
- Removing sebastian/object-enumerator (5.0.0)
- Removing sebastian/lines-of-code (2.0.2)
- Removing sebastian/global-state (6.0.1)
- Removing sebastian/exporter (5.1.1)
- Removing sebastian/environment (6.0.1)
- Removing sebastian/diff (5.1.0)
- Removing sebastian/complexity (3.2.0)
- Removing sebastian/comparator (5.0.1)
- Removing sebastian/code-unit-reverse-lookup (3.0.0)
- Removing sebastian/code-unit (2.0.0)
- Removing sebastian/cli-parser (2.0.0)
- Removing phpunit/phpunit (10.5.5)
- Removing phpunit/php-timer (6.0.0)
- Removing phpunit/php-text-template (3.0.1)
- Removing phpunit/php-invoker (4.0.0)
- Removing phpunit/php-file-iterator (4.1.0)
- Removing phpunit/php-code-coverage (10.1.11)
- Removing phar-io/version (3.2.1)
- Removing phar-io/manifest (2.0.3)
- Removing nunomaduro/collision (v7.10.0)
- Removing myclabs/deep-copy (1.11.1)
- Removing mockery/mockery (1.6.7)
- Removing laravel/sail (v1.26.3)
- Removing laravel/pint (v1.13.7)
- Removing hamcrest/hamcrest-php (v2.0.1)
- Removing filp/whoops (2.15.4)
- Removing fakerphp/faker (v1.23.0)
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Could not open input file: artisan
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
-----> Composer command failed
Traceback (most recent call last):
File "/tmp/buildpacks/bf04536342a2b09e39e9b4fc737b7c41/scripts/compile.py", line 55, in <module>
.from_build_pack('lib/additional_commands')
File "/tmp/buildpacks/bf04536342a2b09e39e9b4fc737b7c41/lib/build_pack_utils/builder.py", line 212, in extensions
process_extension(path, ctx, 'compile', process, args=[self])
File "/tmp/buildpacks/bf04536342a2b09e39e9b4fc737b7c41/lib/build_pack_utils/utils.py", line 69, in process_extension
success(getattr(extn, to_call)(*args))
File "/tmp/buildpacks/bf04536342a2b09e39e9b4fc737b7c41/extensions/composer/extension.py", line 444, in compile
return composer.compile(install)
File "/tmp/buildpacks/bf04536342a2b09e39e9b4fc737b7c41/lib/extension_helpers.py", line 154, in compile
self._compile(install)
File "/tmp/buildpacks/bf04536342a2b09e39e9b4fc737b7c41/extensions/composer/extension.py", line 196, in _compile
self.run()
File "/tmp/buildpacks/bf04536342a2b09e39e9b4fc737b7c41/extensions/composer/extension.py", line 343, in run
*self._ctx['COMPOSER_INSTALL_OPTIONS'])
File "/tmp/buildpacks/bf04536342a2b09e39e9b4fc737b7c41/extensions/composer/extension.py", line 390, in run
shell=True)
File "/tmp/buildpacks/bf04536342a2b09e39e9b4fc737b7c41/lib/build_pack_utils/runner.py", line 109, in stream_output
raise CalledProcessError(retcode, cmd)
build_pack_utils.runner.CalledProcessError: Command '<open file '<fdopen>', mode 'w' at 0x7fe8a9cb1ae0>' returned non-zero exit status 1
BuildpackCompileFailed - App staging failed in the buildpack compile phase
FAILED
有人知道如何解决这个问题吗?我已经搜索过,但在其他地方没有找到。
此外,我无法尝试更改构建包来运行某些测试,我所在的地方不允许使用自定义构建包。
看起来错误发生在
composer
安装阶段,当它尝试运行 post-autoload-dump
事件时,特别是 @php artisan package:discover --ansi
命令。错误消息表明无法打开输入文件:artisan
。
Laravel 应用程序期望 artisan 脚本存在于根目录中。但是,在 CF 环境中,应用程序暂存于不同的目录中,并且 artisan 脚本可能无法访问。
要解决此问题,您可以尝试以下步骤:
确保
artisan
脚本存在于 Laravel 应用程序的根目录中。当您使用 composer create-project
创建新的 Laravel 应用程序时,应自动生成 artisan
脚本。
更新您的
composer.json
文件以包含正确的路径。打开 composer.json
并查找“脚本”部分。它应该有这样的东西:
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
]
},
确保
@php artisan package:discover --ansi
命令正确指向 artisan
脚本。如果需要,请调整路径以匹配 Cloud Foundry 环境。
您可以选择更新您的
manifest.yml
文件以指定正确的启动命令。您可以显式定义运行 Laravel 应用程序的命令,而不是依赖默认命令。例如:
applications:
- name: laravel-test
memory: 512M
buildpacks:
- php_buildpack_v4_6_13
command: "php public/index.php" // assuming that your Laravel application's entry point is public/index.php
进行这些更改后,尝试重新部署,这应该足够了。
请原谅任何语法错误