Services and Settings
Every DocSpring Enterprise install runs the same pieces from the Docker image, whatever platform it’s on. Our deployment configs set all of this up for Docker Compose, Kubernetes, AWS ECS, Convox and Aptible. This page is for checking them, or for setting up a platform we don’t have a config for.
Services
Section titled “Services”Run each as its own container (a Kubernetes Deployment, an ECS service, a Compose service), with the same image and settings.
| Service | Command | What it does |
|---|---|---|
web | run_as_deploy puma -C config/puma.rb | The app, the API and the admin dashboard, on port 4001. |
worker | run_as_deploy sidekiq | Generates PDFs and Word documents, and sends email and webhooks. |
worker_gj | run_as_deploy good_job | Account exports and imports (Admin API). |
Every command starts with run_as_deploy, which blocks the cloud metadata address, switches to the unprivileged
deploy user and runs the command under an init process that cleans up after Chromium and LibreOffice. Never leave
it out.
How many of each to run, and their CPU and memory, is on the Requirements
page. web and worker can run as many copies as you like; one worker_gj is enough.
Health checks
Section titled “Health checks”web answers on port 4001 (the PORT setting):
/health/siteanswers200once the app has booted. Use it for liveness, readiness and your load balancer’s target health. The first boot takes up to a minute./healthalso checks the database, Redis and the cache. Use it for uptime monitoring, not for readiness, or a short database outage takes everywebcontainer out of service at once.
A request waits for a free web server thread, so when every thread is busy these checks can time out although the
server is fine. With DOCSPRING_PUMA_READINESS_PORT set, web also answers readiness checks on that port (any path)
while its worker processes are running, without waiting for a thread. It needs WEB_CONCURRENCY of 1 or more.
The workers have no HTTP port. Set your platform to restart any container that exits.
Stopping
Section titled “Stopping”When a container is told to stop (SIGTERM), web finishes the requests it’s running and the workers finish their
jobs, then they exit. Give them time:
web: 240 seconds, since some requests run for up to 210 seconds. Where your platform allows less (AWS Fargate allows 120), a long request that’s still running is cut off.workerandworker_gj: 60 seconds. Sidekiq finishes its jobs for 25 seconds, then puts the rest back on the queue to run again.
Database connections
Section titled “Database connections”worker_gj, the release command and the scheduled tasks need a direct
connection to PostgreSQL. If DATABASE_URL points at a connection pooler such as PgBouncer in transaction mode, give
those a DATABASE_URL that points at the database itself. Most
installs connect directly and need nothing extra.
The release command
Section titled “The release command”run_as_deploy rake db:prepareRun it once for each new release, after you pull the new image and before the new release’s services start. On an
empty database it loads the schema and creates the first admin user from DOCSPRING_ADMIN_EMAIL and
DOCSPRING_ADMIN_PASSWORD; afterwards it runs the release’s database migrations. It’s safe to run again, and the
services of the previous release keep working while it runs.
Scheduled tasks
Section titled “Scheduled tasks”Three commands, run hourly, daily and weekly: see Scheduled tasks.
Settings
Section titled “Settings”DocSpring is configured with environment variables. Give every service, the release command and the scheduled tasks the same ones. These are required:
| Setting | What it is |
|---|---|
DATABASE_URL | postgres://user:password@host:5432/docspring |
REDIS_URL | redis://host:6379/0, or rediss:// for TLS |
SECRET_KEY_BASE | Signs sessions and links. Generate it once with openssl rand -hex 64. |
DOCSPRING_SUBMISSION_DATA_ENCRYPTION_KEY | Encrypts submission data in the database. Generate it once with openssl rand -hex 32, keep a copy somewhere safe, and never change it: without it the data can’t be read. |
DOCSPRING_LICENSE | Your license key. |
DOCSPRING_DOMAIN_NAME | The host name people use, such as docspring.example.com. See Domains and HTTPS. |
For the first install, also set DOCSPRING_ADMIN_EMAIL and DOCSPRING_ADMIN_PASSWORD (Admin users),
and the settings for your file storage and
email. Every other setting is optional:
Environment variables lists them all.
Keep the secret ones in your platform’s secret store (Kubernetes Secrets, AWS Secrets Manager) rather than in plain configuration.
Container security
Section titled “Container security”The container starts as root, so that run_as_deploy can block the cloud metadata address and switch to deploy.
The app itself never runs as root. Don’t set a USER, runAsUser or runAsNonRoot.
Give the containers as few privileges as this needs:
- Drop every Linux capability, then add back
SETUIDandSETGID(to switch todeploy) andKILL(so a stop signal reaches the app). - Add
NET_ADMINwhere your platform allows it.run_as_deployuses it to add a firewall rule that blocks the cloud metadata address (169.254.169.254), so nothing in the app can read your server’s cloud credentials, even if a customer’s document exploited a bug in a document tool. Where it isn’t allowed (AWS Fargate, Aptible, a Kubernetes namespace below theprivilegedPod Security level),run_as_deploylogs a warning and carries on: block that address with a Kubernetes NetworkPolicy instead, or run where it isn’t reachable, as on Fargate. - Don’t allow privilege escalation (
allowPrivilegeEscalation: false, or Docker’sno-new-privileges), and use the runtime’s default seccomp profile. - Leave the root file system writable: the app writes temporary files while it makes documents.
In Docker Compose:
cap_drop: [ALL]cap_add: [NET_ADMIN, SETUID, SETGID, KILL]security_opt: ["no-new-privileges:true"]In Kubernetes:
securityContext: allowPrivilegeEscalation: false capabilities: drop: [ALL] add: [NET_ADMIN, SETUID, SETGID, KILL] seccompProfile: type: RuntimeDefault