Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ MIGRATE_ON_START=false
# ── Attachments ──────────────────────────────────────────────────────────────
# local: files on disk under STORAGE_LOCAL_DIR (default DATA_DIR/uploads)
# s3: any S3-compatible store (AWS S3, Cloudflare R2, Garage, SeaweedFS, MinIO)
# postgres: in the database itself, for small instances on hosts without a persistent disk
# (free tiers). Counts against the database size; keep MAX_UPLOAD_BYTES modest.
STORAGE_DRIVER=local
STORAGE_LOCAL_DIR=
S3_ENDPOINT=
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ jobs:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm --filter @reprodrop/e2e exec playwright install --with-deps chromium
# Ubuntu's package mirrors time out now and then; retry instead of failing the run.
- name: Install Chromium for Playwright
run: |
for attempt in 1 2 3; do
pnpm --filter @reprodrop/e2e exec playwright install --with-deps chromium && exit 0
echo "Attempt $attempt failed; retrying in 20 s"
sleep 20
done
exit 1
- run: pnpm --filter @reprodrop/e2e build
- run: pnpm --filter @reprodrop/e2e e2e
- uses: actions/upload-artifact@v4
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ jobs:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm --filter @reprodrop/site exec playwright install --with-deps chromium
# Ubuntu's package mirrors time out now and then; retry instead of failing the run.
- name: Install Chromium for Playwright
run: |
for attempt in 1 2 3; do
pnpm --filter @reprodrop/site exec playwright install --with-deps chromium && exit 0
echo "Attempt $attempt failed; retrying in 20 s"
sleep 20
done
exit 1
# Tested without analytics, so the tests can prove the page makes no third-party requests.
- run: pnpm --filter @reprodrop/site build
- run: pnpm --filter @reprodrop/site test:site
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ release process.

## [Unreleased]

### Added

- `STORAGE_DRIVER=postgres` keeps attachments in the database, for hosts without a persistent disk
such as free tiers that wipe the filesystem on restart.
- Free hosting on Render and Neon: a `render.yaml` blueprint and a guide
(`docs/self-hosting/render.md`). On Render, `APP_URL` defaults to the service's public address.

## [0.1.2] - 2026-12-01

### Highlights
Expand Down
8 changes: 5 additions & 3 deletions apps/api/src/create-context.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { createDatabase, type DatabaseHandle } from "@reprodrop/database";
import { createDatabase, type Database, type DatabaseHandle } from "@reprodrop/database";
import { HttpJiraClient, MockJira, type FetchLike } from "@reprodrop/jira";
import type { AppConfig } from "./config";
import type { AppContext } from "./context";
import { TokenCipher } from "./lib/crypto";
import { LocalStorage, type Storage } from "./storage";
import { PostgresStorage } from "./storage/postgres";
import { S3Storage } from "./storage/s3";

export interface ContextOverrides {
Expand All @@ -13,7 +14,8 @@ export interface ContextOverrides {
database?: DatabaseHandle;
}

export function createStorage(config: AppConfig): Storage {
export function createStorage(config: AppConfig, db: Database): Storage {
if (config.STORAGE_DRIVER === "postgres") return new PostgresStorage(db);
if (config.STORAGE_DRIVER === "s3") {
return new S3Storage({
bucket: config.S3_BUCKET!,
Expand All @@ -36,7 +38,7 @@ export function createContext(
const ctx: AppContext = {
config,
db: database.db,
storage: overrides.storage ?? createStorage(config),
storage: overrides.storage ?? createStorage(config, database.db),
cipher: new TokenCipher(config.encryptionKey, config.previousEncryptionKeys),
jira: {
createClient: (getAccessToken) => new HttpJiraClient({ getAccessToken, fetch: jiraFetch }),
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Readable } from "node:stream";

/** Where attachment bytes live. Metadata always lives in Postgres. */
export interface Storage {
readonly driver: "local" | "s3" | "memory";
readonly driver: "local" | "s3" | "postgres" | "memory";
put(key: string, data: Buffer, contentType: string): Promise<void>;
get(key: string): Promise<Readable>;
delete(key: string): Promise<void>;
Expand Down
46 changes: 46 additions & 0 deletions apps/api/src/storage/postgres.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Readable } from "node:stream";
import { eq, sql } from "drizzle-orm";
import { attachmentBlobs, type Database } from "@reprodrop/database";
import { assertSafeKey, type Storage } from "./index";

/**
* Keeps attachment bytes in Postgres, in the `attachment_blobs` table.
*
* Meant for small instances on hosts without a persistent disk (free tiers that wipe the
* filesystem on restart), so screenshots survive as long as the database does. Every byte counts
* against the database's size, so keep MAX_UPLOAD_BYTES and the retention period modest. For
* larger instances use local storage on a persistent volume, or S3.
*/
export class PostgresStorage implements Storage {
readonly driver = "postgres" as const;

constructor(private readonly db: Database) {}

async put(key: string, data: Buffer, contentType: string): Promise<void> {
assertSafeKey(key);
await this.db
.insert(attachmentBlobs)
.values({ key, contentType, data })
.onConflictDoUpdate({ target: attachmentBlobs.key, set: { data, contentType } });
}

async get(key: string): Promise<Readable> {
assertSafeKey(key);
const [row] = await this.db
.select({ data: attachmentBlobs.data })
.from(attachmentBlobs)
.where(eq(attachmentBlobs.key, key))
.limit(1);
if (!row) throw Object.assign(new Error("Not found"), { code: "ENOENT" });
return Readable.from(row.data);
}

async delete(key: string): Promise<void> {
assertSafeKey(key);
await this.db.delete(attachmentBlobs).where(eq(attachmentBlobs.key, key));
}

async check(): Promise<void> {
await this.db.execute(sql`select 1 from attachment_blobs limit 1`);
}
}
2 changes: 1 addition & 1 deletion apps/api/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function resetDatabase(ctx: AppContext): Promise<void> {
await ctx.db.execute(sql`
truncate table audit_logs, share_links, jira_issues, oauth_states, integration_tokens, integrations,
report_attachments, report_events, reports, projects, api_tokens, sessions, organization_members,
organizations, users restart identity cascade
organizations, users, attachment_blobs restart identity cascade
`);
}

Expand Down
55 changes: 55 additions & 0 deletions apps/api/test/storage-postgres.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import type { Readable } from "node:stream";
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { sql } from "drizzle-orm";
import { createDatabase, type DatabaseHandle } from "@reprodrop/database";
import { PostgresStorage } from "../src/storage/postgres";
import { TEST_DATABASE_URL } from "./global-setup";

async function read(stream: Readable): Promise<Buffer> {
const chunks: Buffer[] = [];
for await (const chunk of stream) chunks.push(Buffer.from(chunk));
return Buffer.concat(chunks);
}

describe("PostgresStorage", () => {
let handle: DatabaseHandle;
let storage: PostgresStorage;

beforeAll(() => {
handle = createDatabase(TEST_DATABASE_URL, { max: 2 });
storage = new PostgresStorage(handle.db);
});
afterAll(() => handle.close());
beforeEach(() => handle.db.execute(sql`truncate table attachment_blobs`));

it("stores, reads back, overwrites and deletes bytes", async () => {
const key = "org-1/report-1/shot-1.png";
const bytes = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x00, 0xff, 0x10]);
await storage.put(key, bytes, "image/png");
expect(await read(await storage.get(key))).toEqual(bytes);

const replaced = Buffer.from("second version");
await storage.put(key, replaced, "image/png");
expect(await read(await storage.get(key))).toEqual(replaced);

await storage.delete(key);
await expect(storage.get(key)).rejects.toMatchObject({ code: "ENOENT" });
});

it("reports a missing key the way the other drivers do", async () => {
await expect(storage.get("org-1/missing.png")).rejects.toMatchObject({ code: "ENOENT" });
await expect(storage.delete("org-1/missing.png")).resolves.toBeUndefined();
});

it("refuses unsafe keys", async () => {
await expect(storage.put("../escape.png", Buffer.from("x"), "image/png")).rejects.toThrow(
/unsafe storage key/,
);
await expect(storage.get("a//b.png")).rejects.toThrow(/unsafe storage key/);
});

it("passes the health check once the table exists", async () => {
await expect(storage.check()).resolves.toBeUndefined();
expect(storage.driver).toBe("postgres");
});
});
8 changes: 8 additions & 0 deletions docs/self-hosting/production.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ replica behind a load balancer. With local disk storage, run a single replica wi
3. **Database.** Use a managed Postgres (13+) or your own with backups and point-in-time recovery. Set
`DATABASE_URL`, including `?sslmode=require` if your provider needs it.
4. **Attachments.** Use object storage for durability and multiple replicas:

```env
STORAGE_DRIVER=s3
S3_BUCKET=reprodrop-attachments
Expand All @@ -34,8 +35,15 @@ replica behind a load balancer. With local disk storage, run a single replica wi
S3_SECRET_ACCESS_KEY=…
# S3_ENDPOINT=https://<account>.r2.cloudflarestorage.com (R2, Garage, SeaweedFS, MinIO…)
```

Keep the bucket private. Give the key only `s3:PutObject`, `s3:GetObject`, `s3:DeleteObject` on the
bucket and `s3:ListBucket` for the health check.

On a host without a persistent disk, for example a free tier that wipes the filesystem on
restart, `STORAGE_DRIVER=postgres` keeps attachments in the database instead. It suits small
instances: every screenshot counts against the database size, so keep `MAX_UPLOAD_BYTES` and
retention modest. See [render.md](render.md).

5. **Sign-ups.** After your team has joined, set `ALLOW_SIGNUP=false`. Admins add members from
Settings → Members.
6. **Extension origin.** Publish the extension privately and set
Expand Down
55 changes: 55 additions & 0 deletions docs/self-hosting/render.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Free hosting on Render and Neon

Runs ReproDrop at no cost: the published Docker image on Render's free web service, with Neon's free
Postgres. Good for trying ReproDrop, a small team, or a demo. For anything you depend on, use
[production.md](production.md).

## What to expect

- **The server sleeps.** Render's free service stops after about 15 minutes without traffic, and the
next request takes about a minute while it starts. If a submission fails while it wakes, submit
again from the review page: it resumes where it stopped instead of creating a duplicate.
- **Attachments live in the database.** The free service's disk is wiped on every restart, so
[render.yaml](../../render.yaml) sets `STORAGE_DRIVER=postgres` and keeps screenshots in Postgres.
Uploads are capped at 2 MB each (`MAX_UPLOAD_BYTES`).
- **Neon's free plan holds 0.5 GB.** Reports are small, but screenshots add up. Keep the retention
period short (the **Privacy** page) and watch the size in Neon's dashboard.
- **No backups or uptime guarantee** on either free plan.

## 1. Create the database (Neon)

1. Sign up at [neon.tech](https://neon.tech) and create a project. Pick the region closest to
Render's Virginia region (AWS us-east-1).
2. Open **Connect**, turn **Connection pooling** off, and copy the connection string. It looks like
`postgresql://user:password@ep-….us-east-1.aws.neon.tech/neondb?sslmode=require`. Keep it secret.

## 2. Deploy the server (Render)

1. Sign up at [render.com](https://render.com).
2. Open <https://render.com/deploy?repo=https://github.com/patchyard/reprodrop>. Render reads
[render.yaml](../../render.yaml) and shows one free web service, `reprodrop`.
3. Paste the Neon connection string into **DATABASE_URL**, then **Apply**. Render generates
`APP_SECRET` and `ENCRYPTION_KEY` itself, and `APP_URL` defaults to the service's address
(`https://reprodrop-….onrender.com`).
4. When the deploy finishes, open the service URL and create the first account. The database is
migrated on start, and `/api/health` reports `"storage": "ok"`.

Don't change `APP_SECRET` or `ENCRYPTION_KEY` later. Sessions and stored Jira credentials depend on
them.

## 3. Connect the extension

In the extension's settings, set the server address to the service URL, and paste an API token
created under **Settings → API tokens**.

## Running it for other people

`ALLOW_SIGNUP` is `true` in the blueprint, so anyone with the URL can create an account. If the
server is only for your team, set it to `false` in Render's **Environment** tab once everyone has
joined. If you keep sign-up open, you're operating a service that holds other people's bug reports:
publish who runs it and how long data is kept, keep retention short, and expect to remove abuse.

## Updating

The blueprint pins an image version. To update, change the image tag under **Settings → Image** in
Render (for example `ghcr.io/patchyard/reprodrop:0.1.4`) and deploy. Migrations run on start.
2 changes: 2 additions & 0 deletions e2e/scripts/start-server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const child = spawn(process.execPath, [server], {
APP_URL: process.env.E2E_APP_URL ?? `http://127.0.0.1:${port}`,
DATABASE_URL: databaseUrl.toString(),
DATA_DIR: dataDir,
// E2E_STORAGE_DRIVER=postgres runs the suite with attachments stored in the database.
STORAGE_DRIVER: process.env.E2E_STORAGE_DRIVER ?? "local",
WEB_DIST_DIR: web,
MIGRATIONS_DIR: path.join(root, "infra/migrations"),
MIGRATE_ON_START: "true",
Expand Down
6 changes: 6 additions & 0 deletions infra/migrations/0001_attachment_blobs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE "attachment_blobs" (
"key" text PRIMARY KEY NOT NULL,
"content_type" text NOT NULL,
"data" "bytea" NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
Loading
Loading