Skip to main content

Guide to Deploying a Rails App to Hatchbox


1️⃣ Prepare Your App Locally

  1. Make sure your Rails app runs locally without errors.
  2. Commit all code to GitHub (Hatchbox pulls from Git).

2️⃣ Create a Cluster in Hatchbox

  1. Log in to Hatchbox.io.

  2. Click New Cluster.

  3. 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).
  4. Save the cluster.


3️⃣ Create a VPC Setting in Hatchbox

  1. In Cluster tab → Click the cluster or New Server.
  2. If prompted, click Create and Configure VPC for me.
  3. Choose any subnet and set AZ to Let AWS choose for me.
  4. Save the cluster.

4️⃣ Create a Server in a Cluster in Hatchbox

  1. Name: Server name (e.g., uddhava-production-server).
  2. Size: Choose server size (e.g., t4g.small for most apps).
  3. Volume: Choose volume size (e.g., 50GB for most apps).
  4. Role: Choose server role (e.g., Web Server, Background Worker, Cron Jobs, Database, Redis).

5️⃣ Create an App in Hatchbox

  1. In App tab → Click New App.

  2. Add:

    • Cluster: Choose your cluster.
    • Name: Your app name (e.g., uddhava-production).

6️⃣ Setting Up the App Repository in Hatchbox

  1. In Current App tab (the one you created).

  2. 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).
  3. Set Automatic Deploys.


7️⃣ Creating Database in Hatchbox (Unmanaged)

  1. 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

  1. Go to Cron Jobs tab in Current App → Click New Cron Job.

  2. 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 * * * *).

9️⃣ Adding Environment Variables in Hatchbox

  1. Go to Environment Variables tab in Current App → Click New Environment Variable.

  2. Add:

    • Name: Environment variable name (e.g., DATABASE_URL).
    • Value: Environment variable value (e.g., postgres://username:password@rds-endpoint:5432/uddhava_production).
  3. Click Save Changes after adding all variables.


🔟 Deploy the App to Hatchbox

  1. In Hatchbox → App → Click Deploy.

  2. 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

  1. In Hatchbox → App → Domains → Add your domain.
  2. Point DNS to your Hatchbox on Route53.

Bonus: Setting Up AWS RDS (Managed)

  1. 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.
  2. Go to Environment Variables in your app:

    DATABASE_URL=postgres://USERNAME:PASSWORD@RDS-ENDPOINT:5432/uddhava_production

    Save.


SSH into Your Server

  1. In Hatchbox → App → Click SSH Keys → Add your SSH key.
  2. In the current app, go to Process and find the SSH command for the server.
  3. 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.