Skip to content

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

1 Commit

Folders and files

Repository files navigation

πŸ—οΈ template-infra

GitHub Template Repository β€” Use this template to create new infrastructure projects with pre-configured Docker, NGINX, and deployment automation.

Infrastructure-as-Code template by 7T providing production-ready Docker Compose configurations, NGINX reverse proxy with SSL, automated deployment with rollback support, and database backup management.

πŸ“‹ Table of Contents

✨ Features

  • Docker Compose β€” Multi-service orchestration (app, NGINX, database, Redis)
  • NGINX Reverse Proxy β€” TLS termination, rate limiting, gzip compression
  • Redis Cache β€” In-memory data store for caching and session management
  • Production Overrides β€” Resource limits, replicas, optimized DB settings
  • Deployment Automation β€” Zero-downtime deploys with health checks and rollback
  • SSL Management β€” Automated Let's Encrypt certificate renewal (30-day threshold)
  • Database Backups β€” Automated backups with configurable retention (minimum 7)
  • CI Pipeline β€” Docker Compose validation, ShellCheck, security checks
  • Health Checks β€” All services monitored at ≀30 second intervals

πŸ“ Project Structure

template-infra/
β”œβ”€β”€ docker-compose.yml          # Base service definitions (app, nginx, db, redis)
β”œβ”€β”€ docker-compose.prod.yml     # Production overrides
β”œβ”€β”€ .env.example                # Environment variable template
β”œβ”€β”€ nginx/
β”‚   β”œβ”€β”€ nginx.conf              # Main NGINX configuration
β”‚   β”œβ”€β”€ conf.d/
β”‚   β”‚   └── default.conf        # Server blocks and upstream config
β”‚   └── ssl/
β”‚       └── ssl-params.conf     # SSL/TLS parameters
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ deploy.sh               # Deployment with rollback support
β”‚   β”œβ”€β”€ backup.sh               # Database backup automation
β”‚   β”œβ”€β”€ restore.sh              # Database restore from backup
β”‚   └── ssl-renew.sh            # SSL certificate renewal
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── ci.yml              # CI pipeline (validate, lint, security)
β”œβ”€β”€ .gitignore
β”œβ”€β”€ LICENSE
└── README.md

πŸ”§ Prerequisites

πŸš€ Setup

1. Create from template

Click "Use this template" on GitHub or clone directly:

git clone https://github.com/7tteam/template-infra.git my-project-infra
cd my-project-infra

2. Configure environment

cp .env.example .env

Edit .env with your settings:

APP_NAME=my-service
APP_PORT=3000
DB_NAME=mydb
DB_USER=myuser
DB_PASSWORD=<secure-password>
DOMAIN=api.mydomain.com
SSL_EMAIL=admin@mydomain.com

3. Start services (development)

docker compose up -d

4. Verify services are running

docker compose ps
curl http://localhost/health

πŸ“– Usage

Development Mode

# Start all services
docker compose up -d

# View logs
docker compose logs -f

# Stop services
docker compose down

# Rebuild after changes
docker compose up -d --build

Production Mode

# Start with production overrides
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d

# Check service health
docker compose ps

Service Access

Service URL Description
Application http://localhost:3000 Direct app access
NGINX (HTTP) http://localhost:80 Reverse proxy
NGINX (HTTPS) https://localhost:443 SSL-terminated access
Database localhost:5432 PostgreSQL
Redis localhost:6379 Redis cache

🚒 Deployment

The deployment script supports zero-downtime deployments with automatic rollback on failure.

# Deploy to staging
./scripts/deploy.sh --env staging --version 1.2.0

# Deploy to production
./scripts/deploy.sh --env production --version 1.2.0

# Rollback to previous version
./scripts/deploy.sh --env production --rollback

Deployment Flow

  1. Pull latest images
  2. Start containers with new version
  3. Run health check (120s timeout)
  4. βœ… Success β†’ Save version, notify
  5. ❌ Failure β†’ Auto-rollback to previous version
  6. ❌ Rollback failure β†’ Halt pipeline, alert ops team

πŸ” SSL Certificates

Automated SSL certificate management using Let's Encrypt with 30-day renewal threshold.

# Check certificate status
./scripts/ssl-renew.sh --domain api.mydomain.com --check

# Renew certificate
./scripts/ssl-renew.sh --domain api.mydomain.com --email admin@mydomain.com

# Force renewal
./scripts/ssl-renew.sh --domain api.mydomain.com --force

Cron Setup (Automatic Renewal)

# Add to crontab - check daily at 3 AM
0 3 * * * /path/to/scripts/ssl-renew.sh --domain api.mydomain.com --email admin@mydomain.com

πŸ’Ύ Backups

Automated database backups with retention management and point-in-time restore.

# Create a full backup
./scripts/backup.sh --type full

# List available backups
./scripts/backup.sh --list

# Set custom retention (default: 7)
./scripts/backup.sh --type full --retain 14

Restoring from Backup

# List available backups
./scripts/restore.sh --list

# Restore from a specific backup file
./scripts/restore.sh --file backups/appdb_full_20240115_030000.sql.gz

# Restore to a specific database
./scripts/restore.sh --file backups/appdb_full_20240115_030000.sql.gz --db mydb

# Skip safety backup before restore
./scripts/restore.sh --file backups/appdb_full_20240115_030000.sql.gz --no-safety

Cron Setup (Automated Daily Backups)

# Daily backup at midnight
0 0 * * * /path/to/scripts/backup.sh --type full --retain 7

πŸ”„ CI/CD

The CI pipeline runs on every push and pull request:

  1. Validate β€” Docker Compose configuration syntax check
  2. ShellCheck β€” Lint all shell scripts for best practices
  3. Security β€” Scan for hardcoded secrets in config files

πŸ“ Template Usage

This repository is a GitHub Template. To create a new infrastructure project:

  1. Click the "Use this template" button at the top of the repository page
  2. Name your new repository and select visibility
  3. Clone the new repository locally
  4. Copy .env.example to .env and configure for your environment
  5. Update nginx/conf.d/default.conf with your upstream services
  6. Customize docker-compose.yml services for your stack
  7. Run docker compose up -d to verify everything works

Customization Guide

  • Add services: Edit docker-compose.yml to add Redis, Elasticsearch, etc.
  • Modify proxy rules: Update nginx/conf.d/default.conf with routing rules
  • Adjust resources: Edit docker-compose.prod.yml for production limits
  • Change database: Swap PostgreSQL image/config for MySQL, MongoDB, etc.

🀝 Contributing

Please see our Contributing Guidelines for details on how to contribute to this project.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❀️ by 7T

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages