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.
- Features
- Project Structure
- Prerequisites
- Setup
- Usage
- Deployment
- SSL Certificates
- Backups
- CI/CD
- Template Usage
- Contributing
- License
- 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
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
- Docker (v20.10+)
- Docker Compose (v2.0+)
- Bash (v4.0+) for scripts
- curl for health checks
- (Optional) ShellCheck for script linting
Click "Use this template" on GitHub or clone directly:
git clone https://github.com/7tteam/template-infra.git my-project-infra
cd my-project-infracp .env.example .envEdit .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.comdocker compose up -ddocker compose ps
curl http://localhost/health# 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# Start with production overrides
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
# Check service health
docker compose ps| 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 |
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- Pull latest images
- Start containers with new version
- Run health check (120s timeout)
- β Success β Save version, notify
- β Failure β Auto-rollback to previous version
- β Rollback failure β Halt pipeline, alert ops team
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# Add to crontab - check daily at 3 AM
0 3 * * * /path/to/scripts/ssl-renew.sh --domain api.mydomain.com --email admin@mydomain.comAutomated 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# 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# Daily backup at midnight
0 0 * * * /path/to/scripts/backup.sh --type full --retain 7The CI pipeline runs on every push and pull request:
- Validate β Docker Compose configuration syntax check
- ShellCheck β Lint all shell scripts for best practices
- Security β Scan for hardcoded secrets in config files
This repository is a GitHub Template. To create a new infrastructure project:
- Click the "Use this template" button at the top of the repository page
- Name your new repository and select visibility
- Clone the new repository locally
- Copy
.env.exampleto.envand configure for your environment - Update
nginx/conf.d/default.confwith your upstream services - Customize
docker-compose.ymlservices for your stack - Run
docker compose up -dto verify everything works
- Add services: Edit
docker-compose.ymlto add Redis, Elasticsearch, etc. - Modify proxy rules: Update
nginx/conf.d/default.confwith routing rules - Adjust resources: Edit
docker-compose.prod.ymlfor production limits - Change database: Swap PostgreSQL image/config for MySQL, MongoDB, etc.
Please see our Contributing Guidelines for details on how to contribute to this project.
This project is licensed under the MIT License - see the LICENSE file for details.
Built with β€οΈ by 7T