php 在composer命令后Laravel部署到App引擎中断

dkqlctbz  于 2023-04-10  发布在  PHP
关注(0)|答案(2)|浏览(108)

我正在使用Laravel 7编程PHP API。我的开发过程是这样的:
本地(宅基地@Virtualbox:Ubuntu)=〉Github =〉Google Cloud build(由主提交触发的部署)=〉Google App Engine〈〉Google Cloud SQL
现在我用这种方式部署我的应用程序没有问题,但昨天我尝试添加一个composer包(mpociot/laravel-apidoc-generator)。在一些本地测试后,一切都很好,我提交了我的master分支,我的GC Build触发器试图在我的应用程序引擎示例上部署应用程序。
进程终止了,出现了一个我从未见过的错误。然后我恢复了最近的一次提交,回到了我从未运行composer命令的状态,并再次提交了我的master分支:部署照常成功。
因此,由于composer命令发生了一些事情,我进一步调查。
以下是我在GC Build失败部署中获得的日志:

FETCHSOURCE
Fetching storage object: gs://701891080190.cloudbuild-source.googleusercontent.com/7541db97159423ca9ec0996eb740a404aef3c4b9-ec3f59e5-8eb5-46f9-98ab-6848be6dd6f8.tar.gz#1589712757789375
Copying gs://701891080190.cloudbuild-source.googleusercontent.com/7541db97159423ca9ec0996eb740a404aef3c4b9-ec3f59e5-8eb5-46f9-98ab-6848be6dd6f8.tar.gz#1589712757789375...
/ [0 files][    0.0 B/  9.4 MiB]                                                
/ [1 files][  9.4 MiB/  9.4 MiB]                                                
Operation completed over 1 objects/9.4 MiB.                                      
BUILD
Already have image (with digest): gcr.io/cloud-builders/gcloud
Services to deploy:

descriptor:      [/workspace/app.yaml]
source:          [/workspace]
target project:  [#####]
target service:  [#####]
target version:  [20200517t105250]
target url:      [https://#####.ew.r.appspot.com]

Do you want to continue (Y/n)?  
Beginning deployment of service [heavnt-test]...
#============================================================#
#= Uploading 2 files to Google Cloud Storage                =#
#============================================================#
File upload done.
Updating service [heavnt-test]...
.............................................................................................................................................................................................................failed.
ERROR: (gcloud.app.deploy) Error Response: [9] Cloud build 0dd458db-cd18-463a-b0de-034668d9802a status: FAILURE.
Build error details: {"error":{"errorType":"BuildError","canonicalCode":"INVALID_ARGUMENT","errorId":"39857F2F","errorMessage":"INFO     FTL version php-v0.17.0\nINFO     Beginning FTL build for php\nINFO     FTL arg passed: exposed_ports None\nINFO     FTL arg passed: cache_repository eu.gcr.io/hotpot-63d32/app-engine-tmp/build-cache/ttl-7d\nINFO     FTL arg passed: tar_base_image_path None\nINFO     FTL arg passed: export_cache_stats False\nINFO     FTL arg passed: builder_output_path \"\"\nINFO     FTL arg passed: name eu.gcr.io/hotpot-63d32/app-engine-tmp/app/ttl-2h:a30cd452-e54a-46f4-a041-9b975258909a\nINFO     FTL arg passed: ttl 168\nINFO     FTL arg passed: global_cache False\nINFO     FTL arg passed: cache True\nINFO     FTL arg passed: upload True\nINFO     FTL arg passed: sh_c_prefix False\nINFO     FTL arg passed: fail_on_error True\nINFO     FTL arg passed: base eu.gcr.io/gae-runtimes/php72:php72_20200412_7_2_29_RC00\nINFO     FTL arg passed: output_path None\nINFO     FTL arg passed: cache_key_version v0.17.0\nINFO     FTL arg passed: cache_salt \nINFO     FTL arg passed: directory /workspace\nINFO     FTL arg passed: entrypoint None\nINFO     FTL arg passed: additional_directory /.googleconfig\nINFO     FTL arg passed: destination_path /srv\nINFO     FTL arg passed: verbosity NOTSET\nINFO     starting: full build\nINFO     starting: builder initialization\nINFO     Loading Docker credentials for repository 'eu.gcr.io/gae-runtimes/php72:php72_20200412_7_2_29_RC00'\nINFO     Loading Docker credentials for repository 'eu.gcr.io/hotpot-63d32/app-engine-tmp/app/ttl-2h:a30cd452-e54a-46f4-a041-9b975258909a'\nINFO     builder initialization took 0 seconds\nINFO     starting: build process for FTL image\nINFO     starting: rm_vendor_dir\nINFO     rm_vendor_dir rm -rf /workspace/vendor\nINFO     `rm_vendor_dir` stdout:\n\nINFO     rm_vendor_dir took 0 seconds\nINFO     descriptor_contents:\n{\n    \"_readme\": [\n        \"This file locks the dependencies of your project to a known state\",\n        \"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies\",\n        \"This file is @generated automatically\"\n    ],\n    \"content-hash\": \"f8027c7d3e5d36c84e1215645bb96efa\",\n    \"packages\": [\n        {\n            \"name\": \"asm89/stack-cors\",\n            \"version\": \"1.3.0\",\n            \"source\": {\n                \"type\": \"git\",\n                \"url\": \"https://github.com/asm89/stack-cors.git\",\n                \"reference\": \"b9c31def6a83f84b4d4a40d35996d375755f0e08\"\n            },\n            \"dist\": {\n                \"type\": \"zip\",\n                \"url\": \"https://api.github.com/repos/asm89/stack-cors/zipball/b9c31def6a83f84b4d4a40d35996d375755f0e08\",\n                \"reference\": \"b9c31def6a83f84b4d4a40d35996d375755f0e08\",\n                \"shasum\": \"\"\n            },\n            \"require\": {\n                \"php\": \"\u003e=5.5.9\",\n                \"symfony/http-foundation\": \"~2.7|~3.0|~4.0|~5.0\",\n                \"symfony/http-kernel\": \"~2.7|~3.0|~4.0|~5.0\"\n            },\n            \"require-dev\": {\n                \"phpunit/phpunit\": \"^5.0 || ^4.8.10\",\n                \"squizlabs/php_codesniffer\": \"^2.3\"\n            },\n            \"type\": \"library\",\n            \"extra\": {\n                \"branch-alias\": {\n                    \"dev-master\": \"1.2-dev\"\n                }\n            },\n            \"autoload\": {\n                \"psr-4\": {\n                    \"Asm89\\\\Stack\\\\\": \"src/Asm89/Stack/\"\n                }\n            },\n            \"notification-url\": \"https://packagist.org/downloads/\",\n            \"license\": [\n                \"MIT\"\n            ],\n            \"authors\": [\n                {\n                    \"name\": \"Alexander\",\n                    \"email\": \"iam.asm89@gmail.com\"\n                }\n            ],\n            \"description\": \"Cross-origin resource sharing library and stack middleware\",\n            \"homepage\": \"https://github.com/asm8.
Check the build log for errors: ####SEE BELOW####
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/gcloud" failed: step exited with non-zero status: 1

日志的完整内容对于这个网站来说太大了(16 k+行),但它的结尾是这样的:

Step #1 - "builder": Generating optimized autoload files
Step #1 - "builder": > Illuminate\Foundation\ComposerScripts::postAutoloadDump
Step #1 - "builder": > @php artisan package:discover --ansi
Step #1 - "builder": Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
Step #1 - "builder": 
Step #1 - "builder": error: `composer_install` returned code: 1
Step #1 - "builder": Traceback (most recent call last):
Step #1 - "builder":   File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
Step #1 - "builder":     "__main__", fname, loader, pkg_name)
Step #1 - "builder":   File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
Step #1 - "builder":     exec code in run_globals
Step #1 - "builder":   File "/usr/local/bin/ftl.par/__main__.py", line 65, in <module>
Step #1 - "builder":   File "/usr/local/bin/ftl.par/__main__.py", line 57, in main
Step #1 - "builder":   File "/usr/local/bin/ftl.par/__main__/ftl/common/ftl_error.py", line 58, in UserErrorHandler
Step #1 - "builder": IOError: [Errno 2] No such file or directory: '""/output'
Finished Step #1 - "builder"
ERROR
ERROR: build step 1 "gcr.io/gae-runtimes/php72_app_builder:php72_20200412_7_2_29_RC00" failed: step exited with non-zero status: 1

我的App.yaml文件:

service: heavnt-test
runtime: php72

env_variables:
    ## Put production environment variables here.
    APP_KEY: base64:TRoTxS+x5PeiAOlwV/F1AwyfgV6y8mZloqGastMYylQ=
    APP_STORAGE: /tmp
    VIEW_COMPILED_PATH: /tmp
    SESSION_DRIVER: cookie  
    APP_SERVICES_CACHE: /tmp/services.php
    APP_PACKAGES_CACHE: /tmp/packages.php
    APP_CONFIG_CACHE: /tmp/config.php
    APP_ROUTES_CACHE: /tmp/routes.php

handlers:
- url: /(.*\.(gif|png|jpg|css|js))$
  static_files: public/\1
  upload: public/.*\.(gif|png|jpg|css|js)$

- url: /.*
  secure: always
  redirect_http_response_code: 301
  script: auto

entrypoint: serve /public/index.php

我的Cloudbuild.yaml文件:

steps:
- name: "gcr.io/cloud-builders/gcloud"
  args: ["app", "deploy"]
timeout: "1600s"

我尝试使用Github Desktop检查添加我的composer包时文件上发生的更改,但添加和更改的文件太多,我没有线索
编辑18/05/2020:
在16 k+行日志中,我发现了这个问题:

Step #1 - "builder": INFO     composer_install composer install --no-dev --no-progress --no-suggest --no-interaction
Step #1 - "builder": INFO     `composer_install` stdout:
Step #1 - "builder": 
Step #1 - "builder": In PackageManifest.php line 177:
Step #1 - "builder":                                                                           
Step #1 - "builder":   The /workspace/bootstrap/cache directory must be present and writable.

我不知道如何弄清楚这是否是我正在经历的问题,因为一切都在本地工作正常,过去在网上工作正常。

vfh0ocws

vfh0ocws1#

为了进一步研究,我尝试直接从本地设置(云应用部署)部署我的应用,所以没有使用我的Github〉GCloud Build桥。
它部署得很好,所以我尝试访问我最初想添加的docs包,由于public/docs/中的静态文件没有提供,我将这些行添加到我的app.yaml中:

- url: /docs
  static_dir: public/docs

”””所以,据我所知,这是唯一的线我改变了。
为了尝试,我通过我的原始进程提交了这段代码(docs包+app.yaml行),它完美地部署了(触发了多次以确保)。
所以总结一下,我完全不知道这是怎么发生的,为什么会发生,我真的希望它不会再次出现。

mbyulnm0

mbyulnm02#

对于今天(2023年,Laravel 9/10)仍然有问题的人来说,问题在于composer.json post-autoload-dump脚本中的php artisan package:discover命令,该命令检查bootstrap/cache目录是否存在且可写。如果不存在,则退出错误级别1,从而中断GAE构建。
要解决这个问题,请像这样编辑composer.json脚本:

...
        "post-autoload-dump": [
            "mkdir -p ./bootstrap/cache/",
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-install-cmd": [
            "chmod -R 755 bootstrap\/cache",
            "php artisan cache:clear"
        ],
...

来源:https://github.com/GoogleCloudPlatform/php-docs-samples/issues/1167#issuecomment-747304053

相关问题