Goal
This guide shows how to deploy a toy Ruby on Rails 5 application on Platform.sh running on Sqlite (please do not use Sqlite in production, ever).
In a later post I’ll show how to deploy a robust, production-ready Rails with Postgres and Redis.
Assumptions
- An empty Platform.sh project - more info on creating a project here
- An SSH key loaded in an SSH agent and configured in the Platform.sh dashboard
- The Platform.sh CLI installed
- Some supported version of Ruby and the Rails gem installed. You can follow this excellent guide to get both installed. Your best experience would be to use the same version of Ruby you will be running on the server (for example 2.6).
Steps
1. Create a new Rails application using the CLI
$ rails new rails-platformsh
$ cd rails-platformsh
2. Configure the application for Platform.sh
Set the platform
Git remote.
$ platform project:set-remote <project id>
Update the Ruby version directive in the Gemfile not to care about patch level, because locking patch-level is evil.
# rails-platformsh/Gemfile
ruby '~> 2.6.0'
Then update the Gemfile.lock
$ bundle update
3. Add the Platform.sh configuration files
Create the .platform.app.yaml
application configuration file.
$ touch .platform.app.yaml
Add a basic Rails application configuration to the file.
# rails-platformsh/.platform.app.yaml
name: "ruby_example"
type: "ruby:2.6"
disk: 1024
hooks:
build: |
bundle install
rake assets:precompile
deploy: |
rails db:migrate
mounts:
"/log": "shared:files/log"
"/tmp": "shared:files/tmp"
"/db": "shared:files/db"
web:
commands:
start: 'rails server -p $PORT'
Create the .platform/services.yaml
services configuration and .platform/routes.yaml
router configuration files.
$ touch .platform/routes.yaml
$ touch .platform/services.yaml
Add basic routes configuration:
# rails-platformsh/.platform/routes.yaml
"https://{default}":
type: upstream
upstream: "ruby_example:http"
you can leave .platform/services.yaml
empty for the moment. Later if you would like a Postgres or a MySQL… this is where you will put it.
4. Deploy the application to Platform.sh
Commit everything to the repository:
git add --all
git commit -m "Initial commit"
Push the working branch to the platform
remote:
git push platform master
Conclusion
The Rails gem can be used in conjunction with the Platform CLI to easily create and configure a Ruby on Rails application for deployment on Platform.sh.