Skip to main content

Deployment Flow

Lightfold uses a composable, idempotent deployment architecture where each step is independent and can be run standalone or orchestrated together.

Orchestrated Deployment

The lightfold deploy command chains all steps automatically:
What happens:
1

Framework Detection

Analyzes project structure to identify framework and package manager.Supports 15+ frameworks including Next.js, Django, Rails, Laravel, and more.
2

Infrastructure Creation

Creates server infrastructure if not already created.
  • Auto-provision mode: Creates VM on cloud provider (DigitalOcean, Vultr, Hetzner)
  • BYOS mode: Validates SSH access to existing server
Marks target as “created” in local state.
3

Server Configuration

Configures server if not already configured.
  • Installs runtime dependencies
  • Sets up systemd services
  • Configures nginx reverse proxy
  • Creates deployment directory structure
Writes /etc/lightfold/configured marker on server.
4

Code Deployment

Deploys code changes using blue/green deployment.
  • Checks git commit vs. last deployed commit
  • Creates timestamped release: /srv/<app>/releases/<timestamp>/
  • Uploads tarball and builds project
  • Swaps symlink /srv/<app>/current with health checks
  • Auto-rollback on failure

Manual Steps

You can run each step independently for granular control:

Idempotency

Lightfold is designed to be safe to rerun. Each step checks state before executing.

State Tracking

Local State (~/.lightfold/state/<target>.json):
Remote Markers (on server):
  • /etc/lightfold/created - Written by create command
  • /etc/lightfold/configured - Written by configure command

Smart Skipping

Commands automatically skip completed steps:
  • create - Skips if already created
  • configure - Skips if /etc/lightfold/configured exists
  • push - Skips if git commit unchanged
  • deploy - Skips all completed steps
Use --force to override and rerun steps.

Builder System

Lightfold supports multiple build strategies:

Native Builder

Traditional approach using framework detection + nginx.
  • Uses framework-specific build commands
  • Serves static files with nginx
  • Runs app with systemd service

Nixpacks Builder

Railway’s Nixpacks for auto-detected builds.
  • Auto-detects runtime and dependencies
  • Generates optimized Docker container
  • No Dockerfile required

Dockerfile Builder

Uses your existing Dockerfile (coming soon).

Auto-Selection

Lightfold automatically selects the best builder:
  1. If Dockerfile exists → dockerfile
  2. If Node/Python + nixpacks available → nixpacks
  3. Otherwise → native
Override with --builder flag:

Blue/Green Deployment

Lightfold uses blue/green deployment for zero-downtime releases:
1

Create new release

Creates timestamped directory: /srv/<app>/releases/20251003103000/
2

Build application

Uploads code, installs dependencies, runs build commands.
3

Health check

Starts new release and runs health checks.
4

Swap symlink

Atomically updates /srv/<app>/current symlink to new release.
5

Cleanup

Keeps last 5 releases, removes older ones.
On failure: Automatically rolls back to previous release.

Rollback

Instant rollback to previous release:
Swaps symlink back to previous release directory.

Custom Domains & SSL

Add custom domain with automatic Let’s Encrypt SSL:
What happens:
  1. Prompts for SSL enable (default: yes)
  2. Installs certbot if needed
  3. Issues Let’s Encrypt certificate
  4. Configures nginx with domain + HTTPS
  5. Sets up auto-renewal
  6. Updates target config
Remove domain:

State Recovery

If local state gets corrupted or server IP changes, use sync:
Sync operations:
  • Recovers server IP from provider API
  • Verifies SSH connectivity
  • Syncs remote markers (created, configured)
  • Updates deployment info (current release, git commit)
  • Checks service status

Environment Variables

Set environment variables in config:
Or use .env file in project root (automatically loaded).

Multi-Target Deployments

Deploy the same project to multiple environments:
Each target has independent configuration and state.

Deployment Tips

First deployment installs all dependencies and configures the server. Subsequent deployments are much faster due to idempotency.
Use --force to rerun steps:
Check application logs:
View detailed status:
Access server directly: