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
- Install rbenv.
- Install latest Ruby through rbenv:
rbenv install 2.2.3
- Create .ruby-version file in the repository root. Set the contents of the file to be
2.2.3
and save the file. - Install Rails:
gem install rails
- 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.
-
Add
gem ‘devise’
to the main section of the Gemfile. -
Run
bundle install
to pull down the gem dependency. -
Run
rails generate devise:install
to install the devise initializer configuration into the Rails application. -
Run
rails generate devise User
to configure the User model for management under devise. -
Add the following line to the config/environments/development.rb file:
config.action_mailer.default_url_options = { host: ‘localhost’, port: 3000 }
-
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.
-
Add the following line to the Gemfile:
gem ‘puma’
-
Run
bundle install
to install the gem into your Rails app environment. -
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
-
Start your Rails server and ensure that Puma starts up:
rails server
Other notables
- Using Materialize Sass for Rails Asset Pipeline. The Materialize front-end framework can be found here.