feat: comprehensive project structure improvements and Cloud for Sovereignty landing zone

- Add Cloud for Sovereignty landing zone architecture and deployment
- Implement complete legal document management system
- Reorganize documentation with improved navigation
- Add infrastructure improvements (Dockerfiles, K8s, monitoring)
- Add operational improvements (graceful shutdown, rate limiting, caching)
- Create comprehensive project structure documentation
- Add Azure deployment automation scripts
- Improve repository navigation and organization
This commit is contained in:
defiQUG
2025-11-13 09:32:55 -08:00
parent 92cc41d26d
commit 6a8582e54d
202 changed files with 22699 additions and 981 deletions

80
scripts/README.md Normal file
View File

@@ -0,0 +1,80 @@
# Scripts Directory
**Last Updated**: 2025-01-27
**Purpose**: Utility scripts for development, deployment, and operations
## Overview
This directory contains utility scripts organized by purpose.
## Script Categories
### Deployment (`deploy/`)
- Azure deployment scripts
- CDN setup scripts
- Seal deployment scripts
- Monitoring setup
### Development (`dev/`)
- Development environment setup
- Docker Compose configurations
- Local service management
### Backup (`backup/`)
- Database backup scripts
- Automated backup procedures
### Security (`security/`)
- Security scanning automation
- Vulnerability assessment
- Compliance checking
### Infrastructure (`infra/scripts/`)
- Azure infrastructure scripts
- Terraform automation
- Environment management
## Usage
### Development Setup
```bash
./scripts/dev/setup-dev.sh
```
### Azure Deployment
```bash
source infra/scripts/azure-load-env.sh
./infra/scripts/azure-deploy.sh
```
### Security Scanning
```bash
./scripts/security/security-scan.sh
```
### Database Backup
```bash
./scripts/backup/database-backup.sh
```
## Script Organization
```
scripts/
├── README.md # This file
├── deploy/ # Deployment scripts
├── dev/ # Development scripts
├── backup/ # Backup scripts
└── security/ # Security scripts
```
## Related Documentation
- [Deployment Guides](../docs/deployment/)
- [Development Guide](../QUICKSTART.md)
- [Infrastructure Scripts](../infra/scripts/)
---
**Last Updated**: 2025-01-27

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Automated database backup script
# Supports full and incremental backups
set -e
BACKUP_DIR="${BACKUP_DIR:-/backups}"
DB_NAME="${DB_NAME:-theorder}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_TYPE="${1:-full}" # full or incremental
echo "📦 Starting database backup (type: $BACKUP_TYPE)..."
mkdir -p "$BACKUP_DIR"
if [ "$BACKUP_TYPE" = "full" ]; then
BACKUP_FILE="$BACKUP_DIR/full_backup_${TIMESTAMP}.sql.gz"
echo "Creating full backup..."
pg_dump "$DATABASE_URL" | gzip > "$BACKUP_FILE"
echo "✅ Full backup created: $BACKUP_FILE"
# Keep only last 7 full backups
ls -t "$BACKUP_DIR"/full_backup_*.sql.gz | tail -n +8 | xargs rm -f || true
elif [ "$BACKUP_TYPE" = "incremental" ]; then
BACKUP_FILE="$BACKUP_DIR/incremental_backup_${TIMESTAMP}.sql.gz"
echo "Creating incremental backup..."
# For PostgreSQL, we use WAL archiving for true incremental backups
# This is a simplified version using pg_dump with --data-only
pg_dump "$DATABASE_URL" --data-only | gzip > "$BACKUP_FILE"
echo "✅ Incremental backup created: $BACKUP_FILE"
# Keep only last 24 incremental backups
ls -t "$BACKUP_DIR"/incremental_backup_*.sql.gz | tail -n +25 | xargs rm -f || true
fi
# Upload to cloud storage if configured
if [ -n "$BACKUP_STORAGE_BUCKET" ]; then
echo "Uploading backup to cloud storage..."
if command -v aws &> /dev/null; then
aws s3 cp "$BACKUP_FILE" "s3://$BACKUP_STORAGE_BUCKET/$(basename $BACKUP_FILE)" || true
elif command -v az &> /dev/null; then
az storage blob upload --file "$BACKUP_FILE" --container-name backups --name "$(basename $BACKUP_FILE)" --account-name "$AZURE_STORAGE_ACCOUNT" || true
fi
fi
echo "✅ Backup complete!"

View File

@@ -0,0 +1,90 @@
version: '3.8'
services:
postgres:
image: postgres:15-alpine
environment:
POSTGRES_USER: theorder
POSTGRES_PASSWORD: theorder_dev
POSTGRES_DB: theorder_dev
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U theorder"]
interval: 10s
timeout: 5s
retries: 5
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
opensearch:
image: opensearchproject/opensearch:2.11.0
environment:
- discovery.type=single-node
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
- "DISABLE_SECURITY_PLUGIN=true"
ports:
- "9200:9200"
- "9600:9600"
volumes:
- opensearch_data:/usr/share/opensearch/data
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:9200/_cluster/health || exit 1"]
interval: 30s
timeout: 10s
retries: 5
opensearch-dashboards:
image: opensearchproject/opensearch-dashboards:2.11.0
ports:
- "5601:5601"
environment:
- 'OPENSEARCH_HOSTS=["http://opensearch:9200"]'
- "DISABLE_SECURITY_DASHBOARDS_PLUGIN=true"
depends_on:
opensearch:
condition: service_healthy
prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus-config.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
- GF_SERVER_ROOT_URL=http://localhost:3000
volumes:
- grafana_data:/var/lib/grafana
depends_on:
- prometheus
volumes:
postgres_data:
redis_data:
opensearch_data:
prometheus_data:
grafana_data:

48
scripts/dev/setup-dev.sh Executable file
View File

@@ -0,0 +1,48 @@
#!/bin/bash
# Development environment setup script
set -e
echo "🚀 Setting up development environment..."
# Check prerequisites
command -v docker >/dev/null 2>&1 || { echo "Docker is required but not installed. Aborting." >&2; exit 1; }
command -v docker-compose >/dev/null 2>&1 || { echo "Docker Compose is required but not installed. Aborting." >&2; exit 1; }
command -v pnpm >/dev/null 2>&1 || { echo "pnpm is required but not installed. Aborting." >&2; exit 1; }
# Start services
echo "Starting Docker services..."
docker-compose -f scripts/dev/docker-compose-dev.yml up -d
# Wait for services to be ready
echo "Waiting for services to be ready..."
sleep 10
# Check service health
echo "Checking service health..."
docker-compose -f scripts/dev/docker-compose-dev.yml ps
# Install dependencies
echo "Installing dependencies..."
pnpm install
# Run database migrations
echo "Running database migrations..."
pnpm --filter @the-order/database migrate
# Build packages
echo "Building packages..."
pnpm build
echo "✅ Development environment ready!"
echo ""
echo "Services available at:"
echo " • PostgreSQL: localhost:5432"
echo " • Redis: localhost:6379"
echo " • OpenSearch: localhost:9200"
echo " • OpenSearch Dashboards: http://localhost:5601"
echo " • Prometheus: http://localhost:9090"
echo " • Grafana: http://localhost:3000 (admin/admin)"
echo ""
echo "To start services: pnpm dev"

View File

@@ -0,0 +1,70 @@
#!/bin/bash
# Security scanning automation script
# Runs SAST, DAST, dependency scanning, and container scanning
set -e
echo "🔒 Starting security scanning..."
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# SAST - Static Application Security Testing
echo -e "${YELLOW}Running SAST (Static Analysis)...${NC}"
if command -v semgrep &> /dev/null; then
semgrep --config=auto --json -o sast-results.json . || true
echo -e "${GREEN}✓ SAST complete${NC}"
else
echo -e "${RED}✗ Semgrep not installed. Install with: pip install semgrep${NC}"
fi
# Dependency Scanning
echo -e "${YELLOW}Running dependency vulnerability scan...${NC}"
pnpm audit --audit-level moderate --json > dependency-scan.json || true
echo -e "${GREEN}✓ Dependency scan complete${NC}"
# Container Scanning
echo -e "${YELLOW}Running container image scanning...${NC}"
if command -v trivy &> /dev/null; then
for dockerfile in $(find . -name "Dockerfile"); do
echo "Scanning $dockerfile..."
trivy fs --security-checks vuln,config --format json -o "container-scan-$(basename $(dirname $dockerfile)).json" "$(dirname $dockerfile)" || true
done
echo -e "${GREEN}✓ Container scan complete${NC}"
else
echo -e "${RED}✗ Trivy not installed. Install from: https://github.com/aquasecurity/trivy${NC}"
fi
# Generate summary
echo -e "${YELLOW}Generating security scan summary...${NC}"
cat > security-scan-summary.md << EOF
# Security Scan Summary
**Date**: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
## SAST Results
- Report: sast-results.json
- Status: See report for details
## Dependency Scan
- Report: dependency-scan.json
- Status: See report for details
## Container Scan
- Reports: container-scan-*.json
- Status: See reports for details
## Recommendations
1. Review all findings
2. Fix high and critical vulnerabilities immediately
3. Address medium vulnerabilities in next sprint
4. Document accepted risks for low vulnerabilities
EOF
echo -e "${GREEN}✅ Security scanning complete!${NC}"
echo "Reports generated in current directory"