Updated for nself v0.4.8
nself v0.4.7+ provides a comprehensive environment management system using the .environments/ directory structure. This enables you to maintain separate configurations for development, staging, and production with proper secrets management and SSH deployment.
nself supports three primary environments, each stored in its own directory:
Local development with debug tools, hot reloading, admin UI enabled, and relaxed security. Uses *.local.nself.org wildcard domains.
Production-like environment on a VPS for testing. Deploys full stack including frontends. Uses *.staging.yourdomain.com.
Live production with security hardening, admin UI disabled, and backend-only deployment. Frontends typically deployed separately via Vercel/CDN.
Each environment is stored in .environments/<name>/ with three files:
.environments/
├── dev/
│ ├── .env # Development configuration
│ ├── .env.secrets # Development secrets (git-ignored)
│ └── server.json # Local server config (optional)
├── staging/
│ ├── .env # Staging configuration
│ ├── .env.secrets # Staging secrets (git-ignored, chmod 600)
│ └── server.json # SSH connection details
└── prod/
├── .env # Production configuration
├── .env.secrets # Production secrets (git-ignored, chmod 600)
└── server.json # SSH connection detailsThe .env.secrets files are automatically set to chmod 600 and should never be committed to git. Add .environments/*/.env.secrets to your .gitignore.
# List all environments (active marked with *)
nself env list
# Output:
# * dev (active)
# staging
# prod# Switch to a different environment
nself env switch dev
nself env switch staging
nself env switch prod
# What happens:
# 1. Current .env files are backed up
# 2. Environment config is merged to .env.local
# 3. Current environment marker is updated# Create from template (local, staging, or prod)
nself env create dev
nself env create staging staging
nself env create prod prod
# Create QA environment from staging template
nself env create qa staging# Show current environment status
nself env status
# Show environment info
nself env info staging
# Compare two environments
nself env diff staging prod
nself env diff dev staging --values# Validate configuration before deployment
nself env validate
nself env validate staging
nself env validate prodContains non-sensitive environment configuration:
# .environments/staging/.env
ENV=staging
DEBUG=false
BASE_DOMAIN=staging.myapp.com
# Services
NSELF_ADMIN_ENABLED=false
MINIO_ENABLED=true
REDIS_ENABLED=true
MONITORING_ENABLED=true
# Database
POSTGRES_DB=myapp_stagingContains sensitive credentials (chmod 600, git-ignored):
# .environments/staging/.env.secrets
POSTGRES_PASSWORD=your-secure-password
HASURA_GRAPHQL_ADMIN_SECRET=your-admin-secret
JWT_SECRET=your-jwt-secret-at-least-32-characters
MINIO_ROOT_PASSWORD=your-minio-passwordContains SSH connection details for remote deployment:
{
"name": "staging",
"type": "staging",
"host": "staging.myapp.com",
"port": 22,
"user": "deploy",
"key": "~/.ssh/staging_key",
"deploy_path": "/opt/nself"
}# Generate secrets for an environment
nself staging secrets generate
nself prod secrets generate
# This creates secure random values for:
# - POSTGRES_PASSWORD
# - HASURA_GRAPHQL_ADMIN_SECRET
# - JWT_SECRET
# - MINIO_ROOT_PASSWORD
# - etc.# View secrets with masked values
nself env info staging
# Compare environments (values masked)
nself env diff staging prod --values# 1. Switch to dev environment
nself env switch dev
# 2. Build configuration
nself build
# 3. Start services locally
nself start
# 4. Check status
nself status
nself urls# 1. Check SSH access
nself deploy check-access
# 2. Preview deployment
nself staging deploy --dry-run
# 3. Deploy to staging (full stack including frontends)
nself staging deploy
# 4. Check health
nself deploy health staging# 1. Check SSH access
nself deploy check-access
# 2. Preview deployment
nself deploy prod --dry-run
# 3. Deploy to production (backend only - frontends on Vercel/CDN)
nself deploy prod
# 4. Check health
nself deploy health prod# Services enabled only in development
NSELF_ADMIN_ENABLED=true # Admin UI at admin.local.nself.org
MAILPIT_ENABLED=true # Email testing at mail.local.nself.org
SWAGGER_ENABLED=true # API documentation# Production security settings
NSELF_ADMIN_ENABLED=false # Admin UI DISABLED for security
MONITORING_ENABLED=true # Enable Prometheus/Grafana
SSL_MODE=letsencrypt # Real SSL certificatesWhen an environment is active, configuration loads in this order (later overrides earlier):
.env.dev - Base development config.environments/<name>/.env - Environment-specific config.env.local - Generated merged config.environments/<name>/.env.secrets - Secrets# Staging shortcuts
nself staging deploy # Deploy to staging
nself staging secrets generate # Generate staging secrets
# Production shortcuts
nself prod init myapp.com # Initialize production
nself prod check # Security audit
nself prod harden # Apply security hardening
nself prod ssl request # Request SSL certificate.environments/*/.env.secrets to .gitignorenself env validate.env files (not secrets) to git--dry-runnself deploy health# Test connectivity
nself deploy check-access
# Ensure SSH key is added to server
ssh-copy-id -i ~/.ssh/my_key user@server
# Test manual connection
ssh -i ~/.ssh/my_key user@server# Check what's missing
nself env validate staging
# Common fixes:
# - Missing .env.secrets: Run 'nself staging secrets generate'
# - Invalid server.json: Check host, port, user, key path
# - Missing required vars: Add to .env file# Check deployment logs
nself deploy logs
# Check server directly
ssh user@server "cd /opt/nself && docker compose logs"
# Verify services are running
ssh user@server "cd /opt/nself && docker compose ps"Proper environment management is crucial for reliable software delivery. Use the .environments/ structure to maintain clean separation between development, staging, and production configurations.