DEV Community

DeployHQ
DeployHQ

Posted on • Originally published at deployhq.com on

Implementing 12-Factor App Methodology with DeployHQ

The 12-Factor App methodology has become the gold standard for building modern, scalable, and maintainable web applications. These twelve principles provide a framework for creating applications that are portable, resilient, and ready for continuous deployment. In this comprehensive guide, we'll explore how DeployHQ's powerful deployment platform can help you implement each of the 12 factors effectively.

What is the 12-Factor App Methodology?

The 12-Factor App is a methodology for building software-as-a-service applications that emphasizes:

  • Portability across execution environments
  • Scalability without significant architectural changes
  • Continuous deployment for maximum development agility
  • Minimal divergence between development and production environments

Let's dive into how DeployHQ supports each factor.


I. Codebase: One Codebase Tracked in Revision Control

The Factor: One codebase tracked in revision control, many deploys.

DeployHQ Implementation:

DeployHQ excels at this fundamental requirement by supporting multiple version control systems including Git, SVN, and Mercurial. The platform integrates seamlessly with popular repositories like GitHub, GitLab, and Bitbucket.

Key Features:

  • Multi-repository support : Connect projects from GitHub, GitLab, Bitbucket, or self-hosted repositories
  • Branch-specific deployments : Configure different servers to deploy from specific branches (development, staging, production)
  • Single source of truth : One codebase can be deployed to multiple environments with different configurations

Best Practice with DeployHQ: Set up separate server configurations for each environment, all pointing to the same repository but potentially different branches:

  • Development server: develop branch
  • Staging server: release branch
  • Production server: main branch

II. Dependencies: Explicitly Declare and Isolate Dependencies

The Factor: Explicitly declare and isolate dependencies.

DeployHQ Implementation:

DeployHQ's build pipeline system allows you to manage dependencies consistently across all deployments through custom build environments and automated dependency installation.

Key Features:

  • Custom build environments : Configure specific versions of Ruby, PHP, Node.js, Java, and other tools
  • Build pipeline commands : Automate dependency installation with commands like npm install, composer install, or bundle install
  • Consistent environments : Ensure the same dependency versions across all deployments

Example Build Pipeline Configuration:

# Install Ruby dependencies
bundle install --deployment --without development test

# Install Node.js dependencies  
npm ci --production

# Compile assets
npm run build:production

Enter fullscreen mode Exit fullscreen mode

III. Config: Store Configuration in the Environment

The Factor: Store config in the environment.

DeployHQ Implementation:

While DeployHQ doesn't currently offer built-in environment variable management per server, it provides robust configuration management through config files and deployment variables.

Key Features:

  • Config files : Store sensitive configuration separate from your codebase
  • Environment-specific variables : Use variables like %environment%, %branch%, and %deployment_url%
  • Secure configuration management : Keep sensitive data out of version control

Implementation Strategy: Create environment-specific config files in DeployHQ:

# config/database.yml (managed through DeployHQ config files)
production:
  adapter: postgresql
  host: %database_host%
  database: myapp_%environment%
  username: %database_user%
  password: %database_password%

Enter fullscreen mode Exit fullscreen mode

Pro Tip: Use DeployHQ's config file feature combined with server-specific environment settings to maintain configuration separation while leveraging the platform's deployment capabilities.


IV. Backing Services: Treat Backing Services as Attached Resources

The Factor: Treat backing services as attached resources.

DeployHQ Implementation:

DeployHQ supports this factor through its flexible configuration system and integration capabilities, allowing you to easily switch between different backing services across environments.

Key Features:

  • Environment-specific configurations : Different database, cache, or API configurations per environment
  • SSH command integration : Run commands to configure or migrate backing services during deployment
  • Config file flexibility : Store different service endpoints for each environment

Example Implementation:

# SSH commands in DeployHQ to handle database migrations
rails db:migrate RAILS_ENV=%environment%

# Service health checks
curl -f http://%service_endpoint%/health || exit 1

Enter fullscreen mode Exit fullscreen mode

V. Build, Release, Run: Strictly Separate Build and Run Stages

The Factor: Strictly separate build, release, and run stages.

DeployHQ Implementation:

DeployHQ's deployment pipeline naturally enforces this separation with distinct build and deployment phases.

The Three Stages in DeployHQ:

  1. Build Stage :

  2. Release Stage :

  3. Run Stage :

Build Pipeline Example:

# Build stage commands
npm run test
npm run build:production
composer install --no-dev --optimize-autoloader

# The release stage is handled automatically by DeployHQ
# Run stage begins with atomic deployment

Enter fullscreen mode Exit fullscreen mode

VI. Processes: Execute the App as One or More Stateless Processes

The Factor: Execute the app as one or more stateless processes.

DeployHQ Implementation:

DeployHQ supports stateless application deployment through its atomic deployment process and server configuration options.

Key Features:

  • Atomic deployments : Ensure clean process restarts
  • Multiple server support : Deploy to multiple application servers
  • Process management : Use SSH commands to restart application processes
  • Session storage : Configure external session storage through config files

Implementation Example:

# SSH commands to restart application processes
sudo systemctl restart nginx
sudo systemctl restart app-worker
sudo php-fpm reload

# Clear application caches
php artisan cache:clear

Enter fullscreen mode Exit fullscreen mode

VII. Port Binding: Export Services via Port Binding

The Factor: Export services via port binding.

DeployHQ Implementation:

DeployHQ supports port binding configuration through its flexible server setup and configuration management.

Key Features:

  • Server-specific configurations : Configure different ports for different environments
  • Load balancer support : Deploy to multiple servers behind load balancers
  • Environment variables : Use port configuration in config files

Configuration Example:

# Nginx configuration managed through DeployHQ config files
server {
    listen %app_port%;
    server_name %server_name%;

    location / {
        proxy_pass http://localhost:%internal_app_port%;
    }
}

Enter fullscreen mode Exit fullscreen mode

VIII. Concurrency: Scale Out via the Process Model

The Factor: Scale out via the process model.

DeployHQ Implementation:

DeployHQ facilitates horizontal scaling through its multi-server deployment capabilities and process management features.

Key Features:

  • Server groups : Deploy to multiple servers simultaneously
  • Load balancer integration : Support for various hosting platforms
  • Process management : Configure different process types through SSH commands
  • Environment-specific scaling : Different server configurations per environment

Scaling Strategy:

# SSH commands to manage different process types
sudo systemctl start app-web@{1..4} # Web processes
sudo systemctl start app-worker@{1..2} # Background workers  
sudo systemctl start app-scheduler # Cron processes

Enter fullscreen mode Exit fullscreen mode

IX. Disposability: Maximize Robustness with Fast Startup and Graceful Shutdown

The Factor: Maximize robustness with fast startup and graceful shutdown.

DeployHQ Implementation:

DeployHQ's atomic deployment system inherently supports disposability by ensuring clean, predictable deployments.

Key Features:

  • Atomic deployments : All-or-nothing deployment approach
  • Zero-downtime deployments : Graceful process switching
  • Rollback capabilities : Quick recovery from failed deployments
  • Health checks : Verify application health before completion

Implementation:

# Graceful shutdown commands
sudo systemctl reload nginx # Graceful reload
pkill -TERM -f "app-worker" # Graceful worker shutdown

# Health check before completing deployment
curl -f http://localhost/health || exit 1

Enter fullscreen mode Exit fullscreen mode

X. Dev/Prod Parity: Keep Development, Staging, and Production as Similar as Possible

The Factor: Keep development, staging, and production as similar as possible.

DeployHQ Implementation:

DeployHQ excels at maintaining environment parity through consistent deployment processes and configuration management.

Key Features:

  • Consistent build process : Same build pipeline across all environments
  • Environment-specific configurations : Maintain same structure, different values
  • Branch-based deployments : Similar code paths with environment-appropriate branches
  • Identical deployment process : Same steps across all environments

Best Practices:

  • Use the same build pipeline commands across environments
  • Maintain similar server configurations with environment-specific values
  • Deploy frequently to reduce drift between environments
  • Use feature flags for environment-specific functionality

XI. Logs: Treat Logs as Event Streams

The Factor: Treat logs as event streams.

DeployHQ Implementation:

While DeployHQ doesn't provide log aggregation directly, it supports log management through deployment integration and monitoring setup.

Key Features:

  • Deployment logging : Comprehensive deployment logs and history
  • SSH command integration : Set up log forwarding during deployment
  • Integration support : Connect with log management services
  • Build pipeline logging : Detailed build and deployment process logs

Log Management Setup:

# Configure log forwarding during deployment
echo "*.* @@logs.example.com:514" >> /etc/rsyslog.conf
systemctl restart rsyslog

# Set up log rotation
logrotate -f /etc/logrotate.conf

Enter fullscreen mode Exit fullscreen mode

XII. Admin Processes: Run Admin/Management Tasks as One-off Processes

The Factor: Run admin/management tasks as one-off processes.

DeployHQ Implementation:

DeployHQ supports admin processes through its SSH command system and flexible deployment configuration.

Key Features:

  • SSH commands : Run one-off administrative tasks during deployment
  • Manual deployment triggers : Execute admin processes on-demand
  • Environment-specific commands : Different admin tasks per environment
  • Safe execution : Run admin processes in the same environment as the application

Admin Task Examples:

# Database migrations
rails db:migrate RAILS_ENV=%environment%

# Cache warming
php artisan cache:warm

# Data cleanup tasks
python manage.py cleanup_old_data --days=30

# Search index rebuilding  
php artisan scout:import "App\\Models\\Product"

Enter fullscreen mode Exit fullscreen mode

Bringing It All Together: A Complete 12-Factor Deployment with DeployHQ

Here's how a complete 12-factor application deployment looks in DeployHQ:

1. Project Setup

  • Connect your Git repository (Factor I: Codebase)
  • Configure build pipeline for dependency management (Factor II: Dependencies)

2. Environment Configuration

  • Set up config files for each environment (Factor III: Config)
  • Configure backing service endpoints (Factor IV: Backing Services)

3. Deployment Pipeline

  • Build pipeline handles compilation and testing (Factor V: Build/Release/Run)
  • Atomic deployments ensure clean releases (Factor VI: Processes)

4. Server Configuration

  • Configure port bindings and server settings (Factor VII: Port Binding)
  • Set up server groups for scaling (Factor VIII: Concurrency)

5. Deployment Process

  • Zero-downtime deployments support disposability (Factor IX: Disposability)
  • Consistent process across environments (Factor X: Dev/Prod Parity)

6. Operations

  • Comprehensive deployment logging (Factor XI: Logs)
  • SSH commands for admin processes (Factor XII: Admin Processes)

Conclusion

DeployHQ provides a robust platform for implementing 12-Factor App methodology, offering the tools and flexibility needed to build scalable, maintainable applications. While some factors require additional tooling (like dedicated environment variable management or log aggregation services), DeployHQ's core features align well with 12-factor principles.

The platform's strength lies in its simplicity and reliability, making it easier for teams to adopt 12-factor practices without overwhelming complexity. By leveraging DeployHQ's build pipelines, atomic deployments, configuration management, and multi-environment support, you can create a deployment process that embodies the best practices of modern application development.

Ready to implement 12-factor principles in your applications? Start your DeployHQ free trial today and experience how streamlined deployments can transform your development workflow.


Want to learn more about specific 12-factor implementations with DeployHQ? Check out our detailed guides and documentation, or reach out to our support team for personalized assistance with your deployment strategy.

Top comments (0)