Skip to content

Instantly share code, notes, and snippets.

@ukazap
Forked from kyptin/steps.md
Created September 24, 2018 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ukazap/a3569ddaa181e51da777f1e859038c8a to your computer and use it in GitHub Desktop.
Save ukazap/a3569ddaa181e51da777f1e859038c8a to your computer and use it in GitHub Desktop.
Accessing a rails console in Google App Engine (flexible)

If you're running a Rails app in Google App Engine's flexible environment, it takes a bit of setup to get to a rails console attached to your deployed environment. I wanted to document the steps for my own reference and also as an aid to others.

  1. Open the Google App Engine -> instances section of the Google Cloud Platform (GCP) console.

  2. Select the "SSH" drop-down for a running instance. (Which instance? Both of my instances are in the same cluster, and both are running Rails, so it didn't matter for me. YMMV.) You have a choice about how to connect via ssh.

    1. Choose "Open in browser window" to open a web-based SSH session, which is convenient but potentially awkward.

    2. Choose "View gcloud command" to view and copy a gcloud command that you can use from a terminal, which lets you use your favorite terminal app but may require the extra steps of installing the gcloud command and authenticating the gcloud command with GCP.

  3. When you're in the SSH session of your choice, run sudo docker ps to see what docker containers are presently running.

  4. Identify the container of your app. Here's what my output looked like (abbreviated for easier reading). My app's container was the first one.

    jeff@aef-default-425eaf...hvj:~$ sudo docker ps
    CONTAINER ID   IMAGE                                       COMMAND                  NAMES
    38e......552   us.gcr.io/my-project/appengine/default...   "/bin/sh -c 'exec bun"   gaeapp
    8c0......0ab   gcr.io/google_appengine/cloud-sql-proxy     "/cloud_sql_proxy -di"   focused_lalande
    855......f92   gcr.io/google_appengine/api-proxy           "/proxy"                 api
    7ce......0ce   gcr.io/google_appengine/nginx-proxy         "/var/lib/nginx/bin/s"   nginx_proxy
    25f......bb8   gcr.io/google_appengine/fluentd-logger      "/opt/google-fluentd/"   fluentd_logger
    
  5. Note the container name of your app (gaeapp in my case), and run container_exec <container_name> bash.

  6. Add ruby and node to your environment: export PATH=$PATH:/rbenv/versions/2.3.4/bin:/rbenv/bin:/nodejs/bin

  7. cd /app to get to your application code.

  8. Add any necessary environment variables that your Rails application expects to your environment. For example: export DATABASE_URL='...'

    If you don't know what your app needs, you can view the full environment of the app with cat app.yaml.

  9. bin/rails console production to start a Rails console in the Rails production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment