Skip to content

Repository files navigation

πŸš€ CI/CD Deployment Strategies

A comprehensive collection of production-ready CI/CD deployment strategies for Next.js applications on VPS servers. Each strategy is battle-tested, secure, and optimized for different use cases.

πŸ“š Table of Contents

🎯 Quick Start

Choose the deployment strategy that fits your needs:

Strategy Best For Setup Time Link
Version 1 Simple apps, fast deployments ⚑ 5 min v1-do-rsync-pm2
Version 1.5 Mission-critical apps, instant rollbacks ⚑ 5 min v1.5-do-rsync-atomic-pm2
Version 2 Teams preferring Git-based workflows ⚑ 10 min v2-do-git-pm2

πŸ“¦ Deployment Strategies Overview

Version 1: Rsync + PM2 Cluster

Strategy: Build on CI β†’ Rsync artifacts β†’ PM2 zero-downtime reload

  • βœ… Fastest deployment (no server-side build)
  • βœ… Minimal server footprint (no source code on server)
  • βœ… Zero downtime with PM2 cluster mode
  • βœ… PR preview deployments support
  • βœ… Staging environments support

Use when: You want the fastest, simplest deployment with maximum security.

πŸ“– Full Documentation


Version 1.5: Atomic Deployment (Rsync + Symlink)

Strategy: Build on CI β†’ Upload to timestamped release β†’ Atomic symlink switch

  • βœ… Instant rollbacks (no rebuild needed)
  • βœ… Partial failure protection (incomplete uploads don't break site)
  • βœ… Release history (keep last 5 releases)
  • βœ… Zero downtime deployments
  • βœ… PR preview deployments support
  • βœ… Staging environments support

Use when: You need instant rollback capability and maximum reliability.

πŸ“– Full Documentation


Version 2: Git Pull + Server Build

Strategy: GitHub Action triggers β†’ Server pulls code β†’ Server builds app

  • βœ… Familiar Git workflow
  • βœ… No artifact management needed
  • βœ… Server-side builds (good for large monorepos)
  • βœ… Automatic dependency updates

Use when: You prefer Git-based workflows and have sufficient server resources.

πŸ“– Full Documentation


πŸ” Strategy Comparison

Security Comparison

Feature Version 1 Version 1.5 Version 2
Source Code on Server ❌ No ❌ No ⚠️ Yes
SSH Key-Based Auth βœ… Yes βœ… Yes βœ… Yes
Restricted Deploy User βœ… Yes βœ… Yes βœ… Yes
Minimal Attack Surface βœ… Highest βœ… Highest ⚠️ Medium
Secrets Isolation βœ… Build-time βœ… Build-time ⚠️ Server-side

Winner: Version 1 & 1.5 (no source code on server)

Speed Comparison

Metric Version 1 Version 1.5 Version 2
Deployment Time ⚑ ~30s ⚑ ~35s 🐒 ~2-5 min
Build Location CI/CD CI/CD Server
Network Transfer Small artifacts Small artifacts Full repo
Server CPU Usage Minimal Minimal High (build)

Winner: Version 1 (fastest), Version 1.5 (slightly slower due to release management)

Reliability Comparison

Feature Version 1 Version 1.5 Version 2
Rollback Speed 🐒 Rebuild required ⚑ Instant (symlink) 🐒 Rebuild required
Partial Failure Protection ⚠️ Medium βœ… High ⚠️ Medium
Release History ❌ No βœ… Yes (5 releases) ❌ No
Zero Downtime βœ… Yes βœ… Yes βœ… Yes

Winner: Version 1.5 (best reliability and rollback capability)

Resource Usage

Resource Version 1 Version 1.5 Version 2
Server RAM Low Low High (builds)
Server Disk Low Medium (releases) Medium
Server CPU Low Low High (builds)
CI/CD Minutes Medium Medium Low

Winner: Version 1 (lowest resource usage)

Feature Comparison

Feature Version 1 Version 1.5 Version 2
PR Preview Deployments βœ… Yes (single) βœ… Yes (single) ❌ No
PR Preview (Monorepo) ⚠️ Not implemented ⚠️ Not implemented ❌ No
Staging Environments βœ… Yes (single) βœ… Yes (single) ❌ No
Staging (Monorepo) ⚠️ Not implemented ⚠️ Not implemented ❌ No
Wildcard SSL Support βœ… Yes βœ… Yes ❌ No
Monorepo Support βœ… Yes βœ… Yes ❌ No
Git Pull Monorepo ❌ N/A ❌ N/A ❌ Not implemented

Winner: Version 1 & 1.5 (most features, but monorepo preview/staging missing)

⚠️ Note: PR preview and staging support for monorepos is planned but not yet implemented. See TODO.md for details.

🏰 Monorepo Support

Both Version 1 and Version 1.5 support monorepo deployments with:

  • Path-based filtering (only deploy changed apps)
  • Multiple apps on one server (isolated ports and PM2 processes)
  • Independent deployments per app
  • Shared preview infrastructure (one wildcard SSL cert)

πŸ“– Monorepo Documentation - Version 1
πŸ“– Monorepo Documentation - Version 1.5

✨ Features

All strategies support:

  • βœ… Zero-downtime deployments with PM2
  • βœ… Cluster mode for maximum performance
  • βœ… SSH key-based authentication
  • βœ… Restricted deploy users
  • βœ… Nginx reverse proxy configuration
  • βœ… SSL certificate setup (Let's Encrypt)
  • βœ… Firewall configuration (UFW)
  • βœ… Automatic PM2 process management

Version 1 & 1.5 additionally support:

  • βœ… PR preview deployments (dynamic ports 8500-8999)
  • βœ… Staging environments
  • βœ… Wildcard SSL certificates (DigitalOcean & Cloudflare)
  • βœ… Dynamic Nginx routing based on hostname

βœ… Testing Status

Version 1: Rsync + PM2 Cluster

  • Single app deployment tested
  • Monorepo deployment tested
  • PR preview deployment tested
  • Staging deployment tested
  • Rollback procedure tested
  • SSL certificate renewal tested
  • PM2 cluster mode verified
  • Zero-downtime deployment verified
  • Multi-region deployment tested
  • Load testing performed

Version 1.5: Atomic Deployment

  • Single app deployment tested
  • Monorepo deployment tested
  • PR preview deployment tested
  • Staging deployment tested
  • Instant rollback tested
  • Partial failure recovery tested
  • Release cleanup verified
  • SSL certificate renewal tested
  • Zero-downtime deployment verified
  • Multi-region deployment tested
  • Load testing performed

Version 2: Git Pull + Server Build

  • Single app deployment tested
  • Monorepo deployment tested
  • PR preview deployment tested (⚠️ Not implemented)
  • Staging deployment tested (⚠️ Not implemented)
  • Build failure recovery tested
  • Swap space handling verified
  • Large repo performance tested
  • SSL certificate renewal tested
  • Zero-downtime deployment verified
  • Multi-region deployment tested
  • Load testing performed

Monorepo Versions

Version 1 Monorepo

  • Multi-app deployment tested
  • Path-based filtering verified
  • PR preview deployment tested (⚠️ Not implemented)
  • Staging deployment tested (⚠️ Not implemented)
  • Independent app deployments verified
  • Port isolation tested

Version 1.5 Monorepo

  • Multi-app deployment tested
  • Path-based filtering verified
  • PR preview deployment tested (⚠️ Not implemented)
  • Staging deployment tested (⚠️ Not implemented)
  • Independent app deployments verified
  • Atomic rollback per app tested
  • Port isolation tested

πŸ—ΊοΈ Roadmap

⚠️ Missing Features (High Priority)

These features are currently missing and should be prioritized:

PR Preview & Staging Support

  • PR Preview for Monorepos

    • Version 1 monorepo PR preview workflows
    • Version 1.5 monorepo PR preview workflows
    • Per-app preview deployments in monorepo
    • Preview cleanup automation
  • Staging for Monorepos

    • Version 1 monorepo staging workflows
    • Version 1.5 monorepo staging workflows
    • Per-app staging environments
  • Version 2 (Git Pull) Missing Features

    • PR preview deployment support
    • Staging deployment support
    • Wildcard SSL certificate setup
    • Dynamic Nginx routing for previews
  • Git Pull Monorepo Support

    • Complete monorepo setup script for Git Pull
    • Path-based filtering for Git Pull
    • Multiple apps on one server (Git Pull)
    • PR preview for Git Pull monorepo
    • Staging for Git Pull monorepo

πŸ“‹ See TODO.md for detailed tracking of all missing features and implementation details.

Planned Features

Containerization & Orchestration

  • Docker Support

    • Dockerfile templates for Next.js apps
    • Docker Compose setup for local development
    • Docker-based deployment workflows
    • Multi-stage builds optimization
    • Container registry integration (Docker Hub, GitHub Container Registry)
  • Kubernetes Support

    • Kubernetes manifests (Deployment, Service, Ingress)
    • Helm charts for easy deployment
    • Kubernetes deployment workflows
    • Horizontal Pod Autoscaling (HPA)
    • Rolling update strategies
    • ConfigMap and Secret management
    • Service mesh integration (Istio/Linkerd)
  • Container Orchestration Alternatives

    • Docker Swarm setup
    • Nomad deployment strategies
    • ECS/EKS deployment guides

Autoscaling & High Availability

  • Horizontal Autoscaling

    • PM2-based autoscaling configuration
    • Load balancer setup (Nginx, HAProxy)
    • Multi-server deployment strategies
    • Health check endpoints
    • Auto-scaling based on CPU/memory metrics
  • Vertical Autoscaling

    • Dynamic resource allocation
    • Memory optimization strategies
    • CPU optimization strategies
  • High Availability

    • Multi-region deployment guides
    • Database replication strategies
    • Session management across servers
    • Failover mechanisms
    • Disaster recovery procedures

Advanced CI/CD Features

  • PR Preview Deployments - Missing Implementations

    • PR preview support for monorepo (Version 1)
    • PR preview support for monorepo (Version 1.5)
    • PR preview support for Version 2 (Git Pull)
    • PR preview cleanup automation (remove old previews)
    • PR preview comment updates with deployment status
    • Preview deployment health checks
  • Staging Deployments - Missing Implementations

    • Staging support for monorepo (Version 1)
    • Staging support for monorepo (Version 1.5)
    • Staging support for Version 2 (Git Pull)
    • Staging environment management
    • Staging to production promotion workflow
  • Version 2 (Git Pull) Enhancements

    • PR preview deployments for Git Pull strategy
    • Staging deployments for Git Pull strategy
    • Wildcard SSL support for Git Pull strategy
    • Monorepo support for Git Pull strategy
    • Path-based filtering for monorepo Git Pull
    • Multiple apps on one server (Git Pull)
  • Monorepo Enhancements

    • PR preview deployments (Version 1 monorepo)
    • PR preview deployments (Version 1.5 monorepo)
    • Staging deployments (Version 1 monorepo)
    • Staging deployments (Version 1.5 monorepo)
    • Cross-app dependency handling
    • Shared package deployment strategies
  • Multi-Environment Support

    • Development environment setup
    • QA environment automation
    • Production environment strategies
    • Environment-specific configurations
  • Advanced Deployment Strategies

    • Blue-Green deployments
    • Canary deployments
    • Feature flag integration
    • A/B testing infrastructure
  • Monitoring & Observability

    • Application performance monitoring (APM)
    • Log aggregation (ELK, Loki)
    • Metrics collection (Prometheus, Grafana)
    • Error tracking (Sentry, Rollbar)
    • Uptime monitoring
    • Real-time alerting
  • Security Enhancements

    • Automated security scanning
    • Dependency vulnerability checks
    • Secrets management (Vault, AWS Secrets Manager)
    • WAF (Web Application Firewall) integration
    • DDoS protection setup
    • Rate limiting strategies

Cloud Platform Integrations

  • AWS

    • EC2 deployment guides
    • ECS/EKS integration
    • Lambda@Edge for edge functions
    • CloudFront CDN integration
    • Route53 DNS management
  • Google Cloud Platform

    • Compute Engine deployment
    • GKE (Kubernetes Engine) integration
    • Cloud Run serverless option
    • Cloud CDN integration
  • Azure

    • Azure VM deployment
    • AKS (Azure Kubernetes Service) integration
    • Azure Container Instances
    • Azure CDN integration
  • DigitalOcean

    • Droplet deployment optimization
    • Kubernetes integration
    • App Platform integration
    • Spaces (S3-compatible) integration
  • Cloudflare

    • Workers deployment
    • Pages integration
    • Tunnel setup for secure connections
    • DDoS protection configuration

Performance Optimizations

  • CDN Integration

    • Cloudflare CDN setup
    • CloudFront configuration
    • Static asset optimization
    • Edge caching strategies
  • Caching Strategies

    • Redis caching setup
    • Memcached integration
    • Application-level caching
    • Database query caching
  • Database Optimization

    • Connection pooling
    • Read replicas setup
    • Database migration strategies
    • Backup and restore procedures

Developer Experience

  • Local Development

    • Docker Compose for local stack
    • Development environment automation
    • Hot reload configurations
    • Local SSL certificate setup
  • Testing Integration

    • Unit test integration
    • E2E test automation
    • Performance testing
    • Security testing automation
  • Documentation

    • API documentation generation
    • Architecture diagrams
    • Troubleshooting guides
    • Video tutorials

🀝 Contributing

We welcome contributions! This project aims to provide the best CI/CD strategies for Next.js applications.

Please read our Contributing Guide for detailed information on how to contribute.

Quick Start

  1. Fork the repository
  2. Read CONTRIBUTING.md
  3. Create a feature branch (git checkout -b feature/amazing-feature)
  4. Make your changes following our coding standards
  5. Test thoroughly using our testing guidelines
  6. Commit your changes following our commit message format
  7. Push and create a Pull Request

Code of Conduct

This project follows a Code of Conduct that all contributors are expected to follow. Please read it before contributing.

Areas Needing Contributions

We especially welcome contributions in:

  • 🐳 Docker & Kubernetes implementations
  • πŸ“Š Monitoring & Observability setups
  • πŸ”’ Security enhancements and best practices
  • ⚑ Performance optimizations
  • πŸ“ Documentation improvements
  • πŸ§ͺ Testing and test automation
  • 🌍 Multi-region deployment strategies
  • πŸ“ˆ Autoscaling configurations
  • πŸ”„ Advanced deployment strategies (blue-green, canary)

πŸ“„ License

This project is open source and available under the MIT License.

πŸ™ Acknowledgments

  • PM2 team for the excellent process manager
  • Next.js team for the standalone output feature
  • Let's Encrypt for free SSL certificates
  • All contributors who help improve these deployment strategies

Need Help? Check the individual strategy READMEs or open an issue for support.

Found a Bug? Please report it so we can fix it for everyone!

Have an Idea? We'd love to hear it! Open an issue or start a discussion.

About

Production-ready CI/CD deployment strategies for Next.js/Node.js apps on VPS. Rsync, Atomic, Git Pull with PM2, PR previews, staging, monorepo support.

Topics

Resources

Code of conduct

Contributing

Stars

2 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages