Appearance
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
Setup Rails app
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:
shell
cd myapp
bundle lock --add-platform x86_64-linux --add-platform rubySetup Git
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 Deploio app
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:
WARNING
The app name you choose cannot be changed later.
bash
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 Paketo Ruby buildpack will be used. The buildpack will then attempt to detect the desired ruby version from the Gemfile.lock in the app source.
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. You can check the status as follows.
bash
nctl get app MY_RAILS_APP_NAME --project=MY_PROJECT_NAMEThe output includes a HOSTS column with your app's default URL (ending in .deploio.app). You can verify the app is responding by opening that URL in your browser or by running:
bash
curl -i https://MY_RAILS_APP_NAME-xxxxxx.deploio.appIf 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:
bash
nctl get app MY_RAILS_APP_NAME --project=MY_PROJECT_NAME -o yamlYou can also open an interactive shell to inspect or debug:
bash
nctl exec app MY_RAILS_APP_NAME --project=MY_PROJECT_NAMEThe next step is to set up a database for your application.