cebartling / app-engine-ruby-spike

A simple Ruby on Rails spike solution deployed to Google's App Engine Managed VMs infrastructure.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

app-engine-ruby-spike

A simple Ruby on Rails spike solution deployed to Google's App Engine Managed VMs infrastructure.

Prerequisites

  • MySQL for local development. You can install it directly or use it within a Docker container.
  • If using Docker on your local system, you will need to have VirtualBox and the Docker Toolbox installed. Looks like Docker Toolbox brings VirtualBox along, so Docker Toolbox is really the only install for Docker support.
  • Google Cloud SDK.

Creating the Ruby on Rails App Engine application

  1. Install rbenv.
  2. Install latest Ruby through rbenv: rbenv install 2.2.3
  3. Create .ruby-version file in the repository root. Set the contents of the file to be 2.2.3 and save the file.
  4. Install Rails: gem install rails
  5. Create a new Rails app in the current directory: rails new .

Configure the local MySQL database

We will be using Cloud SQL in the Google App Engine Managed VMs environment, which is basically a hosted MySQL system. Thus, we will need MySQL in our local development environment for development and testing purposes.

Using devise

Devise is a Ruby gem for flexible authentication solution for Rails based on Warden. It’s very popular with the Rails crowd and we’re going to use it in this spike solution application. Check out their documentation to see all the great support devise gives you for managing authentication and accounts.

  1. Add gem ‘devise’ to the main section of the Gemfile.

  2. Run bundle install to pull down the gem dependency.

  3. Run rails generate devise:install to install the devise initializer configuration into the Rails application.

  4. Run rails generate devise User to configure the User model for management under devise.

  5. Add the following line to the config/environments/development.rb file:

     config.action_mailer.default_url_options = { 
           host: ‘localhost’, 
           port: 3000 
     }
    
  6. Migrate the database to get the new users table created in the database: bundle exec rake db:migrate

Using the puma web server

Puma is a simple, fast, threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications.

  1. Add the following line to the Gemfile: gem ‘puma’

  2. Run bundle install to install the gem into your Rails app environment.

  3. Create a new file, config/puma.rb, and paste the following source code into the new file and save the file:

     workers Integer(ENV.fetch(‘WEB_CONCURRENCY’, 1))
     threads Integer(ENV.fetch(‘MIN_THREADS’, 2)),
             Integer(ENV.fetch(‘MAX_THREADS’, 2))
    
     preload_app!
    
     rackup DefaultRackup
     port ENV.fetch(‘PORT’, 3000)
     environment ENV.fetch(‘RACK_ENV’, ‘development’)
    
     on_worker_boot do
          # Force reconnection for each worker
          ActiveRecord::Base.establish_connection
     end
    
  4. Start your Rails server and ensure that Puma starts up: rails server

Other notables

About

A simple Ruby on Rails spike solution deployed to Google's App Engine Managed VMs infrastructure.

License:MIT License


Languages

Language:Ruby 79.5%Language:HTML 10.1%Language:Shell 8.7%Language:JavaScript 1.4%Language:CSS 0.2%