Step-by-Step Guide to Deploying Rails 8 with Kamal and GitHub Actions

Posted on

If you're looking to automate the deployment of your Rails 8 app using Kamal and GitHub Actions, this guide will walk you through the process, from creating the necessary files to setting up secrets and configuring your Docker registry.

1. Set Up Your GitHub Actions Workflow
First, create a GitHub Actions workflow file inside your .github/workflows folder. Name the file something like deploy.yml.

Here's a basic configuration that runs after the CI workflow completes successfully:

name: Deploy to Production

on:
  workflow_run:
    workflows: ["CI"]
    types:
      - completed

jobs:
  deploy:
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    runs-on: ubuntu-latest
    container:
      image: ghcr.io/basecamp/kamal:latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Set up SSH
        run: |
          mkdir -p ~/.ssh
          echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa

      - name: Disable Git safe directory check
        run: git config --global --add safe.directory '*'

      - name: Deploy Application
        env:
          KAMAL_REGISTRY_PASSWORD: ${{ secrets.KAMAL_REGISTRY_PASSWORD }}
          RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
        run: |
          kamal deploy


This workflow checks out the code, sets up SSH, and then runs the kamal deploy command.

2. Generate an SSH Key for GitHub
You’ll need to create an SSH key for secure communication between GitHub and your server:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Follow the prompts to save the key. Once generated, add the public key to your server’s ~/.ssh/authorized_keys file, and add the private key to your GitHub repository as a secret (SSH_PRIVATE_KEY).

3. Add Secrets to GitHub
You'll need to add several secrets to GitHub:

  1. SSH_PRIVATE_KEY: The private key generated in the previous step.
  2. KAMAL_REGISTRY_PASSWORD: Your Docker Hub password (assuming Docker Hub is your registry).
  3. RAILS_MASTER_KEY: The master key for your Rails application (found in config/master.key).

To add these secrets:

  • Go to your GitHub repository.
  • Click Settings > Secrets and variables > Actions.
  • Click New repository secret and add each key-value pair.

If you’re not using Docker Hub as your registry, check the Kamal docs on Docker registry configuration to adapt the workflow.

4. Update .kamal/secrets File
Make sure your .kamal/secrets file references the GitHub secrets:

KAMAL_REGISTRY_PASSWORD=$KAMAL_REGISTRY_PASSWORD
RAILS_MASTER_KEY=$RAILS_MASTER_KEY

5. Push!

For a full list of Rails 8 changes, refer to the Rails 8 Release Notes.

Refurbished Steelcase Leap Review Coming Soon – A Herman Miller Alternative

Posted on

I finally found a new office chair for home. I've used a Herman Miller Aeron Classic at the office for years and never had tailbone or lower back pain with it.

At home, it’s a different story. My twenty-year-old leather chair has a worn-out pad and no lumbar support. After long coding sessions, my lower back and tailbone start to ache.

I didn’t want to splurge on a Herman Miller Embody or Aeron Remastered for home use. Instead, I took a chance on a refurbished Steelcase Leap from BTOD.com. I found BTOD after watching a few of their YouTube videos. It didn’t hurt that they’re based in Wisconsin.

The total cost was $501.59, and the chair should arrive within a week. I’ll update this post with my thoughts after I’ve used it for a while.

Rails 8 Beta Bug: Fixing authenticated? Helper with allow_unauthenticated_access

Posted on

In Rails 8 Beta 1, I ran into a bug with the new built-in authentication package. The authenticated? helper method would return false on routes using the allow_unauthenticated_access method to bypass authentication. My use case was to show an edit button only if I was authenticated. There are plenty of scenarios where you'd want this functionality.

Thankfully, this issue has already been addressed and merged ("Fix helper behavior on controller that don't require authentication #53175"). It will be resolved in the next release, but if you want to fix it now, check the issue linked above for the details.

How Kevin Rose Uses AI to Retain Book Knowledge – A Strategy for Customer Service

Posted on

Kevin Rose shared a unique approach to retaining book knowledge in his post, "Creating Custom GPTs from World-Class Authors to Build an AI Negotiation Expert." He struggled with consuming books but not applying what he learned. His old method involved listening to audiobooks, buying hard copies, and taking notes.

I’ve tried that too but never stuck with it.

Now, he's training a custom AI on the book’s PDF and having it answer questions based on the text.

That’s an idea worth exploring. I’m thinking of using a similar method to build a knowledge base for my customer service team at PrintsWell.

Relaunching My Blog with Rails 8, Kamal, and Hetzner

Posted on

I'm relaunching my blog with Rails 8, deploying via Kamal, and using Thruster for proxying. I'm also testing Hetzner as my web host. More updates soon.