googlecloudplatform / getting-started-ruby Goto Github PK
View Code? Open in Web Editor NEWA tutorial for creating a complete application using Ruby on Google Cloud Platform
Home Page: https://cloud.google.com/ruby
License: Apache License 2.0
A tutorial for creating a complete application using Ruby on Google Cloud Platform
Home Page: https://cloud.google.com/ruby
License: Apache License 2.0
I could be wrong, but because the entire repo is sent to the cloud repository, I believe this line needs to be updated to ./7-compute-engine/gce/configure.sh
I'm trying to follow the Bookshelf on Kubernetes Engine tutorial, however get caught out when trying to deploy the bookshelf-worker
backend, as per this step.
It looks like the bookshelf-worker
pods fail to start and then backs off after too many failures:
> kubectl create -f bookshelf-worker.yaml
> kubectl get pods
NAME READY STATUS RESTARTS AGE
bookshelf-frontend-4221472564-czvth 1/1 Running 0 13m
bookshelf-frontend-4221472564-fwkbz 1/1 Running 0 13m
bookshelf-frontend-4221472564-vjmzg 1/1 Running 0 13m
bookshelf-worker-3385195378-xg9r5 0/1 CrashLoopBackOff 6 8m
bookshelf-worker-3385195378-zqwx9 0/1 CrashLoopBackOff 6 8m
I looked at the logs and a NoMethodError
seems to be the culprit:
> kubectl logs -f bookshelf-worker-3385195378-xg9r5
12:26:22 worker.1 | started with pid 31
12:26:25 worker.1 | Running worker to lookup book details
12:26:26 worker.1 | rake aborted!
12:26:26 worker.1 | NoMethodError: undefined method `subscription' for nil:NilClass
12:26:26 worker.1 | /app/lib/active_job/queue_adapters/pub_sub_queue_adapter.rb:32:in `run_worker!'
12:26:26 worker.1 | /app/lib/tasks/run_worker.rake:4:in `block in <top (required)>'
12:26:26 worker.1 | /app/vendor/bundle/ruby/2.2.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
12:26:26 worker.1 | Tasks: TOP => run_worker
12:26:26 worker.1 | (See full trace by running task with --trace)
12:26:26 worker.1 | exited with code 1
12:26:26 system | sending SIGTERM to all processes
Any ideas on how to resolve? Assistance appreciated.
Issue:
The root README contains information to get started and includes installation instructions for Cloud SDK. The instructions are presented with a link and a command. As a passing developer, I wouldn't try the link and just run the command presented right after. It also doesn't include gcloud init
to setup the default project.
Possible-Changes:
I vote to remove the shell command and just link the user out.
Can't connect to cloud sql through ipv6?
Any help is appreciated!
Remove references to gcd for emulating Datastore.
Also, update the tests to wait for Datastore operations to complete. The live service is eventually consistent whereas the emulator can be run with 100% consistency.
Original question:
database.example.yml
$ gcd.sh create gcd-test-dataset-directory
$ gcd.sh start --testing ./gcd-test-dataset-directory/
What is gcd.sh?
Hello, it appears after #96 that the docs on the google cloud website have not been updated.
I was following the tutorial here to learn about rails and cloud datastore here: https://cloud.google.com/ruby/getting-started/using-cloud-datastore however, the docs point to directories and application structure which no longer exists. How should one go about this? Do the tutorial docs need to be updated on the google cloud site and/or has the tutorial been updated somewhere else which I should now follow?
Thanks in advance.
The following page only specifies HTTP redirect URLs which break when running the app in HTTPS mode: https://cloud.google.com/ruby/getting-started/authenticate-users
We get the following 404 page:
400. That’s an error.
Error: redirect_uri_mismatch
Application: ruby-on-rails-on-google
You can email the developer of this application at: [email protected]
The redirect URI in the request, http://flowing-lead-130219.appspot.com/auth/google_oauth2/callback, does not match the ones authorized for the OAuth client. Visit https://console.developers.google.com/apis/credentials/oauthclient/844847615690-7t80tao2364ilp7t8bvljif4lnn8ulmq.apps.googleusercontent.com?project=844847615690 to update the authorized redirect URIs.
With the following technical reason:
Request Details
access_type=offline
scope=email profile
response_type=code
redirect_uri=http://flowing-lead-130219.appspot.com/auth/google_oauth2/callback
state=390f0b29f780146582b934660b21638be38934ce97035971
client_id=844847615690-7t80tao2364ilp7t8bvljif4lnn8ulmq.apps.googleusercontent.com
This is what I get
root@b75e5b6f5b9b:/app# bundle exec foreman start --formation web=1
21:06:12 web.1 | started with pid 117
21:06:14 web.1 | config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
21:06:14 web.1 |
21:06:14 web.1 | * development - set it to false
21:06:14 web.1 | * test - set it to false (unless you use a tool that preloads your test environment)
21:06:14 web.1 | * production - set it to true
21:06:14 web.1 |
21:06:14 web.1 | /app/config/initializers/omniauth.rb:7:in `block in <top (required)>': undefined method `[]' for nil:NilClass (NoMethodError)
For some reason config/settings.yml
is not loading.
Starting without foreman works fine:
root@b75e5b6f5b9b:/app# bundle exec rackup -p 8080 -E production config.ru
[2016-04-22 21:06:59] INFO WEBrick 1.3.1
[2016-04-22 21:06:59] INFO ruby 2.2.3 (2015-08-18) [x86_64-linux]
[2016-04-22 21:06:59] INFO WEBrick::HTTPServer#start: pid=122 port=8080
Hello Guys,
As referenced in this thread googleapis/google-cloud-ruby#910
The bookshelf tutorial isn't going smoothly and got stucking issues due to no mention on setting up credentials, env variables, service accounts, confusion about naming convention, deployment troubleshooting in the tutorial or code-sample etc.
Hope you find the pointers useful for better docs/sample.
use-sql.sh copies from structured_data/sql
, but that directory does not exist
v0.9.0 switches to using Cloud Datastore v1beta3:
https://github.com/GoogleCloudPlatform/gcloud-ruby/releases/tag/v0.9.0
v1beta2 will be decommissioned on September 30, 2016:
https://cloudplatform.googleblog.com/2016/04/Google-Cloud-Datastore-gets-faster-cross-platform-API.html
To reduce maintenance and not have to duplicate issues / etc across all Ruby samples that are used in or referenced by our cloud.google.com documentation, this sample application should be moved into ruby-docs-samples
See tracking issue in ruby-docs-samples repo: ...
Many of the issues we file are for things such as "update all Ruby samples to use the latest X.Y.Z version of the ABC library." This type of maintenance is more difficult with our samples in 2 repositories. It's easy to forget about this repository ... plus you have to git grep
across both. Yuck!
We also will be making it simpler to run end-to-end tests for all samples found in ruby-docs-samples and having these Rails applications as part of that test pipeline will simplify things greatly!
Before this can be closed and the repo completely moved ...
We should match the nodejs getting started guide:
https://github.com/GoogleCloudPlatform/nodejs-getting-started
The bookshelf app: https://library-1071.appspot.com gives the following error:
We're sorry, but something went wrong.
If you are the application owner check the logs for more information.
How do I check the logs? How to fix this problem?
reproduce by creating a book with a gibberish name, I get:
Exception
TypeError
Error
no implicit conversion of NoMethodError into String
/home/jeffmendoza/git/getting-started-ruby/7-compute-engine/app/jobs/lookup_book_details_job.rb:31:in +' /home/jeffmendoza/git/getting-started-ruby/7-compute-engine/app/jobs/lookup_book_details_job.rb:31:in
block in perform'
/home/jeffmendoza/.gem/gems/google-api-client-0.9.20/lib/google/apis/core/http_command.rb:116:in rescue in execute' /home/jeffmendoza/.gem/gems/google-api-client-0.9.20/lib/google/apis/core/http_command.rb:95:in
execute'
/home/jeffmendoza/.gem/gems/google-api-client-0.9.20/lib/google/apis/core/base_service.rb:351:in execute_or_queue_command' /home/jeffmendoza/.gem/gems/google-api-client-0.9.20/generated/google/apis/books_v1/service.rb:2043:in
list_volumes'
/home/jeffmendoza/git/getting-started-ruby/7-compute-engine/app/jobs/lookup_book_details_job.rb:29:in `perform'
...
See current fog usage: https://github.com/GoogleCloudPlatform/getting-started-ruby/blob/9ac76fddd441efc73e5f992a63bb34a10bd15bbe/3-cloud-storage/config/initializers/fog_cloud_storage.rb
Unnecessary and overly complicated for the Getting Started with Cloud Storage for the Bookshelf application
Page: https://cloud.google.com/ruby/getting-started/authenticate-users
Problem: Creating new credentials for use with oauth ID indicates a set of URL's which should be used which are based on the {{Project Name}}.appspot.com.
This is not valid as according to the App Engine Flexible Release documentation;
Domain update
Traffic is now served from the appspot-preview.com domain instead of the appspot.com domain. All traffic from the App Engine flexible environment will be automatically redirected to the new domain. All App Engine Standard traffic will continue to be through appspot.com. When the App Engine flexible environment is generally available (GA), users will be able to use the appspot.com or appspot-preview.com domains for routing traffic.
The URLs that are generated are based on the version and project name, which is not necessarily known beforehand preventing the oauth-credentials callback whitelist to be effectivly populated.
A workaround may be possible, but I do not know GCP well enough to speculate.
Deploying a Rails app on a Managed VM with SSL enabled in the config/environments/production.rb as follows:
config.force_ssl = true
causes an infinite redirect loop. It appears that the HTTP_X_FORWARDED_PROTO HTTP header isn’t set properly.
force_ssl relies on the HTTP_X_FORWARDED_PROTO HTTP header to determine whether or not the request was an HTTPS request. If this setting isn't set to https then you end up with an infinite redirect loop as force_ssl will always think the forwarded request isn't HTTPS.
When we deploy Rails to a managed VM it appears each machine is set up with nginx in front? Is it possible for nginx to take care of the header?
Note: With force_ssl enabled I also had to disable health checks as they are sent http (not https) so Rails returned a 301 redirect. This caused the instance to be classified as unhealthy and it wouldn't receive any requests.
From a security perspective isn't it bad form to store the production sql user & password in the config/database.yml on a development machine as this would likely get checked into version control? It seems like Google is recommending using the Google SQL Proxy instead when working from a App Engine Managed VM.
Would it be possible to address how to store these passwords somewhere in the getting started guide? I appreciate using SQL Proxy might be beyond the scope of this guide. If so, could you link to some best practices for doing so elsewhere? Perhaps it would be good to make clear that checking production credentials into version control isn't normally done?
Thanks!
I receive the following error when the workers run (using backend:datastore
for 6-task-queueing
.
13:26:49 worker.2 | Book lookup request (5679413765079040)
13:26:49 worker.2 | rake aborted!
13:26:49 worker.2 | NoMethodError: undefined method `find_by_id' for Book:Class
13:26:49 worker.2 | 6-task-queueing/lib/active_job/queue_adapters/pub_sub_queue_adapter.rb:40:in `block in run_worker!'
13:26:49 worker.2 | 6-task-queueing/vendor/bundle/ruby/2.2.0/gems/gcloud-0.4.0/lib/gcloud/pubsub/subscription.rb:376:in `block (2 levels) in listen'
13:26:49 worker.2 | 6-task-queueing/vendor/bundle/ruby/2.2.0/gems/gcloud-0.4.0/lib/gcloud/pubsub/subscription.rb:376:in `each'
13:26:49 worker.2 | 6-task-queueing/vendor/bundle/ruby/2.2.0/gems/gcloud-0.4.0/lib/gcloud/pubsub/subscription.rb:376:in `block in listen'
13:26:49 worker.2 | 6-task-queueing/vendor/bundle/ruby/2.2.0/gems/gcloud-0.4.0/lib/gcloud/pubsub/subscription.rb:373:in `loop'
13:26:49 worker.2 | 6-task-queueing/vendor/bundle/ruby/2.2.0/gems/gcloud-0.4.0/lib/gcloud/pubsub/subscription.rb:373:in `listen'
13:26:49 worker.2 | 6-task-queueing/lib/active_job/queue_adapters/pub_sub_queue_adapter.rb:36:in `run_worker!'
13:26:49 worker.2 | 6-task-queueing/lib/tasks/run_worker.rake:4:in `block in <top (required)>'
This is fixed by editing lib/active_job/queue_adapters/pub_sub_queue_adapter.rb
and changing find_by_id
to find
I try to make the deployed and I can not, I attached the error.
https://github.com/GoogleCloudPlatform/getting-started-ruby.git
The code in this file: https://github.com/GoogleCloudPlatform/getting-started-ruby/blob/master/2-cloud-datastore/app/models/book.rb
still uses the gcloud ruby gem. We have renamed our Google Cloud client library to be google-cloud
and we now also have individual modules for each API, i.e. we should be using google-cloud-datastore
in the bookshelf tutorial.
You can find the google-cloud-datastore folder within the google-cloud-ruby repo.
See current ActiveModel usage:
Unnecessary and overly complicated for the Getting Started with Datastore for the Bookshelf application
Currently this is using the gcloud gem and should be updated to use google-cloud-* gems
reposted from @bshaffer:
I receive the following error when running rake db:migate for the Using Cloud SQL portion of the bookshelf app:
Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:50:in `establish_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/tasks/mysql_database_tasks.rb:8:in `establish_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/tasks/mysql_database_tasks.rb:15:in `create'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:93:in `create'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:275:in `block in each_current_configuration'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:274:in `each'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:274:in `each_current_configuration'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:106:in `create_current'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/Library/Ruby/Gems/2.0.0/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
I removed Gemfile.lock and edited my Gemfile so that it contains
gem 'mysql2', '~> 0.3.18'
instead of
gem 'mysql2'
And that seemed to do the trick. I got this idea from this page, which states that mysql2 is currently incompatible with rails 4
The only thing holding me back from deploying a managed VM is finding a good way to have one set of settings for developing locally (with a local DB, etc.) and another set for when I'm deploying to production.
Sorry if there's an example somewhere and I missed it, but it seems like this tutorial would be a great place to offer some guidance for how to do this. Thanks and keep up the great working. This guide is exactly what I was looking for!
I'm just learning to use pub/sub but shouldn't the worker code in your example delete the subscription when the program terminates?
begin
subscription = topic.subscription "lookup_book_details"
topic.subscribe "lookup_book_details" unless subscription.exists?
subscription.listen autoack: true do |message|
Rails.logger.info "Book lookup request (#{message.data})"
book_id = message.data.to_i
book = Book.find_by_id book_id
LookupBookDetailsJob.perform_now book if book
end
ensure
subscription.delete unless subscription.nil?
end
If this subscription is automatically cleaned up, please ignore this. It didn't seem to be the case when I looked at the Cloud Console but as I said, I'm new to Pub/Sub.
I'm working through putting together the cloud storage project, and I've found a couple spots that are incorrect in the Readme version:
Open config/application.rb, edit the below line to replace bucket with the name of your bucket:
This implies that the config line is already in there, which it isn't. It'd be good to either put it in there. I stuck it into the Module section of the file, which seems to work.
The readme also mentions fog_credentials.example.yml
, but that doesn't exist. Does that refer to settings.yml
?
As a note, when I went back and did the instructions from https://cloud.google.com/ruby/getting-started/using-cloud-storage, things went great.
Dirs:
2-cloud-datastore
Hello;
For anyone reading this, thanks for the help in understanding how things work
I've deployed with the setup you're providing in your example in app.yaml. I keep having two running instances, showing higher resources than shat's specified in your example : g1-small (1 vCPU, 1.7 GB memory)
The app.yaml says the following :
resources:
cpu: .5
memory_gb: 1.3
disk_size_gb: 10
So I don't understand this 1.7GB memory running,and that why instances are running at the same time
Thanks a lot for your elightment !
The (1) works fine for me.
I'm trying to execute the (2) sample (Datastore) and this fails:
$ bundle install
$ rails server # webserver works fine, but when I get to any page I get...
If I need to pre-configure my Datastore access with some kind of credentials, I believe this should go in the README. From the error tyupe, looks like auth mechanism has changed lately.
Is this a bug or WAI? See attached errors (from backend and frontend):
Started GET "/" for 127.0.0.1 at 2017-04-08 13:36:48 +0200
Processing by BooksController#index as HTML
Completed 500 Internal Server Error in 1ms
RuntimeError (Could not load the default credentials. Browse to
https://developers.google.com/accounts/docs/application-default-credentials
for more information
):
app/models/book.rb:24:in dataset' app/models/book.rb:42:in
query'
app/controllers/books_controller.rb:20:in `index'
Rendered /home/riccardo/.rvm/gems/ruby-2.3.3/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_source.erb (2.3ms)
Rendered /home/riccardo/.rvm/gems/ruby-2.3.3/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.1ms)
Rendered /home/riccardo/.rvm/gems/ruby-2.3.3/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.5ms)
Rendered /home/riccardo/.rvm/gems/ruby-2.3.3/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (9.9ms)
RuntimeError in BooksController#index
Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information
Extracted source (around line #24):
# The dataset is used to create, read, update, and delete entity objects.
def self.dataset
@dataset ||= Google::Cloud::Datastore.new(
project: Rails.application.config.
database_configuration[Rails.env]["dataset_id"]
)
I'm trying to run a rails application on appengine and connecting to cloudsql. is there any plan to use KMS to manage secrets for appengine?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.