In this chapter, you will be guided through the process of deploying your application on Render.
Utilizing NeetoDeploy for Application Deployment
All candidates undergoing orientation at BigBinary are required to utilize NeetoDeploy for application deployment. To facilitate this process, kindly post a message in the designated orientation Slack channel, addressing the responsible individual overseeing the orientation, requesting the essential documentation for deploying the application on NeetoDeploy
Deploying using Render
First, sign up for a Render account if you haven’t already. Once you’ve completed the signup process, Render offers two primary options for deploying your application: Manual configuration or using a Blueprint.
Manual configuration
You can manually select the service you want to deploy, connect your GitHub account to Render, and link it to your Git repository. Then, you can configure your application directly through the Render dashboard.
Using a Blueprint
Another way to deploy your application is by writing a Blueprint. A Blueprint acts as a single source of truth for configuring an interconnected set of services, databases, and environment groups. To use this method, you need to add a render.yaml
file to your codebase, specifying the services and configurations required for your application.
We will be writing a Blueprint for the application. The render.yaml
file, which serves as the Blueprint, is the central configuration file for deploying your application and its dependencies. To begin, create a render.yaml
file in the root directory of your repository and add the following configuration:
To configure your web application for deployment, in the services section of your render.yaml
file, set the type
to web to designate it as a web service responsible for handling HTTP requests. You need to assign a unique identifier to your service using the name
field; for example, granite-oliver-smith. Specify the environment by setting runtime
to ruby. Point to your application's source code repository with the repo
field, providing the URL of your GitHub repository. Also specify the branch
to deploy. Opt for Render’s free deployment tier by setting the plan
to free.
Environment variables are defined in the envVars
section. These variables are crucial for configuring your application during deployment. The DATABASE_URL
connects the application to the database by retrieving the connection string from the database defined in the databases section. The RAILS_MASTER_KEY
provides with the encryption key needed for handling sensitive data like credentials.
You also need to define the buildCommand
to prepare your application for deployment and the startCommand
to initialize your application server. To do this, let’s add a build script and set it as the build command. First, create the build script file.
Then, add the following content to the bin/build_script
file:
In this script, we are installing the required gems and packages. Since Node is included in all native environments in Render, we can execute Node-related commands in our Ruby environment.
After the dependencies are installed, the script proceeds to precompile the application’s assets using the rails assets:precompile
task. This step generates optimized CSS, JavaScript, and other assets required for production. Next, the script sets up the database by running rake db:setup
, which creates the database if it's not already present and loads the schema. If there are any pending database migrations, they are applied using rake db:migrate
. Finally, the application server is restarted to ensure that all changes take effect, making the application ready to serve incoming requests.
Let's commit these changes:
Once you have committed the changes, you can visit the Render dashboard and go to the Blueprint section and create a new Blueprint instance. Once you click to create, you will be prompted to connect your repository.
Since the repository now contains the render.yaml
file, Render will automatically pick up the configurations from it and list the web service and database. You will then be prompted to add the RAILS_MASTER_KEY
.
Rails master key
When you create a new Rails app, a file called credentials.yml.enc
is added to the config directory. This file will be decrypted in a production environment using a key stored in RAILS_MASTER_KEY
environment variable. In development, your app will reference config/master.key
to decrypt the data correctly.
If you don't have the credentials.yml.enc
file in your app already, you can run a command to generate one.
This first checks if that file is present and generates a new one if not. A master.key
file is also created if not present. Do not commit the master.key file. Add it to your project's .gitignore
file if it is not already present.
You can now add the RAILS_MASTER_KEY
and deploy the Blueprint.
Note that Render's free tier supports only web services; configuring Sidekiq jobs requires a paid plan.