Deployment
Relevant source files
The following files were used as context for generating this wiki page:Inbox Zero is designed to be deployed in two primary ways: as a hosted service on Vercel or self-hosted using Docker. This document outlines the architecture, configuration, and steps required for both deployment strategies. The main web application is a Next.js application located in apps/web.
For a higher-level overview of the project structure, refer to the Architecture documentation.
Deployment Options
Vercel
Vercel is the recommended platform for a quick and managed deployment. The project includes a one-click deploy button that simplifies the setup process by cloning the repository and prompting for necessary environment variables.
Sources: README.md:18-18
Self-Hosting with Docker
For users who prefer to manage their own infrastructure, the project can be deployed using Docker. A docker-compose.yml file is provided for local development, and a Dockerfile.prod is available for building a production-ready container image. This method provides full control over the application, database, and caching services.
Sources: README.md:143-145, README.md:180-183, ARCHITECTURE.md:104-108
Vercel Deployment
The quickest way to deploy Inbox Zero is by using the "Deploy with Vercel" button. This process automates the repository cloning and initial setup.
This diagram illustrates the user flow for deploying the application to Vercel.
Sources: README.md:18-18
Required Environment Variables
The Vercel deployment button pre-configures the necessary environment variables that you will need to provide. These include credentials for Google/Microsoft OAuth, database connections, and other third-party services.
Sources: README.md:18-18
Cron Jobs
The application relies on scheduled tasks for features like watching for new emails and sending digests. These need to be configured using a cron job provider. The README.md suggests that Vercel's vercel.json configuration for crons was not working and recommends using an alternative provider like Upstash.
The required cron jobs are:
| Path | Schedule | Description |
|---|---|---|
/api/watch/all | 0 1 * * * | Renews the watch on all connected Google accounts. |
/api/resend/summary/all | 0 16 * * 1 | Sends a weekly summary digest email. |
/api/reply-tracker/disable-unused-auto-draft | 0 3 * * * | Disables auto-draft for inactive reply trackers. |
Sources: README.md:164-178
Self-Hosting with Docker
Self-hosting provides more control and is managed via Docker and Docker Compose.
Local Development with Docker Compose
For local development, a docker-compose.yml file is provided to orchestrate the necessary services: a PostgreSQL database, a Redis instance, and the main web application.
The following diagram shows the services defined in the docker-compose.yml file and their dependencies.
Sources: docker-compose.yml, README.md:143-145
The services are defined as follows:
| Service | Image | Description | Ports |
|---|---|---|---|
postgres | postgres:15.3-alpine | The primary PostgreSQL database. | 5432:5432 |
redis | redis:7.2.0-alpine | Redis instance for caching and queueing. | 6379:6379 |
app | inbox-zero (builds from local Dockerfile) | The Next.js web application. | 3000:3000 |
Sources: docker-compose.yml
To start these services, run:
docker-compose up -d
Sources: README.md:144-144
Production Docker Build
A production-ready Docker image can be built using docker/Dockerfile.prod. The build process is multi-stage to create an optimized and secure image.
A critical aspect of the build process is the handling of NEXT_PUBLIC_* environment variables. These variables are embedded at build time.
Build-Time Arguments
The NEXT_PUBLIC_BASE_URL must be provided as a build argument. If it's not provided, it defaults to http://localhost:3000.
# For production with your custom domain
docker build \
--build-arg NEXT_PUBLIC_BASE_URL="https://your-domain.com" \
-t inbox-zero \
-f docker/Dockerfile.prod .
Sources: README.md:185-190, docker/DOCKER_BUILD_GUIDE.md:14-19
Runtime
After building the image, the container is run with runtime environment variables passed in.
docker run -p 3000:3000 \
-e DATABASE_URL="your-database-url" \
-e AUTH_SECRET="your-auth-secret" \
# ... other runtime environment variables
inbox-zero
Sources: README.md:195-201
The container uses an entrypoint.sh script to first run database migrations and then start the Next.js application.
#!/bin/sh
# apps/web/entrypoint.sh
set -e
echo "Running migrations..."
pnpm prisma migrate deploy
echo "Starting app..."
exec "$@"
The exec "$@" part of the script runs the command passed to the Docker container, which is typically pnpm start.
Sources: apps/web/entrypoint.sh, apps/web/package.json:5-5
The overall Docker build and run flow is as follows:
Environment Variables
Configuration is managed heavily through environment variables. The turbo.json file lists all environment variables that are passed to the build task, and apps/web/env.ts defines and validates them using Zod.
Build vs. Runtime Variables
It is crucial to distinguish between build-time and runtime variables.
- Build-time variables: Prefixed with
NEXT_PUBLIC_, these are embedded into the client-side JavaScript bundles during thenext buildprocess. Changing them requires rebuilding the Docker image. - Runtime variables: These are used server-side and can be set when the container starts, without needing a rebuild.
Sources: docker/DOCKER_BUILD_GUIDE.md:3-5
Key Variables for Deployment
The following table lists some of the essential environment variables defined in turbo.json and apps/web/env.ts.
| Variable | Type | Description |
|---|---|---|
DATABASE_URL | Runtime | Connection string for the PostgreSQL database. |
AUTH_SECRET | Runtime | A secret key for NextAuth.js session encryption. |
GOOGLE_CLIENT_ID | Runtime | Google OAuth 2.0 Client ID. |
GOOGLE_CLIENT_SECRET | Runtime | Google OAuth 2.0 Client Secret. |
UPSTASH_REDIS_URL | Runtime | URL for the Upstash Redis instance. |
UPSTASH_REDIS_TOKEN | Runtime | Token for the Upstash Redis instance. |
NEXT_PUBLIC_BASE_URL | Build-time | The public URL where the app is hosted. |
INTERNAL_API_KEY | Runtime | A secret key for securing internal API calls. |
DEFAULT_LLM_PROVIDER | Runtime | Specifies the default LLM provider (e.g., openai, anthropic). |
OPENAI_API_KEY | Runtime | API key for OpenAI services. |
Sources: turbo.json:5-92, apps/web/env.ts, README.md:37-51
Build Process
The application is built using the build script defined in apps/web/package.json.
"scripts": {
"build": "cross-env NODE_OPTIONS=--max_old_space_size=16384 prisma migrate deploy && next build",
}
This command first ensures the database schema is up-to-date by running prisma migrate deploy, and then it builds the Next.js application with next build.
The turbo.json configuration ensures that a comprehensive list of environment variables is available to the build task, which is essential for correctly bundling the application, especially the NEXT_PUBLIC_* variables.
Sources: apps/web/package.json:4-4, turbo.json:4-95
Security
Deployment security is handled through several mechanisms defined in next.config.ts.
Security Headers
The application configures strict security headers for all responses to mitigate common web vulnerabilities.
// apps/web/next.config.ts
async headers() {
return [
{
source: "/(.*)",
headers: [
{ key: "X-Frame-Options", value: "DENY" },
{ key: "X-XSS-Protection", value: "1; mode=block" },
{ key: "X-Content-Type-Options", value: "nosniff" },
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
{ key: "Content-Security-Policy", value: "..." },
{ key: "Strict-Transport-Security", value: "max-age=31536000" },
],
},
];
},
These headers include a restrictive Content Security Policy (CSP), X-Frame-Options to prevent clickjacking, and Strict-Transport-Security to enforce HTTPS.
Sources: next.config.ts:133-176
Docker Security
The DOCKER_BUILD_GUIDE.md provides important security advice:
- Never use build arguments for secrets: Build arguments can be inspected in the image history.
- Use runtime environment variables for secrets: Sensitive data should only be injected when the container starts.
Sources: docker/DOCKER_BUILD_GUIDE.md:58-64