Overview of Rails Application

Code Recognition

Rails 2.x

When the Gemfile.lock file contains rails gem, and the version is greater than or equal to 2.0.0 and less than 3.0.0, the application will be recognized as a Rails 2.x application, which can be seen during deployment

——> Ruby/Rails app detected

Rails 3.x

When the Gemfile.lock file contains railties gem, and the version is greater than or equal to 3.0.0 and less than 4.0.0, the application will be recognized as a Rails 3.x application, and you can see during deployment:

——> Ruby/Rails app detected

Rails 4.x

When the Gemfile.lock file contains railties gem, and the version is greater than or equal to 4.0.0.beta is less than 5.0.0, the application will be recognized as a Rails 4.x application, which can be seen during deployment

——> Ruby/Rails app detected

Database Configuration

Currently, Gridworkz supports MySQL database service, and users can use it by creating Ruby application associated with MySQL service. Refer to Application Console-Dependency.

Use phpmyadmin to Create Database myapp

Modify the Database Configuration

Take Rails 4.x as an example, modify config/database.yml

production:
  adapter: mysql2
  encoding: utf8
  host: <%= ENV['MYSQL_HOST'] %>
  port: <%= ENV['MYSQL_PORT'] %>
  database: myapp
  username: <%= ENV['MYSQL_USER'] %>
  password: <%= ENV['MYSQL_PASSWORD'] %>
  pool: 5

The myapp database configured by database must be created in advance

Run

All Rails applications are set to the following environment variables when the platform is running:

RAILS_ENV="production"
RACK_ENV="production"

Rails 2.x Default Startup Command

web: bundle exec ruby ​​script/server -p $PORT

Rails 3.x Default Startup Command

web: bundle exec rails server -p $PORT

Rails 4.x Default Startup Command

web: bundle exec bin/rails server -p $PORT -e $RAILS_ENV

Although there is a default web server startup command for each version of Rails, we strongly recommend using Puma as a web server in a production environment.

Perform Rake Task

Rake tasks can be executed by formulating a Procfile file format. For example, the following startup command will execute the db:migrate task and start Rails:

web: bundle exec rake db:migrate && bundle exec rails s -b 127.0.0.1 -p $PORT

Build

Rails 3.x

The system will execute the assets:precompile task in the final stage to compile static files to the public/assets directory.

Users can also choose to execute RAILS_ENV=production bundle exec rake assets:precompile locally to compile static files and push the compiled structure to version control, but this is not recommended. If the system detects public/assets/manifest.yml File, it will be considered that you have compiled a static file locally, and will no longer execute the compilation.

To prevent initializing the application and connecting to the database when compiling static files, it is recommended to add configuration in the config/application.rb file:

config.assets.initialize_on_precompile = false

Tip: In Rails 4.x, the config.assets.initialize_on_precompile option has been removed and no configuration is required.

Plugin Injection

rails_stdout_logging: Make sure Rails logs are sent to STDOUT rails3_serve_static_assets: Let Rails 3 support hosting static files

If the application Gemfile contains rails_12factor, the system will no longer perform plugin injection.

Rails 4.x

Similar to Rails 3.x, the system will also execute the assets:precompile task for the application, but the condition is: the application defines the assets:precompile task And there is no public/assets/manifest-*.json file. If this task fails to execute, the deployment will also fail.

Similarly, users can also compile static files locally and push them to version control. If the system detects public/assets/manifest-*.json files, It will be considered that the user has compiled a static file and will no longer perform the compilation (not recommended).

Plugin Injection

Rails 4 no longer supports the plug-in mechanism, so you need to use another way to achieve a similar effect to the previous plug-in injection: use

rails_12factor gem. This operation needs to be performed by the user. If the system does not detect the rails_12factor gem during deployment, a warning will be issued.

Add the following content to Gemfile, then execute bundle install:

gem'rails_12factor', group: :production

By default, Rails does not support hosting static files, rails_12factor includes rails_serve_static_assets, This gem can give Rails this ability, just add configuration:

config.serve_static_assets = true