Guide to Deploying a Rails App to Hatchbox
1️⃣ Prepare Your App Locally
- Make sure your Rails app runs locally without errors.
- Commit all code to GitHub (Hatchbox pulls from Git).
2️⃣ Create a Cluster in Hatchbox
-
Log in to Hatchbox.io.
-
Click New Cluster.
-
Fill in:
Page 1: Create New Cluster
- Name: Your cluster name (e.g.,
Uddhava Production). - Hosting Provider: AWS, DigitalOcean, Linode, etc.
- Region: Choose the region closest to your users (e.g.,
ap-south-1).
Page 2: Connect to Service Provider (Example: AWS)
- Name: Account name to recognize it.
- Access Key ID: Your AWS Access Key ID.
- Secret Access Key: Your AWS Secret Access Key.
- Is this a GovCloud account?: No.
Page 3: Choose Region
- Region: Choose the region closest to your users (e.g.,
ap-south-1).
- Name: Your cluster name (e.g.,
-
Save the cluster.
3️⃣ Create a VPC Setting in Hatchbox
- In Cluster tab → Click the cluster or New Server.
- If prompted, click Create and Configure VPC for me.
- Choose any subnet and set AZ to Let AWS choose for me.
- Save the cluster.
4️⃣ Create a Server in a Cluster in Hatchbox
- Name: Server name (e.g.,
uddhava-production-server). - Size: Choose server size (e.g.,
t4g.smallfor most apps). - Volume: Choose volume size (e.g.,
50GBfor most apps). - Role: Choose server role (e.g.,
Web Server,Background Worker,Cron Jobs,Database,Redis).
5️⃣ Create an App in Hatchbox
-
In App tab → Click New App.
-
Add:
- Cluster: Choose your cluster.
- Name: Your app name (e.g.,
uddhava-production).
6️⃣ Setting Up the App Repository in Hatchbox
-
In Current App tab (the one you created).
-
Add:
- Git Host: Connect to your host or select a pre-set host (e.g.,
Commutatus). - Repository: Your repository path (e.g.,
commutatus/uddhava). - Branch: Branch to deploy (e.g.,
main).
- Git Host: Connect to your host or select a pre-set host (e.g.,
-
Set Automatic Deploys.
7️⃣ Creating Database in Hatchbox (Unmanaged)
- Create a PostgreSQL instance in AWS RDS:
- Go to Databases tab in Current App → Click required Unmanaged Database.
- For PostgreSQL: Provide DB name (e.g., uddhava_production).
- For Redis: Just click create.
- The database will be created and connected to your app via Environment Variables.
8️⃣ Assign Cron Jobs in Hatchbox
-
Go to Cron Jobs tab in Current App → Click New Cron Job.
-
Add:
- Name: Cron job name (e.g.,
uddhava-production-cron). - Command: Cron job command (e.g.,
bundle exec wheneverize . && bundle exec whenever --update-crontab). - Schedule: Cron job schedule (e.g.,
*/5 * * * *).
- Name: Cron job name (e.g.,
9️⃣ Adding Environment Variables in Hatchbox
-
Go to Environment Variables tab in Current App → Click New Environment Variable.
-
Add:
- Name: Environment variable name (e.g.,
DATABASE_URL). - Value: Environment variable value (e.g.,
postgres://username:password@rds-endpoint:5432/uddhava_production).
- Name: Environment variable name (e.g.,
-
Click Save Changes after adding all variables.
🔟 Deploy the App to Hatchbox
-
In Hatchbox → App → Click Deploy.
-
Hatchbox will:
- Clone repo
- Install Ruby + Gems
- Precompile assets
- Run migrations
Note: If errors occur, check Process Logs in Hatchbox. Sidekiq and Rails server will be set up and started automatically.
1️⃣1️⃣ Domain & SSL
- In Hatchbox → App → Domains → Add your domain.
- Point DNS to your Hatchbox on Route53.
Bonus: Setting Up AWS RDS (Managed)
-
Go to Database tab in Current App → Click New Database.
- Follow screenshots (
Screenshot_1.png,Screenshot_2.png). - Choose the VPC selected in Hatchbox.
- If prompted for subnets, create one in any remaining AZ in the VPC.
- Follow screenshots (
-
Go to Environment Variables in your app:
DATABASE_URL=postgres://USERNAME:PASSWORD@RDS-ENDPOINT:5432/uddhava_productionSave.
SSH into Your Server
- In Hatchbox → App → Click SSH Keys → Add your SSH key.
- In the current app, go to Process and find the SSH command for the server.
- Open Terminal and paste the SSH command.
References
Video Links:
✅ After this, your app should be live with:
- Main App Server handling requests.
- Worker Server running background jobs.
- AWS RDS as the database.
- Managed by Hatchbox for deployments.