3 min read

How to deploy an existing Rails app for free

You want to know how to host your app for free, but you don’t want to spend half a day figuring out how to deploy it. Or you tried self-hosting with Kamal but couldn’t make it.

If you are starting an app from scratch, you can follow the previous tutorials for a step-by-step process:

In most cases, you already have an application. This guide shows the full process of deploying a real-world Rails app (toronto-ruby.com) to Miren Club.

About Miren Club

Miren Club is a shared cluster where you can deploy something without setting up your own server. It’s great for demos, hack projects, or to get started. Later on, if you’d rather run Miren on your own machine, you can follow the guide on How to self-host your Ruby apps.

Pre-requisites

  1. Request access to the Miren Club.
  2. Get the miren CLI
  3. Install rv by running the following command:

curl -LsSf https://rv.dev/install | sh

Authentication

Once you have access, connect to Miren Club:

$ miren login

✓ Authentication successful!

…

$ miren cluster add

Select a cluster to bind:

NAME ORGANIZATION ADDRESS

▸ club Miren Club 34.27.122.56:8443 (+6)

Prepare the app

Download the code:

$ git clone git@github.com:toronto-ruby/toronto-ruby.com.git

Move to the project’s folder:

$ cd toronto-ruby.com

Copy the default configuration files

$ cp ./config/database.yml.production ./config/database.yml

$ cp ./config/storage.yml.production ./config/storage.yml

Create a .miren/app.toml configuration file with the following content:

name = 'toronto-ruby.com'
post_import = ''
env = []
include = ['config/database.yml', 'config/storage.yml']

[addons.miren-postgresql]
variant = "small"

Install ruby and required dependencies:

$ rv clean-install

Use the following command to add the application credentials in an encrypted file:

$ rv run rails credentials:edit --environment production

Your editor will open the file, then add the following content:

auth:
  user: YOU_ADMIN_USER
  password: YOUR_ADMIN_PASSWORD
  
admins: []

After you save the file and close it, it will create 2 files:

  • production.yml.enc - You can commit and deploy this file.
  • production.key - Keep safe, keep it secret.

Note: .gitignore will also include the new production.key so the Miren server won’t push it to the server.

Deployment

Make an initial deployment to create the app in the cluster:

$ miren deploy

✓ Deploying: toronto-ruby.com → club
✓ Upload artifacts (0.4s) - 698 B at 4.3 KB/s, reused 162/163 files (saved 969.2 KB, ~3m 43s)
✓ Build & push image (28.9s) - 17 steps completed
✓ Version w1o deployed — scaled to zero, no instance running right now (0.2s)

No routes configured for this app.
To set a hostname, try: miren route set toronto-ruby-com.cluster-jwomf2l0tn8z.org-miren-club-djwhunl15a5n.miren.systems 
toronto-ruby.com
To make it the default route: miren route set-default toronto-ruby.com

Configure a route for the app:

$ miren route set toronto-ruby-com.cluster-jwomf2l0tn8z.org-miren-club-djwhunl15a5n.miren.systems toronto-ruby.com

Route set: toronto-ruby-com.cluster-jwomf2l0tn8z.org-miren-club-djwhunl15a5n.miren.systems → toronto-ruby.com

Set the RAILS_MASTER_KEY so the app can read the encrypted credentials file. The value is the content of /config/credentials/production.key

$ miren env set -s RAILS_MASTER_KEY

setting RAILS_MASTER_KEY (sensitive)…
Setting env vars on 
toronto-ruby.com — new version: toronto-ruby.com-vCd3tqZd1pZAP71wwAG68a
✓ Version toronto-ruby.com-vCd3tqZd1pZAP71wwAG68a deployed — scaled to zero, no instance running right now (0.1s)

Finally, load the database schema:

$ miren app run -- bin/rails db:schema:load

The app should be working now, but it won’t list any events. If you want to add some dummy data, you can run this command:

$ miren app run -- bin/rails db:seed

You can view the end result here: https://toronto-ruby-com.cluster-jwomf2l0tn8z.org-miren-club-djwhunl15a5n.miren.systems

Before you go

Thanks for reaching this far! If you find this guide helpful, please share it with your friends and enemies alike.

I would love to know if you’re able to deploy your apps using this guide. If you have any issues, please reply with your feedback or comments.

If you haven’t already, take a look at the other articles and the #deployment tag in the Ruby Users Forum.

Happy deploying!