Container, database, and service deployment
Invidious is operated as a web service with PostgreSQL as its durable store. The repository supports a local Docker Compose setup, a host-installed PostgreSQL and systemd setup, and published container images for stable and nightly use. These paths share the same application configuration and database model.
Operating model
Service topology
The deployment has two main services: the Invidious application and PostgreSQL. The application serves HTTP on port 3000 and uses PostgreSQL for users, subscriptions, video metadata, sessions, playlists, and related state. In a container deployment, the services communicate over the Compose network. In a host deployment, the application can use a local PostgreSQL socket or local TCP connection. config/config.example.yml defines both database forms.
The application can also use Invidious Companion for video stream loading. Companion is an external service rather than part of the database or application container. Its private URL and key must be set when that service is enabled. See configuration and runtime security for the wider configuration contract.
References: docker-compose.yml• L8-56 config/config.example.yml• L7-39 config/config.example.yml• L51-97
Deployment paths
The repository provides different deployment paths for different goals:
| Path | Main use | Operating boundary |
|---|---|---|
| Docker Compose | Local development | Builds the application from the checkout and runs it with a PostgreSQL container |
| Published container image | Repeatable service operation | Runs a pre-built application image beside a separately managed PostgreSQL service |
| systemd unit | Host installation | Runs the application as the invidious user under a fixed working directory |
| Kubernetes reference | Cluster operation | Points maintainers to the separate Invidious Helm chart repository |
The local Compose file is explicitly for development. Production operators should use the installation artifacts and configuration suited to their host or cluster rather than treating the development file as a complete production policy.
References: docker-compose.yml• L1-5 invidious.service• L1-19 kubernetes/README.md• L1
Container orchestration
Application and database services
The Compose deployment builds the Invidious image from the checkout and starts PostgreSQL with a named data volume. The application exposes port 3000 only on the local host by default. PostgreSQL exposes no host port in this file, so the application reaches it through the service name invidious-db.
The application waits for the database health check before it starts. Both services use an automatic restart policy. The database volume keeps PostgreSQL data outside the short-lived container, while the mounted SQL directory and initialization script provide the starting schema for a new database.
References: docker-compose.yml• L10-58
Startup readiness
Startup readiness is checked at two levels. PostgreSQL reports readiness with pg_isready, and Invidious reports application health through /api/v1/stats. This lets the container runner distinguish a database that can accept connections from an application that can serve requests.
The application still needs valid configuration and a usable database after both health checks pass. A healthy process does not by itself confirm that public URLs, secrets, or optional external services are correct.
References: docker-compose.yml• L17-42 docker-compose.yml• L51-56 config/config.example.yml• L121-183
Image construction
Build stages
The container build turns the Crystal source and its assets into a small Alpine runtime image. The build resolves dependencies, compiles a pinned OpenSSL version, validates the application, and compiles the service before it copies the executable, configuration templates, SQL files, locales, and generated assets into the runtime image.
The final image runs as the unprivileged invidious user and uses tini as its entry process. The release build is static and listens on port 3000. The image keeps configuration and SQL beside the executable so the same image can initialize or check the database at runtime. See build, test, and development workflow for the wider build contract.
References: docker/Dockerfile• L1-25 docker/Dockerfile• L28-49 docker/Dockerfile• L63-74 docker/Dockerfile• L76-93
Release image distribution
Stable images build from version tags, while nightly images build from changes to master. Each workflow builds AMD64 and ARM64 variants, pushes them to quay.io/invidious/invidious, and combines the architecture-specific images into a multi-architecture tag.
The workflows use the same Dockerfile and pass the release build argument. Stable tags include version and latest; nightly tags include a dated commit form and master. Changes that affect only documentation or other ignored paths do not trigger the nightly image workflow.
References: .github/…/build-stable-container.yml• L3-7 .github/…/build-stable-container.yml• L9-67 .github/…/build-stable-container.yml• L68-87 .github/…/build-nightly-container.yml• L3-19 .github/…/build-nightly-container.yml• L21-77 .github/…/build-nightly-container.yml• L79-98
Database initialization and evolution
Schema initialization
PostgreSQL is the system of record for persistent Invidious state. A new database receives the core tables for channels, videos, channel videos, users, sessions, nonces, annotations, playlists, and playlist videos. The SQL files create the tables and their key constraints or indexes in an order that supports the relationships between them.
In a new PostgreSQL container, the entrypoint runs docker/init-invidious-db.sh with the configured database user and database name. The script applies the SQL files once as part of database initialization. An existing postgresdata volume keeps its database and does not represent a fresh initialization.
References: docker/init-invidious-db.sh• L1-12 config/…/channels.sql• L1-24 config/…/videos.sql• L1-22 config/…/users.sql• L1-28 config/…/playlists.sql• L1-29 config/…/playlist_videos.sql• L1-19
Schema evolution
Schema evolution has two related paths. The application can check table shape when check_tables is enabled, and the migration command can apply registered versioned migrations. The migration system records completed versions in public.invidious_migrations and runs pending migrations in version order.
Older standalone scripts in config/migrate-scripts show prior database changes. They remain useful as historical context for upgrades but are not the current version registry. For persistence rules and migration ownership, see persistence and schema migrations.
The database path can be summarized as follows:
flowchart LR
A[PostgreSQL database] --> B{Existing data volume?}
B -- No --> C[Initial SQL schema]
B -- Yes --> D[Keep existing schema and data]
C --> E[Application connection]
D --> E
E --> F{Schema maintenance requested?}
F -- check_tables --> G[Integrity check]
F -- --migrate --> H[Versioned migrations]
F -- No --> I[Normal service operation]
G --> I
H --> I
References: src/…/base.cr• L10-25 src/…/base.cr• L44-123 src/…/migrator.cr• L9-48 src/invidious.cr• L63-69 src/invidious.cr• L131-146 config/…/migrate-db-8e884fe.sh• L1-8
Service execution
Process lifecycle
The application loads configuration, connects to PostgreSQL, checks the requested database state, starts background jobs, registers HTTP routes, and then starts the web server. The same executable supports normal service operation and a separate migration command.
The service unit keeps the process under the dedicated invidious account and restarts it after failure. The container uses the same application entry point with tini, so signal handling and process shutdown work across container and host deployments.
References: src/invidious.cr• L60-69 src/invidious.cr• L131-146 src/invidious.cr• L163-193 src/invidious.cr• L215-262 invidious.service• L6-17 docker/Dockerfile• L90-93
Runtime configuration
Runtime configuration comes from YAML in config/config.yml or from the INVIDIOUS_CONFIG and INVIDIOUS_CONFIG_FILE environment variables. The loader turns either database settings or a PostgreSQL URI into the connection used by the application. It also rejects missing required values and unchanged placeholder secrets before service startup.
The network settings must match the layer in front of Invidious. A reverse proxy needs the external port, domain, and HTTPS settings that describe the public request path. The application may listen on a TCP address or a Unix socket. See configuration and runtime security for secret, proxy, and public-instance rules.
References: src/…/config.cr• L223-325 src/…/config.cr• L328-344 src/invidious.cr• L248-262 config/config.example.yml• L109-206
Deployment artifacts
Host database setup
The database deployment script prepares PostgreSQL as a host service. It starts and enables PostgreSQL, creates the kemal database user and the invidious database, and can write local password access data in non-interactive mode. Interactive mode instead leaves the operator with the required local authentication rules to review.
This path creates the database service but does not start Invidious or apply the full application schema by itself. The application startup check or a migration step must complete the application-side database setup.
References: scripts/deploy-database.sh• L7-19 scripts/deploy-database.sh• L21-41 scripts/deploy-database.sh• L44-60
Service and cluster artifacts
invidious.service is a systemd unit for a host install. It defines the service account, working directory, executable, restart behavior, and boot target. The repository's Kubernetes directory is only a pointer because the maintained Helm chart lives in a separate repository.
These artifacts define process placement rather than application policy. Operators still need to supply the runtime configuration, PostgreSQL access, public network settings, and any companion service outside the unit or chart reference.
References: invidious.service• L1-19 kubernetes/README.md• L1 config/config.example.yml• L7-39
Change checklist
When these files or sections are changed, remember to consider these:
- When a database table or column changes, align the initial SQL, registered migrations, and the data structures used by the integrity check. The migration path must preserve existing data.
- When Compose service names, ports, or database credentials change, update the application database settings and both service health checks together.
- When the runtime image changes, keep the executable, generated assets, configuration templates, SQL files, locales, user permissions, and entry process compatible with the service command.
- When the container build dependency version changes, keep its integrity check and the static application build compatible with the selected runtime image.
- When image tags or architecture names change, update both architecture builds and the manifest source list in the stable and nightly workflows.
- When the host service path or account changes, update the systemd unit and the installation configuration as one deployment contract.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The application starts before PostgreSQL is ready | The database connection fails and the application exits | Use the PostgreSQL health check and the Compose dependency condition |
A new SQL file is changed while an existing postgresdata volume is reused | The running database does not receive the new initial schema automatically | Apply a versioned migration or use an intentional database rebuild |
A required secret remains CHANGE_ME!! or is empty | Configuration loading stops before the service starts | Set a real HMAC key and a valid companion key when Companion is enabled |
| The pinned OpenSSL source or checksum is not available during the image build | The image build stops before it produces a service image | Keep the version and checksum pair valid and reachable |
| A release publishes architecture images but the manifest names do not match their tags | Clients may receive an incomplete or unusable multi-architecture image | Keep the matrix tag suffixes and manifest sources synchronized |
| The systemd working directory or executable path does not match the host install | systemd repeatedly restarts a process it cannot launch | Install to the declared path or update the unit before enabling it |
| Integrity checking sees an unexpected schema shape | It may alter or drop columns to match the current model | Review schema changes and use the migration path for planned upgrades |
Key files
| File | Why to read it |
|---|---|
| docker-compose.yml | Shows the local application and PostgreSQL relationship, readiness checks, volume use, and runtime configuration boundary |
docker/Dockerfile | Defines the source-to-runtime image path, build validation, pinned build inputs, and security boundary of the final container |
| docker/init-invidious-db.sh | Shows how a new PostgreSQL database receives the starting schema |
| config/config.example.yml | Describes the database, network, external-service, and secret settings required by an operator |
src/invidious.cr | Shows the high-level startup order from configuration and database connection to jobs and HTTP service |
src/invidious/config.cr | Defines how file and environment configuration become runtime settings and startup validation |
src/invidious/database/base.cr | Explains the optional table integrity check and its relationship to the SQL schema files |
src/invidious/database/migrator.cr | Defines the version record and ordered migration flow |
| config/…/channels.sql | Illustrates the initial SQL contract for a core persistent table |
| config/…/playlists.sql | Illustrates a table with an application enum and persistent playlist state |
| config/…/migrate-db-8e884fe.sh | Illustrates the older standalone upgrade scripts kept for migration history |
| scripts/deploy-database.sh | Describes host PostgreSQL setup outside Docker |
invidious.service | Defines host process execution and restart behavior |
| .github/…/build-stable-container.yml | Defines tagged release image builds and multi-architecture publication |
| .github/…/build-nightly-container.yml | Defines master-branch image builds and nightly publication |
| kubernetes/README.md | Identifies the external Helm chart used for Kubernetes deployment |