Reputation: 4116
I'm pretty new to Google cloud and I have this issue when I try to deploy my ruby api to google cloud, here goes what I have done:
I have uploaded my ruby api to github (it works fine on localhost), here >> https://github.com/guisantogui/it
I have been trough hello world google tutorial >> https://cloud.google.com/ruby/getting-started/hello-world
and it worked as expected, but when I upload my own application I got this http 502 bad gateway
message, here goes the logs:
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
And finally and i think more important the app.yaml file:
entrypoint: bundle exec rails server Puma -p 3000
env: flex
runtime: ruby
Thanks in advance, i got no idea what is the problem and how to fix it!
Upvotes: 4
Views: 503
Reputation: 2190
The Google Cloud example https://cloud.google.com/ruby/getting-started/hello-world uses Sinatra, not Rails. If you check https://github.com/GoogleCloudPlatform/ruby-docs-samples/tree/master/appengine/hello_world in the app.yaml file it just has:
# [START app_yaml]
runtime: ruby
env: flex
entrypoint: bundle exec ruby app.rb
# [END app_yaml]
And app.rb is just a simple sinatra app.
# [START app]
require "sinatra"
get "/" do
"Hello world!"
end
# [END app]
Rails configuration is a little bit more complex. First of all it seems that GCP App Engine doesn't support Puma (please correct me if I am wrong), but rackup, and you need to set some environment variables like the SECRET_KEY (use bundle exec rails secret
), so your app.yaml file should be:
# [START app_yaml]
runtime: ruby
env: flex
entrypoint: bundle exec rackup --port $PORT
env_variables:
SECRET_KEY_BASE: [SECRET_KEY]
# [END app_yaml]
Remember you also need to run:
RAILS_ENV=production bundle exec rails assets:precompile
before running
gcloud app deploy
to precompile your assets.
What you are looking for is in this guide: https://cloud.google.com/ruby/rails/appengine, skip the initial steps (since you already have the app) and go straight to: "Deploy the app to the App Engine flexible environment"
Sources: Google guide: https://cloud.google.com/ruby/rails/appengine
Code: https://github.com/GoogleCloudPlatform/ruby-docs-samples/tree/master/appengine/rails-hello_world
EDIT: I see you have some GET requests in your logs, so maybe Puma is supported. Try to just set up the SECRET_KEY and precompile your assets before deploy.
Upvotes: 1