9. Production Deployment
Learn how to bundle, distribute, and secure your TitanPL application for high-performance production environments.
TitanPL is designed for high-performance production environments. Its deployment process ensures that all security policies, extensions, and pre-computed routes are packed into a portable, production-ready bundle.
๐๏ธ Production Build (titan build --release)
The titan build --release command is the standard way to package your application for production.
What it Does:
- V8 Bundle: Minifies and bundles all your actions into a single optimized runtime.
- Route Pre-computation: Generates a static map of all actions for faster startup.
- Security Assets: Automatically copies
tanfig.jsonandpackage.jsonto the distribution. - Extension Bundling: Scans
node_modulesfor anytitan.jsonfiles and copies the entire extension tree into a specialized.ext/directory. - Binary Extraction: Pulls the correct platform-specific engine binary into the bundle root.
๐ ๏ธ Custom Assets & Build Configuration
You can control which folders and files are carried over to your production build/ folder by adding a build block to your tanfig.json.
{
"name": "my-app",
"build": {
"files": ["public", "static", "db", "certs", "custom-assets"],
"env": "production"
}
}Supported Fields:
files: An array of folder/file names in your project root to copy into thebuild/directory. By default, TitanPL copiespublic,static,db, andtanfig.json.env: Set toproductionordeployto disable the creation of local symlinks in favor of a clean, standalone file structure.
๐ก๏ธ Production Safety Management
Deploying TitanPL to Docker is straightforward because the build/ directory is self-contained.
Sample Dockerfile:
# ================================================================
# STAGE 1 โ Builder
# ================================================================
FROM node:20-bookworm-slim AS builder
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential pkg-config \
&& rm -rf /var/lib/apt/lists/*
ENV NODE_ENV=production
ENV TITAN_DEV=0
# Copy dependency files
COPY package.json package-lock.json* ./
# Install Titan CLI and dependencies
RUN npm install -g @titanpl/cli
RUN npm install --include=optional
# Copy source code
COPY . .
# Build the Titan app
RUN titan build --release
# ================================================================
# STAGE 2 โ Runtime
# ================================================================
FROM ubuntu:24.04
WORKDIR /app
# Minimal runtime deps
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates curl \
&& rm -rf /var/lib/apt/lists/*
# Create dedicated user
RUN groupadd -r titan && useradd -r -g titan titan
# Copy ALL contents from builder stage build/ directory to current WORKDIR
COPY --from=builder /app/build/ ./
# Map .ext into 'dist' and 'app' to satisfy all potential loader paths.
RUN ln -s /app/.ext /app/dist/.ext || true && \
ln -s /app/.ext /app/app/.ext || true
# Fix ownership
RUN chown -R titan:titan /app
# Environment variables
ENV HOST=0.0.0.0
ENV PORT=5100
ENV TITAN_DEV=0
# Help the dynamic linker find the .so files
ENV LD_LIBRARY_PATH=/app/.ext/@titanpl/core/native/target/release
USER titan
EXPOSE 5100
# Run the native server executable
CMD ["./titan-server", "run", "dist"]๐ก๏ธ Critical Security Checklist
Before deploying to production, ensure the following are correct:
1. tanfig.json Checklist
-
allowNativeonly contains extensions you trust. -
allowWasmis onlytrueif your extensions rely on it. - Your project
nameintanfig.jsonmatches the root configuration.
2. Engine Visibility
- Titan-native host processes run out-of-process for security. If you are using a firewall or restrictive OS policy, ensure IPC pipes from the engine to its spawned sub-processes are allowed.
๐ Execution in Production
Once your build/ folder is on the server, you can start it with zero external dependencies:
cd build
./titan-server run distZero-Downtime: Use a process manager like pm2 to monitor the titan-server binary and ensure it stays online during system reboots or crashes.
Summary
- Use
titan build --releasefor a self-contained production bundle. - Configure
tanfig.jsonfor custom assets and security permissions. - Deploy the
build/folder to any Linux or Windows server. - No Node.js runtime required on the server (just the binary).