Create a Rails Application
INFO
This guide covers how to deploy a Ruby on Rails application with Deploio. It assumes you have a basic understanding of Ruby on Rails and Git.
Prerequisites
- This quick start guide assumes you have installed
nctlon your laptop. If not, please go through the instructions here. - You should also have an organization and project created, where you will create the application. If you haven't done this yet, please follow the instructions here.
- A locally running version of Ruby, Rubygems, Bundler, and Rails
Use an Existing Rails Application or Create a New One
In case you don't have a Rails application yet, you can create one using the Rails CLI. We recommend following the official Rails guide to create a new Rails application. We also have a basic Rails app in our examples repository, which you can also choose as a starting point.
WARNING
Right now, Deploio does not support SQLite databases. You will need to use PostgreSQL or MySQL if you wish to persist data. This can be configured by passing the --database flag to the rails new command with either postgresql or mysql.
Add the x86_64-linux and ruby platforms to your Gemfile, to ensure that the correct gems are installed on the platform:
cd myapp
bundle lock --add-platform x86_64-linux --add-platform rubyUse Git to Store Your Application
Deploio requires your application to be available online in a Git repository, so that it can be cloned and deployed by the platform. You can use any Git repository hosting service, such as GitHub, GitLab, or Bitbucket. We describe the process of setting up a Git repository here. For demonstration purposes, we will use our sample Rails application hosted on GitHub.
INFO
This example presumes that you are using a public repository. Should you need to set up access to a private repository, you will need to create an SSH key for security. See more details here.
Create a Deploio Application
At Renuo, we use the following naming convention for new projects:
| Example value | |
|---|---|
| project name | gifcoins2 |
| staging app name | develop |
| production app name | main |
Each project contains two apps, one for staging and one for production. For example, the staging app is created with nctl create app develop --project=gifcoins2 and accessed via nctl exec app develop --project=gifcoins2.
WARNING
The app name you choose cannot be changed later.
INFO
The following app creation command requires the Rails CLI to generate SECRET_KEY_BASE. If you don't have it, any long random string will do (127+ chars), e.g. openssl rand -hex 64 or head -c 64 /dev/urandom | xxd -p -c 0.
Replace MY_RAILS_APP_NAME with your chosen app name and run:
nctl create app MY_RAILS_APP_NAME \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=ruby/rails-basic \
--env="SECRET_KEY_BASE=$(rails secret)"You can pass multiple environment variables by separating them with ;. Run nctl create app --help to see all available options.
When you create an application, the Git repository is cloned and Deploio will attempt to detect the application type and select the appropriate buildpack. In this case, the Heroku Ruby buildpack will be used. The buildpack will then attempt to detect the desired ruby version from the Gemfile.lock in the app source. The full behavior of the buildpack is documented here.
INFO
If your application requires Node.js either for the build or runtime, a package.json file must be present at the root of the repository for the Node.js runtime to be installed.
Next Steps
The app should be running by now. If your application requires a database, it will likely fail at this point because the database connection is not yet configured. You can check your app configuration with:
nctl get app MY_RAILS_APP_NAME --project=MY_PROJECT_NAME -o yamlYou can also open an interactive shell to inspect or debug:
nctl exec app MY_RAILS_APP_NAME --project=MY_PROJECT_NAMEThe next step is to set up a database for your application.