Deploy on Hatchbox
Deploy a Rails app that mounts cm-admin to Hatchbox, from local checks to a running app with a database, cron jobs and SSL.
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.
10. 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.
11. 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.