【问题标题】:gcloud app deploy fails with 7.4 runtime with "requires composer-runtime-api ^2.0.0"gcloud 应用程序部署失败,7.4 运行时“需要 composer-runtime-api ^2.0.0”
【发布时间】:2021-11-07 03:47:51
【问题描述】:

我一直在尝试使用gcloud app deploy 构建一个 PHP 7.4 应用程序,但它失败了:

您的要求无法解决为一组可安装的软件包。 问题一

  • jean85/pretty-package-versions 2.0.4 的安装请求 -> 可由 jean85/pretty-package-versions[2.0.4] 满足。
  • jean85/pretty-package-versions 2.0.4 需要 composer-runtime-api ^2.0.0 -> 找不到匹配的包。

这是我的composer.json

{
  "require": {
    "slim/slim": "^4.0",
    "slim/psr7": "^1.3",
    "slim/http": "^1.2",
    "mongodb/mongodb": "1.5",
    "ext-mongodb": "^1.6",
    "jean85/pretty-package-versions": "^2.0",
    "nesbot/carbon": "^2.52",
    "php-di/php-di": "^6.3",
    "vlucas/phpdotenv": "^5.3"
  },
  "require-dev": {
    "phpunit/phpunit": "^9.5"   
  }
}

注意事项

我在网上找到的所有信息都是关于可能使用 Composer 1 而不是 Composer 2。

关于 Google App Engine 上的 composer 的最大优点是,当我在交互式控制台中输入 composer --version 时,我会得到“2.1.6”,就像在我的本地开发环境中一样。

最后,作为证据,这是 Cloud Build 日志的尾部:

Step #2 - "build": Status: Downloaded newer image for eu.gcr.io/gae-runtimes/buildpacks/php74/builder:php74_20210728_7_4_21_RC00
Step #2 - "build": eu.gcr.io/gae-runtimes/buildpacks/php74/builder:php74_20210728_7_4_21_RC00
Step #2 - "build": Warning: Not restoring or caching layer data, no cache flag specified.
Step #2 - "build": ===> DETECTING
Step #2 - "build": 3 of 4 buildpacks participating
Step #2 - "build": google.php.composer  0.9.1
Step #2 - "build": google.php.appengine 0.9.0
Step #2 - "build": google.utils.label   0.0.1
Step #2 - "build": ===> ANALYZING
Step #2 - "build": Previous image with name "eu.gcr.io/voltaic-plating-324009/app-engine-tmp/app/default/ttl-18h:e941687b-9375-4927-97bb-eecaaf779592" not found
Step #2 - "build": ===> RESTORING
Step #2 - "build": ===> BUILDING
Step #2 - "build": === PHP - Composer (google.php.composer@0.9.1) ===
Step #2 - "build": --------------------------------------------------------------------------------
Step #2 - "build": Running "php -r echo PHP_VERSION;"
Step #2 - "build": 7.4.21Done "php -r echo PHP_VERSION;" (378.442053ms)
Step #2 - "build": DEBUG: Current dependency hash: "03f83fc1c2a57c9fa5ba4fe96c867d393f905ed37a0aecd50da328fd8392dae3"
Step #2 - "build": DEBUG:   Cache dependency hash: ""
Step #2 - "build": DEBUG: No metadata found from a previous build, skipping cache.
Step #2 - "build": Installing application dependencies.
Step #2 - "build": DEBUG: ***** CACHE MISS: "prod dependencies"
Step #2 - "build": --------------------------------------------------------------------------------
Step #2 - "build": Running "composer install --no-dev --no-progress --no-suggest --no-interaction --optimize-autoloader"
Step #2 - "build": Loading composer repositories with package information
Step #2 - "build": Installing dependencies from lock file
Step #2 - "build": Your requirements could not be resolved to an installable set of packages.
Step #2 - "build": 
Step #2 - "build":   Problem 1
Step #2 - "build":     - Installation request for jean85/pretty-package-versions 2.0.4 -> satisfiable by jean85/pretty-package-versions[2.0.4].
Step #2 - "build":     - jean85/pretty-package-versions 2.0.4 requires composer-runtime-api ^2.0.0 -> no matching package found.
Step #2 - "build": 
Step #2 - "build": Potential causes:
Step #2 - "build":  - A typo in the package name
Step #2 - "build":  - The package is not available in a stable-enough version according to your minimum-stability setting
Step #2 - "build":    see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
Step #2 - "build":  - It's a private package and you forgot to add a custom repository to find it
Step #2 - "build": 
Step #2 - "build": Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Step #2 - "build": Done "composer install --no-dev --no-progress --no-suggest --no-in..." (445.718128ms)
Step #2 - "build": Failure: (ID: 467317e4) Loading composer repositories with package information
Step #2 - "build": Installing dependencies from lock file
Step #2 - "build": Your requirements could not be resolved to an installable set of packages.
Step #2 - "build": 
Step #2 - "build":   Problem 1
Step #2 - "build":     - Installation request for jean85/pretty-package-versions 2.0.4 -> satisfiable by jean85/pretty-package-versions[2.0.4].
Step #2 - "build":     - jean85/pretty-package-versions 2.0.4 requires composer-runtime-api ^2.0.0 -> no matching package found.
Step #2 - "build": 
Step #2 - "build": Potential causes:
Step #2 - "build":  - A typo in the package name
Step #2 - "build":  - The package is not available in a stable-enough version according to your minimum-stability setting
Step #2 - "build":    see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
Step #2 - "build":  - It's a private package and you forgot to add a custom repository to find it
Step #2 - "build": 
Step #2 - "build": Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

如何确保我在 Google Cloud 运行时中有 composer 2,所以我没有收到“需要 composer-runtime-api ^2.0.0 -> 找不到匹配的包”。错误?

【问题讨论】:

  • 这是 Composer 方面的一个错误。看看这个GitHub issue link 并尝试通过运行composer self-update 2.1.3 将 Composer 升级到 2.1.3 的最新版本
  • @PriyashreeBhadra 最新作曲家是 2.1.6,而不是 2.1.3。并且 OP 说他们有“2.1.16”(它不存在,很可能是“2.1.6”的错字)。您提到的错误已在 6 月份解决,因此这里不应该是这种情况。您的建议会使作曲家降级到比最新版本更旧的版本。
  • @yivi 你是对的,但我想确认作曲家的版本,因为他发布了“2.1.16”,但我们假设它的 2.1.6 不存在,因为 2.1.16 不存在。
  • 只是让大家知道我通过使用mongodb/mongodb 1.5ext-mongodb 1.6 并使用extension=mongodb.so 添加单行php.ini 文件,成功构建了应用程序并无错误地连接到外部MongoDB 集群在我的应用发行版的根目录下。

标签: php composer-php gcloud


【解决方案1】:

requires composer-runtime-api ^2.0.0 可以很容易地解决:使用 Composer v2 运行 composer install,而不是使用任何旧版本。通过调用composer diagnose 可以读取该版本。可以在page that is linked in the error message

上找到调试问题的所有进一步步骤

【讨论】:

  • Nico,只是让你知道,我乍一看,我没有作曲家版本的选择,因为后者是由 Google App Engine 强加的。但是,@yivi 让我尝试一个技巧,有机会我会尝试,我会在这里给出我的反馈。
【解决方案2】:

目前,Google 提供的运行时映像是在 Composer 2 发布之前构建的(巨大提示:最新提供的 PHP 还不包括 8.0),因此如果您需要更新的东西,则不能使用 Google 提供的运行时。

有点遗憾,他们没有提供更新的运行时或更好的选项,但并没有失去所有希望。

您始终可以构建自己的custom runtimes

我能想到的基于 Google 的 PHP 7.4 但使用 Composer 2 拥有自己的自定义运行时的最快和最肮脏的方法是在您的 app.yaml 旁边添加一个 Dockerfile 并使用以下内容:

FROM gcr.io/google-appengine/php74:latest

RUN composer self-update --2

runtime,在app.yaml,应该说:custom

目前无法对其进行测试,但这应该会让您走上正轨。

【讨论】:

  • 感谢@yivi 的建议。我可以欣赏来自 cloud.google.com/appengine/docs/flexible/php/… 的自定义参数和容器注册表 URI。但是,当我启动部署时,我收到以下消息:`ERROR: (gcloud.app.deploy) INVALID_ARGUMENT: Invalid runtime 'custom' specified。接受的运行时是:[php, php55, [...] , php72, php73, php74, gcf preprod, gcf prod, gcf staging [...](截断以适应)]
  • 没关系,env 应该设置为flex。是standard。我留下了我之前的评论以帮助其他人。
  • 我收到了这个:Step 1/2 : FROM gcr.io/google-appengine/php74 manifest for gcr.io/google-appengine/php74:latest not found: manifest unknown: Failed to fetch "latest" from request "/v2/google-appengine/php74/manifests/latest". 从那时起,缓存被使用了。如何清除现有图像?
  • 更新:我不知道自上周五以来发生了什么变化,但该应用程序现在构建在 std 环境中,没有使用 composer 或 jean85 或类似的任何东西。我只保留了关于 mongodb 的两个 composer.json 参考行:lib 和扩展。不过,扩展似乎被忽略了:运行时找不到 PHP 的 MongoDB 驱动程序。 Class 'MongoDB\\Driver\\Manager' not found
猜你喜欢
  • 2021-06-25
  • 1970-01-01
  • 2020-03-25
  • 2020-01-14
  • 2019-03-08
  • 2018-08-14
  • 2016-10-20
  • 2020-07-15
  • 2017-01-24
相关资源
最近更新 更多