Configuration
We recommend the following best practices when using Puppeteer with Sevalla:- Always make sure your processes terminate cleanly by calling
process.exit(0) - Implement robust error handling and logging to prevent unwanted crashes.
- Use an external job queue (e.g., Redis, BullMQ) for reliable background processing.
- Add detailed logging to help troubleshoot Puppeteer and browser-related issues.
- Always close browser and page instances to avoid memory leaks and runaway processes.
- Run Puppeteer with the
--no-sandboxand--disable-setuid-sandboxflags in production. - Test all Puppeteer scripts locally before deploying to Sevalla.
Containerization
Dockerfile
The build for Dockerfiles is fully customizable. We recommend using a multi-stage build approach with three stages:deps- Install Chromium and Node.js dependencies.builder- Build TypeScript code.runner- Final production image with minimal size.
- Alpine Linux Base
- Uses
node:lts-alpinefor minimal image size - Includes only essential Chromium dependencies
- Results in smaller, faster deployments
- Uses
- System Chromium
-
Installs Chromium via
apkpackage manager - Avoids duplicate browser downloads
- More reliable than Puppeteer’s bundled Chromium
-
Environment variables configure Puppeteer to use system Chromium:
-
Installs Chromium via
- Security
- Runs as non-root user (
puppeteeruser) - Follows the least-privilege principle
- Safer for production deployments
- Runs as non-root user (
- Multi-stage Build
- Separates build dependencies from runtime
- Reduces final image size
- Only production dependencies in the final image
Nixpacks
Nixpacks automatically detects your project type and creates an optimized build plan. You can customize the Nixpacks build process by defining anixpacks.toml file. This allows you to fine-tune how dependencies are installed, how your application is built, and which runtime settings are applied.
The following is an example nixpacks.toml configuration:
Build phases
1. Setup phasenodejs_lts: Installs the latest Node.js.chromium: Installs system-level Chromium browser and all necessary dependencies. This ensures Chrome/Chromium is available for Puppeteer without manual Dockerfile configuration.
npm ci:Performs a clean install usingpackage-lock.json. This ensures deterministic, reproducible builds, and it is faster and more reliable thannpm installfor production.
npm run build: Compiles TypeScript to JavaScript (outputs todist/directory).npx puppeteer browsers install chrome: Downloads Chrome browser for Puppeteer.- Both commands run sequentially during deployment.
- Starts the application by running the compiled JavaScript.
- Points to
dist/server.js(adjust this if your entry point is different, e.g.,dist/index.js).