谷歌云 ruby​​ 部署和 ruby​​-docker

Nox*_*Nox 0 google-app-engine ruby-on-rails docker

我是第一次尝试把我的rails项目放到google云引擎上,遇到了很多麻烦。我想使用自定义运行时上传我的项目app.yaml(因为我也希望 yarn 安装依赖项),但是部署命令失败并出现以下错误:

Error Response: [4] Your deployment has failed to become healthy in the allotted time and therefore was rolled back. If you believe this was an error, try adjusting the 'app_start_timeout_sec' setting in the 'readiness_check' section.

PS:应用程序在本地运行(开发和生产环境)。

我的 app.yaml 看起来像这样:

entrypoint: bundle exec rails s -b '0.0.0.0' --port $PORT
env: flex
runtime: custom
env_variables:
  My Environment variables

beta_settings:
  cloud_sql_instances: ekoma-app:us-central1:ekoma-db

readiness_check:
  path: "/_ah/health"
  check_interval_sec: 5
  timeout_sec: 4
  failure_threshold: 2
  success_threshold: 1
  app_start_timeout_sec: 120
Run Code Online (Sandbox Code Playgroud)

我的 Dockerfile 看起来像这样:

FROM l.gcr.io/google/ruby:latest

RUN apt-get update -qq && apt-get install apt-transport-https

RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev imagemagick yarn
WORKDIR /app
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
COPY package.json /app/package.json
COPY yarn.lock /app/yarn.lock

RUN gem install pkg-config -v "~> 1.1"
RUN bundle install && npm install

COPY . /app
Run Code Online (Sandbox Code Playgroud)

在使用 ruby​​ 运行时部署时,我意识到生成的 dockerfile 复杂得多,而且可能是完整的,谷歌提供了一个 repo 来生成它。因此,我尝试查看 google 共享的 ruby​​-docker 公共存储库,但我不知道如何使用他们生成的 docker 映像,因此解决了我的 Dockerfile 问题

https://github.com/GoogleCloudPlatform/ruby-docker

有人可以帮我弄清楚我的设置有什么问题以及如何运行这些 ruby​​-docker 映像(似乎非常有用!)?

谢谢!

Dan*_*uma 5

当自定义运行时正在运行时,不使用 app.yaml 中的“入口点”字段。相反,在您的 Dockerfile 中设置 CMD。例如:

CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0", "--port", "8080"]
Run Code Online (Sandbox Code Playgroud)

这可能会使您的应用程序运行。(请记住,环境变量不是以 exec 形式插入的,因此我将您的$PORT替换为硬编码端口 8080,这是 App Engine 期望的端口。)

作为备选:

可能是可以使用Ruby运行时图像红宝石泊坞窗回购,而不必使用自定义运行时(即你可能不需要编写自己的Dockerfile),即使你有喜欢做纱安装自定义生成步骤。中的大部分构建过程runtime: ruby都是可定制的,但没有很好的文档记录。如果你想尝试这条路,TL;DR 是:

  1. 使用runtime: ruby你的app.yaml,不要提供自己的Dockerfile。(并恢复entrypoint当然。)

  2. 如果要安装 ubuntu 包通常不存在于 中runtime: ruby,请将它们列app.yamlruntime_config:下packages。例如:

    runtime_config:
      packages:
        - libgeos-dev
        - libproj-dev
    
    Run Code Online (Sandbox Code Playgroud)
  3. 如果要运行自定义构建步骤,请将它们列app.yamlruntime_config:下build。在 bundle install 步骤(它本身不能被修改)之后,它们在 Dockerfile 中执行。例如:

    runtime_config:
      build:
        - npm install
        - bundle exec rake assets:precompile
        - bundle exec rake setup_my_stuff
    
    Run Code Online (Sandbox Code Playgroud)

    请注意,默认情况下,如果您不提供自定义构建步骤,则 ruby​​ 运行时的行为就像只有一个构建步骤:bundle exec rake assets:precompile || true。也就是说,默认情况下,runtime: ruby将在应用引擎部署期间尝试编译您的资产。如果您确实修改了构建步骤并且希望保留此行为,请确保将该 rake 任务作为自定义构建步骤的一部分。