【问题标题】:How to change the version of bundler used in Cloud Functions deployment?如何更改 Cloud Functions 部署中使用的捆绑器版本?
【发布时间】:2021-03-10 13:37:54
【问题描述】:

上下文

从几天前开始,Cloud Functions 的部署一直失败。

宝石文件

source "https://rubygems.org"

ruby "~> 2.7.0"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem "google-cloud-firestore"

部署脚本

$ gcloud functions deploy my_func --region=us-central1 --memory=128MB --runtime=ruby27

(snip)

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Bundler found conflicting requirements for the Ruby version:
  In Gemfile:
    Ruby (~> 2.7.0)

    google-cloud-firestore was resolved to 2.4.1, which depends on
      google-cloud-firestore-v1 (~> 0.0) was resolved to 0.4.0, which depends on
        gapic-common (~> 0.3) was resolved to 0.4.0, which depends on
google-protobuf (~> 3.15, >= 3.15.2) was resolved to 3.15.5, which
depends on
            Ruby (< 3.1.dev, >= 2.3)

    google-cloud-firestore was resolved to 2.4.1, which depends on
      google-cloud-firestore-v1 (~> 0.0) was resolved to 0.4.0, which depends on
        gapic-common (~> 0.3) was resolved to 0.4.0, which depends on
          grpc (~> 1.36) was resolved to 1.36.0, which depends on
            Ruby (< 3.1.dev, >= 2.4); Error ID: af32a539

为什么?

这是自 bundler v2.2.8 以来 bundler 的回归。

这已在 bundler v2.2.10 中得到修复

所以我希望捆绑器版本低于 v2.2.8 或高于 v2.2.10。

Cloud Functions 部署 (gcloud functions deploy) 自动运行 bundle install 并使用部署任务中安装的 bundler

部署任务中的当前捆绑器版本是 v2.2.9

验证码

宝石文件

source "https://rubygems.org"

ruby "~> 2.7.0"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }


gem "bundler", "!= 2.2.8", "!= 2.2.9" 

部署脚本

$ gcloud functions deploy my_func --region=us-central1 --memory=128MB --runtime=ruby27

(snip)

Resolving dependencies...
Bundler could not find compatible versions for gem "bundler":
  In Gemfile:
    bundler (!= 2.2.8, != 2.2.9)

  Current Bundler version:
    bundler (2.2.9)

主题

gcloud functions deploy 没有一些参数来更改捆绑器版本...

https://cloud.google.com/sdk/gcloud/reference/functions/deploy?hl=ja

如何更改 Cloud Functions 部署中使用的捆绑器版本?

【问题讨论】:

    标签: ruby google-cloud-platform google-cloud-functions


    【解决方案1】:

    我也遇到了类似的问题,但是错误输出略有不同。一个共同点是:

    Bundler found conflicting requirements for the Ruby version:
    

    在进行了一些挖掘和故障排除后,我发现 Google Cloud Functions 代表我们锁定了捆绑的平台。我不是 Ruby 专家,但我怀疑这会影响 Gemfile 中的信息与 Ruby 版本一起被读取的方式。

    来自 Google Cloud Functions 的示例日志

    2021-03-10 13:13:01.764 PST
    Step #4 - "builder": Done "bundle lock --add-platform x86_64-linux" 
    

    解决方案: 在本地更新 bundler(我更新到 2.2.14)。删除您的Gemfile.lock 文件并重新运行bundle install 以生成Gemfile.lock。如果有什么需要修复的话,这应该可以修复依赖关系。

    最重要的是,它将更新您的 Gemfile.lock 中的 Platforms 部分,以符合 Google 的预期。

    就我而言,平台已从 Ruby 更新为 x86_64-darwin-19

    或者,如果可能的话,另一种方法可能是只使用 bundle 更新平台。

    【讨论】:

    • 感谢您的回答。终于我成功部署了!
    • 没问题,很高兴您能够成功部署!
    【解决方案2】:

    最终我已经成功部署了以下内容。

    1. gem install bundler --no-doc
    2. 删除Gemfile.lock
    3. 重新创建Gemfile.lock (bundle install)

    差异

    $ git --no-pager diff main
    
    diff --git a/Gemfile.lock b/Gemfile.lock
    index 5e7502b..b5642ab 100644
    --- a/Gemfile.lock
    +++ b/Gemfile.lock
    @@ -57,7 +57,6 @@ GEM
           gapic-common (~> 0.3)
           google-cloud-errors (~> 1.0)
           grpc-google-iam-v1 (>= 0.6.10, < 2.0)
    -    google-protobuf (3.15.5)
         google-protobuf (3.15.5-universal-darwin)
         googleapis-common-protos (1.3.11)
           google-protobuf (~> 3.14)
    @@ -72,9 +71,6 @@ GEM
           multi_json (~> 1.11)
           os (>= 0.9, < 2.0)
           signet (~> 0.14)
    -    grpc (1.36.0)
    -      google-protobuf (~> 3.14)
    -      googleapis-common-protos-types (~> 1.0)
         grpc (1.36.0-universal-darwin)
           google-protobuf (~> 3.14)
           googleapis-common-protos-types (~> 1.0)
    @@ -160,7 +156,6 @@ GEM
    
     PLATFORMS
       ruby
    -  x86_64-darwin-17
    
     DEPENDENCIES
       dotenv
    @@ -180,4 +175,4 @@ RUBY VERSION
        ruby 2.7.2p137
    
     BUNDLED WITH
    -   2.1.4
    +   2.2.14
    

    【讨论】:

      猜你喜欢
      • 2012-03-07
      • 2019-03-01
      • 2017-08-17
      • 2017-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多