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
98 changes: 98 additions & 0 deletions .agents/skills/docspring-enterprise-install/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
name: docspring-enterprise-install
description: Installs DocSpring Enterprise, the self-hosted DocSpring Docker image, on the customer's own infrastructure with the setups in the docspring-enterprise repository (Docker Compose, Kubernetes with Helm, AWS ECS with Terraform, AWS with Convox, or Aptible). Covers choosing a setup, the license key and registry credentials, PostgreSQL, Redis and file storage, the generated secrets, the release command, the first admin user and checking the install. Use when the user wants to install, deploy, set up or try DocSpring Enterprise, or works in a checkout of docspring-enterprise. Not for upgrading an install (docspring-enterprise-upgrade), running one day to day (docspring-enterprise-operate) or using DocSpring's hosted service.
license: MIT
metadata:
author: DocSpring
---

# Install DocSpring Enterprise

DocSpring Enterprise is one Docker image that runs three services (`web`, `worker`, `worker_gj`), a release command
before each release goes live and three scheduled tasks. This repository has a ready-made setup for each platform; the
guide for each is at https://docspring.com/docs/enterprise/.

## Rules

1. **Never print a secret.** The license key, registry credentials, `SECRET_KEY_BASE`,
`DOCSPRING_SUBMISSION_DATA_ENCRYPTION_KEY`, database and Redis passwords and the admin password go into files,
variables or the platform's secret store, never into your replies, logs or commit messages. To check one, say
whether it's set and how long it is.
2. **Ask before anything that costs money or deletes data:** creating cloud resources (`terraform apply`,
`./install.rb`, `aptible db:create`), `terraform destroy`, `docker compose down -v`, `helm uninstall`. Say what it
creates and roughly what it costs (the folder's README has the figures). A plan or a dry run needs no approval:
`terraform plan`, `./install.rb plan`, `helm template`.
3. **Generate `SECRET_KEY_BASE` and the encryption key once per install, and never change them.** The setups generate
them. Tell the user to copy the encryption key somewhere outside the install (a password manager): without it,
the data DocSpring stores can't be read.
4. **Pin an image version** (a 10-character tag such as `c648191044`, from https://docspring.com/enterprise-releases).
`latest` moves with each release.
5. **Start everything with `run_as_deploy`** and change none of the container settings the setup ships with (it starts
as root, drops all capabilities but a few, and runs Puma, Sidekiq and GoodJob directly). `AGENTS.md` at the
repository root says why.

## 1. Choose a setup

| Folder | Platform | Choose it when |
| ----------------- | ---------------------------------- | ----------------------------------------------------------------- |
| `docker-compose/` | One Linux server with Docker | A trial, or a small install where one server is enough |
| `kubernetes/` | Any Kubernetes cluster, with Helm | The user runs Kubernetes (EKS, GKE, AKS, OpenShift, on-premises) |
| `aws-ecs/` | AWS ECS Fargate, with Terraform | AWS without servers or Kubernetes to manage |
| `convox/` | AWS EKS through Convox, one script | A complete AWS setup from one script, managed with the Convox CLI |
| `aptible/` | Aptible | The user already runs apps on Aptible |

Ask the user which platform they run, if it isn't clear from the conversation or their files. Then read that folder's
`README.md` (the steps) and `AGENTS.md` (its rules and checks) before you start.

## 2. Gather what the install needs

- **From DocSpring** (emailed to the customer): the license key, and credentials for one of the two registries that
hold the image: Docker Hub (`docspringcom/docspring-enterprise`, a username and access token) or Amazon ECR
(`691950705664.dkr.ecr.us-east-1.amazonaws.com/docspring/enterprise`, an access key ID and secret). If they don't
have them, they ask support@docspring.com.
- **A host name**, such as `docspring.example.com`, and how HTTPS will be served (the setup's proxy, their load
balancer, or a platform default domain for a trial).
- **PostgreSQL 14 or later** (17 recommended), **Redis 6.2 or later**, and **file storage** (an S3 bucket or other
S3-compatible storage, or Google Cloud Storage). The ECS, Convox and Aptible setups create the database and Redis;
for Compose and Kubernetes, ask whether to use managed services or the setup's own containers (a trial only).
- **An email provider** for invitations and password resets (SMTP, Postmark, SendGrid, Mailgun or Amazon SES). The
install can start without one.
- **Outbound HTTPS to `api.docspring.com`** for the license check. An air-gapped install needs a perpetual license
from DocSpring.

https://docspring.com/docs/enterprise/requirements/ has the sizes, timeouts and settings in full.

## 3. Install

Follow the folder's README. The short version:

- **Docker Compose:** `./setup.sh` (writes `.env` with new secrets), `docker compose up -d --wait`, then
`sudo ./install-schedule.sh` for the scheduled tasks.
- **Kubernetes:** create the namespace, the database, Redis and bucket, write a values file (or a Secret), then
`helm install docspring-enterprise oci://ghcr.io/docspring/charts/docspring-enterprise --namespace docspring
--values values.yaml --timeout 30m`. The chart runs the release command as a Job before the services start.
- **AWS ECS:** copy `example/`, fill in `terraform.tfvars`, keep the state in an encrypted S3 backend, then
`terraform init && terraform apply`, then the command `terraform output deploy_command` prints.
- **Convox:** `cd convox && ./install.rb plan`, then `./install.rb`. For a run without prompts, pass every setting
and add `--yes --json`. Settings, including generated secrets, are saved to `.installer_config.json`.
- **Aptible:** copy the folder into its own git repository, create the app, database and Redis, set the
configuration, `git push aptible main`, then add an HTTPS endpoint and scale the services.

The release command (`run_as_deploy rake db:prepare`) creates the database schema and the first admin user from
`DOCSPRING_ADMIN_EMAIL` and `DOCSPRING_ADMIN_PASSWORD`. It runs again before every release and is safe to repeat.

If a step fails, read its output, fix the cause and run the same step again. Every setup is safe to re-run.

## 4. Check the install

1. `https://<host>/health/site` returns `200` (the app has booted), and `https://<host>/health` returns `200`
(the database, Redis and the cache work too).
2. Run the checks, which test PostgreSQL, Redis, file storage and background jobs, then generate a test PDF:
`run_as_deploy rake checks:health_check checks:generate_test_submission`, run the way the folder's README runs
one-off commands (`docker compose run --rm tasks ...`, `kubectl exec ...`, the ECS `run_task_command` output,
`convox run command ...`, `aptible ssh --app docspring ...`).
3. The user signs in with the admin email and password and changes the password.

Then point the user at what's left: their domain and HTTPS, email
(https://docspring.com/docs/enterprise/configuration/email-notifications/), backups of the database and the bucket,
and an uptime monitor on `/health`.
96 changes: 96 additions & 0 deletions .agents/skills/docspring-enterprise-operate/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
name: docspring-enterprise-operate
description: Runs a DocSpring Enterprise install (the self-hosted DocSpring Docker image) day to day, on Docker Compose, Kubernetes, AWS ECS, Convox or Aptible. Covers changing settings, one-off commands and the Rails console, logs, the scheduled tasks, health checks, admin users and locked-out admins, backups, scaling, and diagnosing common problems (the license check, failed PDFs, stuck jobs, uploads, emails, timeouts). Use when the user asks to configure, troubleshoot, debug, scale, back up or check on their DocSpring Enterprise install, or to run a command or rake task on it. Not for a new install (docspring-enterprise-install) or an upgrade (docspring-enterprise-upgrade).
license: MIT
metadata:
author: DocSpring
---

# Run DocSpring Enterprise

An install runs three services from one image: `web` (Puma, port 4001), `worker` (Sidekiq: PDFs, emails, webhooks)
and `worker_gj` (GoodJob: account exports and imports), plus three scheduled tasks. The settings are environment
variables, listed at https://docspring.com/docs/enterprise/configuration/environment-variables/.

## Rules

1. **Never print a secret.** Don't run `env`, `printenv`, `convox env`, `kubectl get secret -o yaml`,
`aptible config` or `docker compose config` where the output reaches the conversation: filter to the names you
need (`convox env | cut -d= -f1`), or check whether one is set.
2. **Never look at customer documents or submission data.** Diagnose with IDs, counts, statuses, error messages and
logs. If a problem needs a document's contents, ask the user to look.
3. **Ask before anything that changes or deletes data**: rake tasks that write, Rails console changes, restarts in
production, scaling down, deleting jobs or records. Reading logs and statuses needs no approval.
4. **Never change `DOCSPRING_SUBMISSION_DATA_ENCRYPTION_KEY` or `SECRET_KEY_BASE`** on a running install. A new
encryption key makes the stored data unreadable.
5. **Start every command with `run_as_deploy`**, as the services do.

## Running commands

Run one-off commands with the same image and settings as the services:

| Setup | One-off command | Logs |
| -------------- | -------------------------------------------------------------------------------------- | ------------------------------------------ |
| Docker Compose | `docker compose run --rm tasks run_as_deploy <command>` | `docker compose logs -f web worker` |
| Kubernetes | `kubectl exec -n docspring deploy/docspring-enterprise-web -- run_as_deploy <command>` | `kubectl logs -n docspring deploy/...` |
| AWS ECS | `terraform output run_task_command` (a task that runs and exits), or ECS Exec | CloudWatch (`terraform output log_groups`) |
| Convox | `convox run command '<command>'` | `convox logs` |
| Aptible | `aptible ssh --app docspring <command>` | `aptible logs --app docspring` |

A Rails console is `run_as_deploy rails console` (add `-it` for `kubectl exec`).

## Changing settings

Set the variable where the setup keeps it (`.env`, the Helm values or Secret, `extra_environment` or `extra_secrets`
in Terraform, `convox env set`, `aptible config:set`), then restart the services so they read it: `docker compose up -d`,
`kubectl rollout restart deployment -n docspring -l app.kubernetes.io/instance=docspring-enterprise`, the ECS deploy
command, `./update.sh` on Convox (Aptible restarts by itself). The `/admin/system` page shows the values the app sees,
with secrets hidden.

## Checks

- `/health/site`: the app has booted. `/health`: the database, Redis and the cache work too.
- `run_as_deploy rake checks:health_check`: PostgreSQL, Redis, file storage and Sidekiq. Add
`checks:generate_test_submission` to make a test PDF from start to finish.
- `/sidekiq` (Owners and Developers) shows Sidekiq's queues, retries and dead jobs, and `/good_job` GoodJob's.

## Scheduled tasks

Three tasks run every scheduled job the install needs: `rake timers:hourly` (`15 * * * *`), `timers:daily`
(`0 3 * * *`) and `timers:weekly` (`0 4 * * 0`). Run one now with the one-off command, or one step of it with `ONLY`:
`run_as_deploy rake timers:daily ONLY=submissions:expire_overdue_submissions`. Details:
https://docspring.com/docs/enterprise/scheduled-tasks/.

## Admin users

- Admins have the Owner, Developer or Support role (https://docspring.com/docs/enterprise/admin-users/).
- Everyone locked out: run `run_as_deploy rake db:seed` as a one-off command with `DOCSPRING_ADMIN_EMAIL` and
`DOCSPRING_ADMIN_PASSWORD` set to a new admin's. It creates that user as an Owner, and does nothing if the email
address already exists. Ask the user for the password, or have them set it themselves; never choose one they can't
see.

## Common problems

| Symptom | Look at |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Submissions fail with "Your DocSpring license is no longer valid" | The install can't reach `https://api.docspring.com` (it's disabled 30 days after its last passing check; the admin pages show a banner first), or the license was revoked. Check outbound HTTPS from the containers, then contact support@docspring.com |
| PDFs stay pending | Is `worker` running and healthy? Sidekiq's queues and retries; the worker's logs |
| Account exports or imports stay queued | Is `worker_gj` running? It needs a direct database connection, not a pgbouncer transaction pool |
| Uploads fail in the browser | The bucket's CORS rule allows the install's origin (https://docspring.com/docs/enterprise/requirements/) |
| Large uploads or long requests fail at a proxy | The proxy or load balancer allows 110 MB bodies and a 240-second timeout |
| No emails | `DOCSPRING_DISABLE_EMAILS` is off and an email provider is set; the worker's logs |
| Containers restart on every deploy or stop part way | The container settings match the setup's (`run_as_deploy`, capabilities, no foreman) |
| A scheduled task didn't run | The platform's schedule points at the current image; run the task by hand and read its output |

If you can't find the cause, collect the error messages, the image version and what changed recently, and have the
user send them to support@docspring.com.

## Backups and scaling

- Back up the database (managed snapshots or point-in-time recovery, or `pg_dump`) and the bucket (versioning), and
keep the encryption key and `SECRET_KEY_BASE` somewhere separate. Back up Redis with them: it holds the job queues,
and a database restored without them has submissions that stay pending. Stop `worker` (Sidekiq) while you back up
the database and Redis, so a job can't finish between the two, then start it again. Docker Compose's `backup.sh`
does all of that, and `docker-compose/README.md` restores it.
- `web` and `worker` scale out to any number of containers; one `worker_gj` is enough. Sizes are at
https://docspring.com/docs/enterprise/requirements/#cpu-and-memory.
Loading