Skip to content

Instantly share code, notes, and snippets.

@beccasaurus
Last active April 4, 2017 18:24
Show Gist options
  • Save beccasaurus/ab8d9c6d998f56cf31a6ac2030ec1fe3 to your computer and use it in GitHub Desktop.
Save beccasaurus/ab8d9c6d998f56cf31a6ac2030ec1fe3 to your computer and use it in GitHub Desktop.
App Engine Flex :: Ruby WEBrick Hello World :: cloud.google.com/ruby

Google Cloud Platform logo

App Engine Flex : Hello World!

Run a simple Ruby app! Just using WEBrick, no dependencies! Ruby standard library only!

Run locally

$ ruby app.rb

Deploy

Install the Google Cloud SDK.

See the Ruby App Engine Quickstart or Ruby Flex docs for more.

$ gcloud app deploy

Debug (SSH into container)

If you want to SSH into the container, just cuz...

Follow the documented steps for Debugging an Instance:

To SSH into a container, the following steps can all be run via gcloud... but, via the UI:

1. Go to the App Engine Instances page

GAE Instances page

2. Click SSH on any one of the instances

SSH button

3. Confirm

VM Debug Mode confirmation dialog

4. (Optional) Print out the containers with docker ps

docker ps to print out container names

5. Run BASH in the app container

Container Exec to start BASH and setup Ruby too

Notice that, by default, ruby is not in the PATH.

To see how this is confired by a running session, look at the base Dockerfile for the Ruby Runtime

Notice that we use rbenv and (1) setup RBENV_ROOT (2) add the rbenv bin and shims to PATH

Once that's done, you can use Ruby as usual!

See DEFAULT_RUBY_VERSION in the Dockerfile for the current default version used by the container. If your application has a .ruby-version file, that will be the version used. If you run your Ruby commands from your application directory /app then .ruby-version will be automatically used to choose your Ruby version appropriately.

require "webrick"
server = WEBrick::HTTPServer.new Port: ENV["PORT"]
server.mount_proc("/") {|req,res| res.body = "Hi there!" }
server.start
env: flex
runtime: ruby
entrypoint: ruby app.rb
@quartzmo
Copy link

quartzmo commented Apr 4, 2017

Thanks @remi, these instructions worked perfectly and the environment allowed me to run acceptance tests for google-cloud-ruby! Much appreciated!

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