簡體   English   中英

部署ruby api google雲

[英]Deploy ruby api google cloud

我是谷歌雲的新手,當我嘗試將我的ruby api部署到谷歌雲時,我遇到了這個問題,這就是我所做的:

我已將我的ruby api上傳到github(它在localhost上運行正常),這里>> https://github.com/guisantogui/it

我一直在通過hello world google教程>> https://cloud.google.com/ruby/getting-started/hello-world

並且它按預期工作,但是當我上傳我自己的應用程序時,我得到了這個http 502 bad gateway消息,這里是日志:

2017-10-30 23:48:53 default[20171030t213633]  => Booting Puma
2017-10-30 23:48:53 default[20171030t213633]  => Rails 5.1.4 application starting in production 
2017-10-30 23:48:53 default[20171030t213633]  => Run `rails server -h` for more startup options
2017-10-30 23:48:53 default[20171030t213633]  Puma starting in single mode... 
2017-10-30 23:48:53 default[20171030t213633]  * Version 3.10.0 (ruby 2.4.1-p111), codename: Russell's Teapot
2017-10-30 23:48:53 default[20171030t213633]  * Min threads: 5, max threads: 5
2017-10-30 23:48:53 default[20171030t213633]  * Environment: production
2017-10-30 23:48:53 default[20171030t213633]  * Listening on tcp://0.0.0.0:3000 
2017-10-30 23:48:53 default[20171030t213633] Use Ctrl-C to stop 
2017-10-30 23:58:01 default[20171030t213633]  "GET /" 502 
2017-10-30 23:58:02 default[20171030t213633]  "GET /favicon.ico" 502 
2017-10-30 23:58:06 default[20171030t213633]  "GET /" 502 
2017-10-30 23:58:06 default[20171030t213633]  "GET /favicon.ico" 502 
2017-11-01 10:54:50 default[20171030t213633]  "GET /" 502 
2017-11-01 10:54:50 default[20171030t213633]  "GET /favicon.ico" 502 
2017-11-01 10:55:02 default[20171030t213633]  "GET /favicon.ico" 502 
2017-11-01 10:55:02 default[20171030t213633]  "GET /tatoo_artis/list" 502

最后,我認為app.yaml文件更重要:

entrypoint: bundle exec rails server Puma -p 3000
env: flex
runtime: ruby

在此先感謝,我不知道是什么問題以及如何解決它!

Google Cloud示例https://cloud.google.com/ruby/getting-started/hello-world使用Sinatra,而不是Rails。 如果你在app.yaml文件中查看https://github.com/GoogleCloudPlatform/ruby-docs-samples/tree/master/appengine/hello_world ,它只有:

# [START app_yaml]
runtime: ruby
env: flex
entrypoint: bundle exec ruby app.rb
# [END app_yaml]

而app.rb只是一個簡單的sinatra應用程序。

# [START app]
require "sinatra"
get "/" do
  "Hello world!"
end
# [END app]

Rails配置有點復雜。 首先,似乎GCP App Engine不支持Puma(如果我錯了請糾正我),但是需要設置一些環境變量,比如SECRET_KEY(使用bundle exec rails secret ),所以你的應用程序。 yaml文件應該是:

# [START app_yaml]
runtime: ruby
env: flex
entrypoint: bundle exec rackup --port $PORT
env_variables:
  SECRET_KEY_BASE: [SECRET_KEY]
# [END app_yaml]

記住你還需要運行:

RAILS_ENV=production bundle exec rails assets:precompile

在跑步之前

gcloud app deploy

預編譯您的資產。

您正在尋找的內容在本指南中: https//cloud.google.com/ruby/rails/appengine ,跳過初始步驟(因為您已經擁有該應用)並直接進入:“將應用程序部署到應用程序引擎靈活的環境“

來源:Google指南: https//cloud.google.com/ruby/rails/appengine

代碼: https//github.com/GoogleCloudPlatform/ruby-docs-samples/tree/master/appengine/rails-hello_world

編輯:我看到你的日志中有一些GET請求,所以也許支持Puma。 嘗試在部署之前設置SECRET_KEY並預編譯資產。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM