2

Optional Background: Hello, I’m quite new to the services on google cloud..well, and web development in general (Let’s say my training thus far is less than 60 hours on the rails framework and I’m not used to MVC or using databases at all. “Good luck kid”, I know.) My task is to deploy a mostly-done rails app that runs on Heroku to Google app engine. The app “builds” (after using gcloud app deploy), but it won’t connect to any database. Some of the files for doing that that I think should be there are missing. Namely, the config/database.yml file.

I thought it would make sense to just learn with a tutorial how you even connect a database on Google to an already existing rails app. I know rails generally just sets you up with a sqllite system automatically. But how do I write my own database.yml file to work on google app engine? And later on, how do I import all the information from our prior database...questions questions

Question Starts Here So, I started following this tutorial on the google cloud shell:

Pg 1: https://cloud.google.com/ruby/getting-started/tutorial-app I started here.

Pg 2: https://cloud.google.com/ruby/getting-started/using-structured-data Got here and decided on postgresql as my choice

Pg 3: https://cloud.google.com/ruby/getting-started/deploy-postgres and ran into an error where it tells me to call $: rake db:migrate

Here is the error message:

:~/projects/Bookshelfapp/getting-started-ruby/2-postgresql$ rake db:create could not connect to server: Connection timed out
Is the server running on host "35.193.145.252" and accepting TCP/IP connections on port 5432?”

Am I not connected to the database at all? I'm looking at my database.yml file.

Here is the format I was supposed to follow:

postgresql_settings: &postgresql_settings
adapter: postgresql
encoding: unicode
pool: 5
username: postgres
password: secret123
host: 173.194.230.44
database: bookshelf

Here is how I went for it: My database.yml file:

postgresql_settings: &postgresql_settings
 adapter: postgresql
 encoding: unicode
 pool: 5
 username: postgres
 password: [my password is here]
 host: 35.193.145.252
 database: bookshelf
development:
   <<: *postgresql_settings
production:
   <<: *postgresql_settings
test:
 adapter: sqlite3
 pool: 5
 timeout: 5000
 database: db/test.sqlite3

Here is where I found the username and password:

username and password page

And I picked this IP address for the host: IP address page

What am I doing wrong with my life? I haven’t assigned a static IP address to the VM, but I don’t really understand why I would do that.

Could anyone offer any suggestions of what to check for. I spent quite a bit of time going back into early steps and trying to find where I might have misstepped, but my inexperience isn’t offering too many solutions. Even routes to understand this problem better conceptually might help. I am not sure if I don’t know how to use some tool or if I have a big concept missing.I have never done anything like this before.

This issue seems similar to the following past questions, but I'm not sure how much they match up with mine:

question 1

question 2

question 3

question 4

moveson
  • 5,103
  • 1
  • 15
  • 32
Ariah
  • 21
  • 3

1 Answers1

0

If that error appears, it means the virtual machine where the database is hosted is not being accessed correctly.

The IP address you need for connecting to the database is indicated when you use SSH to access the PostgreSQL instance you created with the launcher (check the IP address that appears under the Bitnami logo).

You also have to open the server port for remote access, in this case 5432, which can be done with this command:

sudo ufw allow 5432

If you don't have ufw installed in the virtual machine, use apt-get to get it.

After that, restart the server to apply the changes, just in case:

sudo /opt/bitnami/ctlscript.sh restart

Besides, the firewall rule indicated in the tutorial is not well prepared, you have to remove the target-tags part. That way, you will be able to connect to the PostgreSQL database and continue the tutorial.

Rodrigo C.
  • 1,114
  • 7
  • 13