Skip to content

Deploying a Lobsters App

Introduction

Lobsters is an open-source link aggregation and discussion platform written in Ruby on Rails. Deploying Lobsters with a Dockerfile on Klutch.sh gives you reproducible builds, managed secrets, and persistent storage for uploaded assets—all configured from klutch.sh/app. This guide covers installation, repository prep, a production-ready Dockerfile, deployment steps, Nixpacks overrides, sample code snippets, and production tips.


Prerequisites

  • A Klutch.sh account (create one)
  • A GitHub repository containing your Lobsters code (GitHub is the only supported git source)
  • Docker familiarity and Ruby/Rails knowledge
  • PostgreSQL credentials (required) and Redis (optional for cache/queues)
  • Storage for uploads and logs

For onboarding, see the Quick Start.


Architecture and ports

  • Lobsters serves HTTP; set the internal container port to 3000.
  • PostgreSQL and Redis should run as separate Klutch.sh TCP apps, exposed on port 8000 and connected internally on 5432 and 6379.
  • Persistent storage is recommended for uploads and logs if you keep them on disk.

Repository layout

lobsters/
├── app/ # Rails app code
├── public/ # Static assets
├── config/ # Rails configuration
├── Dockerfile # Must be at repo root for auto-detection
├── Gemfile
├── Gemfile.lock
└── .env.example # Template only; no secrets

Keep secrets out of Git; store them in Klutch.sh environment variables.


Installation (local) and starter commands

Install dependencies and run locally before pushing to GitHub:

Terminal window
bundle install
bundle exec rails db:setup
bundle exec rails assets:precompile
bundle exec rails server -b 0.0.0.0 -p 3000

Optional helper start.sh for portability and Nixpacks fallback:

#!/usr/bin/env bash
set -euo pipefail
bundle exec rails db:migrate
exec bundle exec rails server -b 0.0.0.0 -p 3000

Make it executable with chmod +x start.sh.


Dockerfile for Lobsters (production-ready)

Place this Dockerfile at the repo root; Klutch.sh auto-detects it (no Docker selection in the UI):

FROM ruby:3.2-slim
WORKDIR /app
RUN apt-get update && apt-get install -y build-essential libpq-dev nodejs yarn git && \
rm -rf /var/lib/apt/lists/*
COPY Gemfile Gemfile.lock ./
RUN bundle config set without 'development test' && bundle install --jobs 4 --retry 3
COPY . .
RUN bundle exec rails assets:precompile
ENV PORT=3000 RAILS_ENV=production
EXPOSE 3000
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0", "-p", "3000"]

Notes:

  • Add any system packages your app requires (e.g., imagemagick for image processing).
  • For Nginx + Puma setups, adjust the CMD and include the web server config accordingly.

Environment variables (Klutch.sh)

Set these in the Klutch.sh app settings (Secrets tab) before deploying:

  • PORT=3000
  • RAILS_ENV=production
  • DATABASE_URL=postgres://<user>:<password>@<host>:<port>/<db>
  • REDIS_URL=redis://<user>:<password>@<host>:<port> (if using Redis)
  • SECRET_KEY_BASE=<secure-secret>
  • HOSTNAME=example-app.klutch.sh

If you deploy without the Dockerfile and need Nixpacks overrides:

  • NIXPACKS_BUILD_CMD=bundle install --without development test && bundle exec rails assets:precompile
  • NIXPACKS_START_CMD=bundle exec rails server -b 0.0.0.0 -p 3000
  • NIXPACKS_RUBY_VERSION=3.2

These keep Lobsters compatible with Nixpacks defaults when a Dockerfile is absent.


Attach persistent volumes

In Klutch.sh storage settings, add mount paths and sizes (no names required):

  • /app/public/system — for uploaded files.
  • /app/log — optional if you persist logs locally.

Ensure these paths are writable inside the container.


Deploy Lobsters on Klutch.sh (Dockerfile workflow)

  1. Push your repository (with the Dockerfile at the root) to GitHub.
  2. Open klutch.sh/app, create a project, and add an app.
  1. Connect the GitHub repository; Klutch.sh automatically detects the Dockerfile.
  2. Choose HTTP traffic for Lobsters.
  3. Set the internal port to 3000.
  4. Add the environment variables above (DB/Redis URLs, secret key, hostname, and any NIXPACKS_* overrides if you temporarily deploy without the Dockerfile).
  5. Attach persistent volumes for /app/public/system (and /app/log if used), selecting sizes that fit your uploads and logging needs.
  6. Deploy. Your Lobsters instance will be reachable at https://example-app.klutch.sh; attach a custom domain if desired.

Sample API usage

Fetch the front page JSON feed (if enabled):

Terminal window
curl -X GET "https://example-app.klutch.sh/hottest.json"

Health checks and production tips

  • Add a reverse proxy probe to / or a lightweight status route.
  • Enforce HTTPS at the edge; forward HTTP to port 3000 internally.
  • Keep image and dependency versions pinned; upgrade intentionally with DB backups.
  • Monitor disk usage on /app/public/system and resize volumes before they fill.
  • Back up PostgreSQL and uploaded files regularly; do not rely on container filesystems for durability.

Lobsters on Klutch.sh combines reproducible Docker builds with managed secrets, persistent storage for uploads, and flexible HTTP/TCP routing. With the Dockerfile at the repo root and port 3000 configured, you can run a reliable community link aggregator without extra YAML or workflow overhead.