claude-all-config 3.1.17 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/VERSION +1 -1
- package/package.json +2 -2
- package/skills/standard-architecture/SKILL.md +191 -0
- package/skills/standard-architecture/scripts/deploy.sh +462 -0
- package/skills/standard-architecture/scripts/health-check.sh +467 -0
- package/skills/standard-architecture/templates/cloudflared.yml.template +167 -0
- package/skills/standard-architecture/templates/docker-compose.yml.template +160 -0
- package/skills/standard-architecture/templates/nginx.conf.template +275 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.
|
|
1
|
+
3.2.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-all-config",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "🤖 Universal AI CLI Config with Advanced Skills System - Quality Scoring, Scaffolding, Testing, Hooks & Multi-Agent Support (Claude Code, Cursor, Copilot, Gemini & 20+ More)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
"codex",
|
|
121
121
|
"trae"
|
|
122
122
|
],
|
|
123
|
-
"skillsCount":
|
|
123
|
+
"skillsCount": 61,
|
|
124
124
|
"agentsCount": 14,
|
|
125
125
|
"commandsCount": 3
|
|
126
126
|
},
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: standard-architecture
|
|
3
|
+
description: Automatically setup secure deployment architecture with Nginx + Unix Socket + Cloudflare Tunnel. Use when creating new applications, backends, APIs, or any web service. Triggers on "create app", "deploy service", "new backend", "setup architecture".
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Standard Security Architecture
|
|
7
|
+
|
|
8
|
+
Automatically deploys applications using the **most secure architecture pattern**:
|
|
9
|
+
- **Zero public ports** for backend services
|
|
10
|
+
- **Unix Domain Sockets** for inter-process communication
|
|
11
|
+
- **Nginx reverse proxy** for security and performance
|
|
12
|
+
- **Cloudflare Tunnel** for zero-trust network access
|
|
13
|
+
- **Docker isolation** with proper security boundaries
|
|
14
|
+
|
|
15
|
+
## When to Use
|
|
16
|
+
|
|
17
|
+
- Creating new web applications, APIs, or backend services
|
|
18
|
+
- Migrating existing services to secure architecture
|
|
19
|
+
- Setting up development/staging/production environments
|
|
20
|
+
- Any application requiring internet access
|
|
21
|
+
|
|
22
|
+
## Architecture Pattern
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
Internet → Cloudflare Edge → CF Tunnel → Nginx → Unix Socket → Docker App
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Security Benefits:**
|
|
29
|
+
- ✅ Zero network ports exposed to internet
|
|
30
|
+
- ✅ File-based permissions for socket access
|
|
31
|
+
- ✅ Nginx security layer (rate limiting, headers)
|
|
32
|
+
- ✅ Container isolation boundaries
|
|
33
|
+
- ✅ DDoS protection via Cloudflare
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
The skill automatically:
|
|
38
|
+
1. **Generate Docker setup** with Unix socket support
|
|
39
|
+
2. **Create Nginx config** with security hardening
|
|
40
|
+
3. **Setup Cloudflare Tunnel** configuration
|
|
41
|
+
4. **Configure systemd services** for auto-restart
|
|
42
|
+
5. **Apply security policies** and file permissions
|
|
43
|
+
6. **Test deployment** end-to-end
|
|
44
|
+
|
|
45
|
+
## Implementation
|
|
46
|
+
|
|
47
|
+
### Application Requirements
|
|
48
|
+
- Must support Unix Domain Socket binding (most modern frameworks do)
|
|
49
|
+
- Should have health check endpoint
|
|
50
|
+
- Environment variable configuration
|
|
51
|
+
|
|
52
|
+
### Generated Files
|
|
53
|
+
```
|
|
54
|
+
project/
|
|
55
|
+
├── docker-compose.yml # Docker with Unix socket volume
|
|
56
|
+
├── nginx/
|
|
57
|
+
│ └── app.conf # Nginx reverse proxy config
|
|
58
|
+
├── cloudflared/
|
|
59
|
+
│ └── config.yml # CF tunnel configuration
|
|
60
|
+
├── systemd/
|
|
61
|
+
│ └── app.service # Auto-restart service
|
|
62
|
+
└── scripts/
|
|
63
|
+
├── deploy.sh # Full deployment script
|
|
64
|
+
└── health-check.sh # Service validation
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Nginx Security Features
|
|
68
|
+
- Rate limiting per IP
|
|
69
|
+
- Security headers (HSTS, CSP, etc)
|
|
70
|
+
- Request size limits
|
|
71
|
+
- Bad bot blocking
|
|
72
|
+
- SSL/TLS hardening
|
|
73
|
+
|
|
74
|
+
### Unix Socket Configuration
|
|
75
|
+
- Proper file permissions (660)
|
|
76
|
+
- Owner/group management
|
|
77
|
+
- Socket cleanup on restart
|
|
78
|
+
- Performance optimizations
|
|
79
|
+
|
|
80
|
+
## Usage Examples
|
|
81
|
+
|
|
82
|
+
### Backend API
|
|
83
|
+
```bash
|
|
84
|
+
./scripts/deploy.sh --type=api --port=8080 --domain=api.example.com
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Full-Stack App
|
|
88
|
+
```bash
|
|
89
|
+
./scripts/deploy.sh --type=webapp --frontend=3000 --backend=8080 --domain=app.example.com
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Database Service
|
|
93
|
+
```bash
|
|
94
|
+
./scripts/deploy.sh --type=database --port=5432 --internal-only
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Advanced Configuration
|
|
98
|
+
|
|
99
|
+
### Multi-Service Setup
|
|
100
|
+
Handle applications with multiple components (frontend, backend, workers) using unified socket directory and Nginx upstream configuration.
|
|
101
|
+
|
|
102
|
+
### Load Balancing
|
|
103
|
+
Configure multiple backend instances behind single Unix socket proxy for horizontal scaling.
|
|
104
|
+
|
|
105
|
+
### Monitoring Integration
|
|
106
|
+
Automatic setup of:
|
|
107
|
+
- Health check endpoints
|
|
108
|
+
- Prometheus metrics exposure
|
|
109
|
+
- Log aggregation configuration
|
|
110
|
+
- Alert manager integration
|
|
111
|
+
|
|
112
|
+
## Security Hardening
|
|
113
|
+
|
|
114
|
+
### File System
|
|
115
|
+
- Unix socket permissions: `660` (owner + group only)
|
|
116
|
+
- Service user isolation
|
|
117
|
+
- Read-only container filesystem where possible
|
|
118
|
+
- Volume mount restrictions
|
|
119
|
+
|
|
120
|
+
### Network
|
|
121
|
+
- Container network isolation (`network_mode: none` for pure socket communication)
|
|
122
|
+
- Firewall rules via iptables
|
|
123
|
+
- CrowdSec integration for threat detection
|
|
124
|
+
|
|
125
|
+
### Process
|
|
126
|
+
- Non-root container execution
|
|
127
|
+
- Resource limits (CPU, memory)
|
|
128
|
+
- Capability dropping
|
|
129
|
+
- Systemd service isolation
|
|
130
|
+
|
|
131
|
+
## Troubleshooting
|
|
132
|
+
|
|
133
|
+
### Common Issues
|
|
134
|
+
- **Socket permission denied**: Check file ownership and permissions
|
|
135
|
+
- **Connection refused**: Verify socket file exists and service is running
|
|
136
|
+
- **502 Bad Gateway**: Check socket path in Nginx config matches application
|
|
137
|
+
- **CF Tunnel not connecting**: Verify tunnel token and domain DNS
|
|
138
|
+
|
|
139
|
+
### Debug Commands
|
|
140
|
+
```bash
|
|
141
|
+
# Check socket file
|
|
142
|
+
ls -la /var/run/sockets/
|
|
143
|
+
|
|
144
|
+
# Test socket connectivity
|
|
145
|
+
curl --unix-socket /var/run/sockets/app.sock http://localhost/health
|
|
146
|
+
|
|
147
|
+
# Nginx config test
|
|
148
|
+
nginx -t
|
|
149
|
+
|
|
150
|
+
# Service status
|
|
151
|
+
systemctl status app
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Best Practices
|
|
155
|
+
|
|
156
|
+
### Development Workflow
|
|
157
|
+
1. Start with localhost development
|
|
158
|
+
2. Test Unix socket locally
|
|
159
|
+
3. Add Nginx layer
|
|
160
|
+
4. Configure CF tunnel
|
|
161
|
+
5. Deploy with monitoring
|
|
162
|
+
|
|
163
|
+
### Production Checklist
|
|
164
|
+
- [ ] Unix socket permissions verified
|
|
165
|
+
- [ ] Nginx security headers enabled
|
|
166
|
+
- [ ] CF tunnel authenticated
|
|
167
|
+
- [ ] Health checks responding
|
|
168
|
+
- [ ] Log rotation configured
|
|
169
|
+
- [ ] Backup strategy in place
|
|
170
|
+
- [ ] Monitoring alerts active
|
|
171
|
+
|
|
172
|
+
### Security Review
|
|
173
|
+
- [ ] No network ports in application containers
|
|
174
|
+
- [ ] Socket files protected (not world-readable)
|
|
175
|
+
- [ ] Nginx rate limiting configured
|
|
176
|
+
- [ ] CF WAF rules enabled
|
|
177
|
+
- [ ] Container runs as non-root
|
|
178
|
+
- [ ] Resource limits applied
|
|
179
|
+
|
|
180
|
+
## Integration with Existing Services
|
|
181
|
+
|
|
182
|
+
Works seamlessly with:
|
|
183
|
+
- **Databases**: PostgreSQL, Redis, MongoDB via Unix sockets
|
|
184
|
+
- **Message Queues**: RabbitMQ, Apache Kafka
|
|
185
|
+
- **Monitoring**: Prometheus, Grafana, ELK stack
|
|
186
|
+
- **CI/CD**: GitHub Actions, GitLab CI, Jenkins
|
|
187
|
+
- **Container Orchestration**: Docker Swarm, basic Kubernetes
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
**Note:** This pattern provides maximum security with minimal complexity. Every new application should follow this architecture unless specific requirements dictate otherwise.
|
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Standard Architecture Deployment Script
|
|
4
|
+
# Automatically deploys applications with Nginx + Unix Socket + Cloudflare Tunnel
|
|
5
|
+
|
|
6
|
+
set -euo pipefail
|
|
7
|
+
|
|
8
|
+
# Colors for output
|
|
9
|
+
RED='\033[0;31m'
|
|
10
|
+
GREEN='\033[0;32m'
|
|
11
|
+
YELLOW='\033[1;33m'
|
|
12
|
+
BLUE='\033[0;34m'
|
|
13
|
+
NC='\033[0m' # No Color
|
|
14
|
+
|
|
15
|
+
# Default values
|
|
16
|
+
APP_NAME=""
|
|
17
|
+
DOMAIN=""
|
|
18
|
+
PORT="8080"
|
|
19
|
+
TYPE="webapp"
|
|
20
|
+
ENVIRONMENT="production"
|
|
21
|
+
SKIP_TUNNEL=false
|
|
22
|
+
SKIP_SYSTEMD=false
|
|
23
|
+
DRY_RUN=false
|
|
24
|
+
|
|
25
|
+
# Directories
|
|
26
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
27
|
+
TEMPLATE_DIR="$(dirname "$SCRIPT_DIR")/templates"
|
|
28
|
+
PROJECT_DIR=""
|
|
29
|
+
|
|
30
|
+
# Usage function
|
|
31
|
+
usage() {
|
|
32
|
+
cat << EOF
|
|
33
|
+
Standard Architecture Deployment Script
|
|
34
|
+
|
|
35
|
+
USAGE:
|
|
36
|
+
$0 --app=APP_NAME --domain=DOMAIN [OPTIONS]
|
|
37
|
+
|
|
38
|
+
REQUIRED:
|
|
39
|
+
--app=NAME Application name (lowercase, alphanumeric + hyphens)
|
|
40
|
+
--domain=DOMAIN Primary domain for the application
|
|
41
|
+
|
|
42
|
+
OPTIONS:
|
|
43
|
+
--port=PORT Internal port (default: 8080)
|
|
44
|
+
--type=TYPE Application type: webapp, api, database (default: webapp)
|
|
45
|
+
--env=ENVIRONMENT Environment: development, staging, production (default: production)
|
|
46
|
+
--project-dir=PATH Project directory (default: ./APP_NAME)
|
|
47
|
+
--skip-tunnel Skip Cloudflare Tunnel setup
|
|
48
|
+
--skip-systemd Skip systemd service creation
|
|
49
|
+
--dry-run Show what would be done without executing
|
|
50
|
+
--help Show this help message
|
|
51
|
+
|
|
52
|
+
EXAMPLES:
|
|
53
|
+
# Basic web application
|
|
54
|
+
$0 --app=myapp --domain=myapp.com
|
|
55
|
+
|
|
56
|
+
# API service
|
|
57
|
+
$0 --app=api --domain=api.myapp.com --type=api --port=8080
|
|
58
|
+
|
|
59
|
+
# Development environment
|
|
60
|
+
$0 --app=myapp-dev --domain=dev.myapp.com --env=development
|
|
61
|
+
|
|
62
|
+
# With custom project directory
|
|
63
|
+
$0 --app=myapp --domain=myapp.com --project-dir=/opt/myapp
|
|
64
|
+
EOF
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
# Logging functions
|
|
68
|
+
log_info() {
|
|
69
|
+
echo -e "${BLUE}[INFO]${NC} $1"
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
log_success() {
|
|
73
|
+
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
log_warning() {
|
|
77
|
+
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
log_error() {
|
|
81
|
+
echo -e "${RED}[ERROR]${NC} $1"
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# Parse command line arguments
|
|
85
|
+
while [[ $# -gt 0 ]]; do
|
|
86
|
+
case $1 in
|
|
87
|
+
--app=*)
|
|
88
|
+
APP_NAME="${1#*=}"
|
|
89
|
+
shift
|
|
90
|
+
;;
|
|
91
|
+
--domain=*)
|
|
92
|
+
DOMAIN="${1#*=}"
|
|
93
|
+
shift
|
|
94
|
+
;;
|
|
95
|
+
--port=*)
|
|
96
|
+
PORT="${1#*=}"
|
|
97
|
+
shift
|
|
98
|
+
;;
|
|
99
|
+
--type=*)
|
|
100
|
+
TYPE="${1#*=}"
|
|
101
|
+
shift
|
|
102
|
+
;;
|
|
103
|
+
--env=*)
|
|
104
|
+
ENVIRONMENT="${1#*=}"
|
|
105
|
+
shift
|
|
106
|
+
;;
|
|
107
|
+
--project-dir=*)
|
|
108
|
+
PROJECT_DIR="${1#*=}"
|
|
109
|
+
shift
|
|
110
|
+
;;
|
|
111
|
+
--skip-tunnel)
|
|
112
|
+
SKIP_TUNNEL=true
|
|
113
|
+
shift
|
|
114
|
+
;;
|
|
115
|
+
--skip-systemd)
|
|
116
|
+
SKIP_SYSTEMD=true
|
|
117
|
+
shift
|
|
118
|
+
;;
|
|
119
|
+
--dry-run)
|
|
120
|
+
DRY_RUN=true
|
|
121
|
+
shift
|
|
122
|
+
;;
|
|
123
|
+
--help)
|
|
124
|
+
usage
|
|
125
|
+
exit 0
|
|
126
|
+
;;
|
|
127
|
+
*)
|
|
128
|
+
log_error "Unknown option: $1"
|
|
129
|
+
usage
|
|
130
|
+
exit 1
|
|
131
|
+
;;
|
|
132
|
+
esac
|
|
133
|
+
done
|
|
134
|
+
|
|
135
|
+
# Validate required parameters
|
|
136
|
+
if [[ -z "$APP_NAME" ]]; then
|
|
137
|
+
log_error "Application name is required (--app=NAME)"
|
|
138
|
+
usage
|
|
139
|
+
exit 1
|
|
140
|
+
fi
|
|
141
|
+
|
|
142
|
+
if [[ -z "$DOMAIN" ]]; then
|
|
143
|
+
log_error "Domain is required (--domain=DOMAIN)"
|
|
144
|
+
usage
|
|
145
|
+
exit 1
|
|
146
|
+
fi
|
|
147
|
+
|
|
148
|
+
# Validate app name format
|
|
149
|
+
if ! [[ "$APP_NAME" =~ ^[a-z0-9-]+$ ]]; then
|
|
150
|
+
log_error "App name must contain only lowercase letters, numbers, and hyphens"
|
|
151
|
+
exit 1
|
|
152
|
+
fi
|
|
153
|
+
|
|
154
|
+
# Set default project directory
|
|
155
|
+
if [[ -z "$PROJECT_DIR" ]]; then
|
|
156
|
+
PROJECT_DIR="$(pwd)/$APP_NAME"
|
|
157
|
+
fi
|
|
158
|
+
|
|
159
|
+
# Validate type
|
|
160
|
+
case $TYPE in
|
|
161
|
+
webapp|api|database)
|
|
162
|
+
;;
|
|
163
|
+
*)
|
|
164
|
+
log_error "Invalid type: $TYPE. Must be webapp, api, or database"
|
|
165
|
+
exit 1
|
|
166
|
+
;;
|
|
167
|
+
esac
|
|
168
|
+
|
|
169
|
+
# Check dependencies
|
|
170
|
+
check_dependencies() {
|
|
171
|
+
log_info "Checking dependencies..."
|
|
172
|
+
|
|
173
|
+
local deps=("docker" "nginx" "envsubst")
|
|
174
|
+
local missing=()
|
|
175
|
+
|
|
176
|
+
for dep in "${deps[@]}"; do
|
|
177
|
+
if ! command -v "$dep" >/dev/null 2>&1; then
|
|
178
|
+
missing+=("$dep")
|
|
179
|
+
fi
|
|
180
|
+
done
|
|
181
|
+
|
|
182
|
+
if ! $SKIP_TUNNEL && ! command -v "cloudflared" >/dev/null 2>&1; then
|
|
183
|
+
missing+=("cloudflared")
|
|
184
|
+
fi
|
|
185
|
+
|
|
186
|
+
if [[ ${#missing[@]} -ne 0 ]]; then
|
|
187
|
+
log_error "Missing dependencies: ${missing[*]}"
|
|
188
|
+
log_error "Please install missing packages and try again"
|
|
189
|
+
exit 1
|
|
190
|
+
fi
|
|
191
|
+
|
|
192
|
+
log_success "All dependencies found"
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
# Create project structure
|
|
196
|
+
create_project_structure() {
|
|
197
|
+
log_info "Creating project structure at $PROJECT_DIR..."
|
|
198
|
+
|
|
199
|
+
if $DRY_RUN; then
|
|
200
|
+
log_info "[DRY RUN] Would create directory structure"
|
|
201
|
+
return
|
|
202
|
+
fi
|
|
203
|
+
|
|
204
|
+
mkdir -p "$PROJECT_DIR"/{nginx,cloudflared,systemd,scripts,logs}
|
|
205
|
+
mkdir -p "/var/run/$APP_NAME"
|
|
206
|
+
|
|
207
|
+
# Set proper permissions
|
|
208
|
+
sudo chown "${USER}:www-data" "/var/run/$APP_NAME"
|
|
209
|
+
chmod 775 "/var/run/$APP_NAME"
|
|
210
|
+
|
|
211
|
+
log_success "Project structure created"
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
# Generate configuration files
|
|
215
|
+
generate_configs() {
|
|
216
|
+
log_info "Generating configuration files..."
|
|
217
|
+
|
|
218
|
+
# Set template variables
|
|
219
|
+
export APP_NAME="$APP_NAME"
|
|
220
|
+
export DOMAIN="$DOMAIN"
|
|
221
|
+
export CF_TUNNEL_PORT="$PORT"
|
|
222
|
+
export PRIMARY_DOMAIN="$DOMAIN"
|
|
223
|
+
export API_DOMAIN="api.$DOMAIN"
|
|
224
|
+
export ADMIN_DOMAIN="admin.$DOMAIN"
|
|
225
|
+
export INTERNAL_PORT="$PORT"
|
|
226
|
+
export NGINX_PORT="$PORT"
|
|
227
|
+
export MEMORY_LIMIT="512M"
|
|
228
|
+
export CPU_LIMIT="0.5"
|
|
229
|
+
export LOG_LEVEL="info"
|
|
230
|
+
export MAX_UPLOAD_SIZE="10M"
|
|
231
|
+
export DB_NAME="$APP_NAME"
|
|
232
|
+
export DB_USER="$APP_NAME"
|
|
233
|
+
export DB_PASSWORD="$(openssl rand -base64 32)"
|
|
234
|
+
export USER="$(whoami)"
|
|
235
|
+
export TUNNEL_ID="" # Will be set if tunnel is created
|
|
236
|
+
|
|
237
|
+
if $DRY_RUN; then
|
|
238
|
+
log_info "[DRY RUN] Would generate configuration files"
|
|
239
|
+
return
|
|
240
|
+
fi
|
|
241
|
+
|
|
242
|
+
# Generate Docker Compose
|
|
243
|
+
envsubst < "$TEMPLATE_DIR/docker-compose.yml.template" > "$PROJECT_DIR/docker-compose.yml"
|
|
244
|
+
log_success "Generated docker-compose.yml"
|
|
245
|
+
|
|
246
|
+
# Generate Nginx config
|
|
247
|
+
envsubst < "$TEMPLATE_DIR/nginx.conf.template" > "$PROJECT_DIR/nginx/${APP_NAME}.conf"
|
|
248
|
+
log_success "Generated nginx configuration"
|
|
249
|
+
|
|
250
|
+
# Generate Cloudflare Tunnel config
|
|
251
|
+
if ! $SKIP_TUNNEL; then
|
|
252
|
+
envsubst < "$TEMPLATE_DIR/cloudflared.yml.template" > "$PROJECT_DIR/cloudflared/config.yml"
|
|
253
|
+
log_success "Generated Cloudflare Tunnel configuration"
|
|
254
|
+
fi
|
|
255
|
+
|
|
256
|
+
# Create .env file
|
|
257
|
+
cat > "$PROJECT_DIR/.env" << EOF
|
|
258
|
+
# Application Configuration
|
|
259
|
+
APP_NAME=$APP_NAME
|
|
260
|
+
DOMAIN=$DOMAIN
|
|
261
|
+
PORT=$PORT
|
|
262
|
+
ENVIRONMENT=$ENVIRONMENT
|
|
263
|
+
|
|
264
|
+
# Database Configuration
|
|
265
|
+
DB_NAME=$DB_NAME
|
|
266
|
+
DB_USER=$DB_USER
|
|
267
|
+
DB_PASSWORD=$DB_PASSWORD
|
|
268
|
+
|
|
269
|
+
# Socket Configuration
|
|
270
|
+
SOCKET_PATH=/var/run/$APP_NAME/$APP_NAME.sock
|
|
271
|
+
|
|
272
|
+
# Security
|
|
273
|
+
JWT_SECRET=$(openssl rand -base64 64)
|
|
274
|
+
ENCRYPTION_KEY=$(openssl rand -base64 32)
|
|
275
|
+
EOF
|
|
276
|
+
|
|
277
|
+
chmod 600 "$PROJECT_DIR/.env"
|
|
278
|
+
log_success "Generated .env file"
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
# Setup Nginx
|
|
282
|
+
setup_nginx() {
|
|
283
|
+
log_info "Setting up Nginx..."
|
|
284
|
+
|
|
285
|
+
if $DRY_RUN; then
|
|
286
|
+
log_info "[DRY RUN] Would configure Nginx"
|
|
287
|
+
return
|
|
288
|
+
fi
|
|
289
|
+
|
|
290
|
+
# Create symlink to sites-enabled
|
|
291
|
+
sudo ln -sf "$PROJECT_DIR/nginx/${APP_NAME}.conf" "/etc/nginx/sites-enabled/${APP_NAME}"
|
|
292
|
+
|
|
293
|
+
# Test configuration
|
|
294
|
+
if sudo nginx -t; then
|
|
295
|
+
sudo systemctl reload nginx
|
|
296
|
+
log_success "Nginx configured and reloaded"
|
|
297
|
+
else
|
|
298
|
+
log_error "Nginx configuration test failed"
|
|
299
|
+
exit 1
|
|
300
|
+
fi
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
# Setup Cloudflare Tunnel
|
|
304
|
+
setup_tunnel() {
|
|
305
|
+
if $SKIP_TUNNEL; then
|
|
306
|
+
log_info "Skipping Cloudflare Tunnel setup"
|
|
307
|
+
return
|
|
308
|
+
fi
|
|
309
|
+
|
|
310
|
+
log_info "Setting up Cloudflare Tunnel..."
|
|
311
|
+
|
|
312
|
+
if $DRY_RUN; then
|
|
313
|
+
log_info "[DRY RUN] Would setup Cloudflare Tunnel"
|
|
314
|
+
return
|
|
315
|
+
fi
|
|
316
|
+
|
|
317
|
+
# Create tunnel
|
|
318
|
+
local tunnel_output
|
|
319
|
+
tunnel_output=$(cloudflared tunnel create "$APP_NAME" 2>/dev/null)
|
|
320
|
+
TUNNEL_ID=$(echo "$tunnel_output" | grep -oE '[a-f0-9-]{36}')
|
|
321
|
+
|
|
322
|
+
if [[ -z "$TUNNEL_ID" ]]; then
|
|
323
|
+
log_error "Failed to create Cloudflare Tunnel"
|
|
324
|
+
exit 1
|
|
325
|
+
fi
|
|
326
|
+
|
|
327
|
+
log_success "Created tunnel: $TUNNEL_ID"
|
|
328
|
+
|
|
329
|
+
# Update config with tunnel ID
|
|
330
|
+
sed -i "s/{{TUNNEL_ID}}/$TUNNEL_ID/g" "$PROJECT_DIR/cloudflared/config.yml"
|
|
331
|
+
|
|
332
|
+
# Route DNS
|
|
333
|
+
cloudflared tunnel route dns "$TUNNEL_ID" "$DOMAIN"
|
|
334
|
+
cloudflared tunnel route dns "$TUNNEL_ID" "api.$DOMAIN"
|
|
335
|
+
|
|
336
|
+
log_success "DNS routes configured"
|
|
337
|
+
|
|
338
|
+
# Create systemd service
|
|
339
|
+
if ! $SKIP_SYSTEMD; then
|
|
340
|
+
cat > "$PROJECT_DIR/systemd/${APP_NAME}-tunnel.service" << EOF
|
|
341
|
+
[Unit]
|
|
342
|
+
Description=Cloudflare Tunnel for $APP_NAME
|
|
343
|
+
After=network.target
|
|
344
|
+
Requires=network.target
|
|
345
|
+
|
|
346
|
+
[Service]
|
|
347
|
+
Type=simple
|
|
348
|
+
User=$(whoami)
|
|
349
|
+
WorkingDirectory=$PROJECT_DIR/cloudflared
|
|
350
|
+
ExecStart=cloudflared tunnel --config $PROJECT_DIR/cloudflared/config.yml run
|
|
351
|
+
Restart=always
|
|
352
|
+
RestartSec=5
|
|
353
|
+
KillMode=mixed
|
|
354
|
+
KillSignal=SIGINT
|
|
355
|
+
TimeoutStopSec=30
|
|
356
|
+
|
|
357
|
+
[Install]
|
|
358
|
+
WantedBy=multi-user.target
|
|
359
|
+
EOF
|
|
360
|
+
|
|
361
|
+
sudo ln -sf "$PROJECT_DIR/systemd/${APP_NAME}-tunnel.service" "/etc/systemd/system/${APP_NAME}-tunnel.service"
|
|
362
|
+
sudo systemctl daemon-reload
|
|
363
|
+
sudo systemctl enable "${APP_NAME}-tunnel.service"
|
|
364
|
+
|
|
365
|
+
log_success "Tunnel systemd service created"
|
|
366
|
+
fi
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
# Create deployment script
|
|
370
|
+
create_deployment_script() {
|
|
371
|
+
log_info "Creating deployment script..."
|
|
372
|
+
|
|
373
|
+
if $DRY_RUN; then
|
|
374
|
+
log_info "[DRY RUN] Would create deployment script"
|
|
375
|
+
return
|
|
376
|
+
fi
|
|
377
|
+
|
|
378
|
+
cat > "$PROJECT_DIR/scripts/start.sh" << 'EOF'
|
|
379
|
+
#!/bin/bash
|
|
380
|
+
set -e
|
|
381
|
+
|
|
382
|
+
APP_NAME="{{APP_NAME}}"
|
|
383
|
+
PROJECT_DIR="{{PROJECT_DIR}}"
|
|
384
|
+
|
|
385
|
+
echo "Starting $APP_NAME..."
|
|
386
|
+
|
|
387
|
+
# Ensure socket directory exists
|
|
388
|
+
sudo mkdir -p "/var/run/$APP_NAME"
|
|
389
|
+
sudo chown "$(whoami):www-data" "/var/run/$APP_NAME"
|
|
390
|
+
chmod 775 "/var/run/$APP_NAME"
|
|
391
|
+
|
|
392
|
+
# Start Docker containers
|
|
393
|
+
cd "$PROJECT_DIR"
|
|
394
|
+
docker-compose up -d
|
|
395
|
+
|
|
396
|
+
# Wait for services to be ready
|
|
397
|
+
echo "Waiting for services to start..."
|
|
398
|
+
sleep 10
|
|
399
|
+
|
|
400
|
+
# Health check
|
|
401
|
+
if curl --unix-socket "/var/run/$APP_NAME/$APP_NAME.sock" http://localhost/health >/dev/null 2>&1; then
|
|
402
|
+
echo "✅ Application is healthy"
|
|
403
|
+
else
|
|
404
|
+
echo "⚠️ Health check failed, check logs:"
|
|
405
|
+
docker-compose logs --tail=20
|
|
406
|
+
fi
|
|
407
|
+
|
|
408
|
+
# Start tunnel (if configured)
|
|
409
|
+
if systemctl is-enabled "${APP_NAME}-tunnel.service" >/dev/null 2>&1; then
|
|
410
|
+
sudo systemctl start "${APP_NAME}-tunnel.service"
|
|
411
|
+
echo "✅ Tunnel started"
|
|
412
|
+
fi
|
|
413
|
+
|
|
414
|
+
echo "🚀 Deployment complete!"
|
|
415
|
+
echo "📊 Monitor with: docker-compose logs -f"
|
|
416
|
+
echo "🌐 Access at: https://{{DOMAIN}}"
|
|
417
|
+
EOF
|
|
418
|
+
|
|
419
|
+
# Replace template variables
|
|
420
|
+
sed -i "s/{{APP_NAME}}/$APP_NAME/g" "$PROJECT_DIR/scripts/start.sh"
|
|
421
|
+
sed -i "s|{{PROJECT_DIR}}|$PROJECT_DIR|g" "$PROJECT_DIR/scripts/start.sh"
|
|
422
|
+
sed -i "s/{{DOMAIN}}/$DOMAIN/g" "$PROJECT_DIR/scripts/start.sh"
|
|
423
|
+
|
|
424
|
+
chmod +x "$PROJECT_DIR/scripts/start.sh"
|
|
425
|
+
log_success "Deployment script created"
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
# Main deployment
|
|
429
|
+
main() {
|
|
430
|
+
log_info "🚀 Starting Standard Architecture deployment"
|
|
431
|
+
log_info "App: $APP_NAME"
|
|
432
|
+
log_info "Domain: $DOMAIN"
|
|
433
|
+
log_info "Type: $TYPE"
|
|
434
|
+
log_info "Environment: $ENVIRONMENT"
|
|
435
|
+
log_info "Project Dir: $PROJECT_DIR"
|
|
436
|
+
|
|
437
|
+
if $DRY_RUN; then
|
|
438
|
+
log_warning "DRY RUN MODE - No changes will be made"
|
|
439
|
+
fi
|
|
440
|
+
|
|
441
|
+
check_dependencies
|
|
442
|
+
create_project_structure
|
|
443
|
+
generate_configs
|
|
444
|
+
setup_nginx
|
|
445
|
+
setup_tunnel
|
|
446
|
+
create_deployment_script
|
|
447
|
+
|
|
448
|
+
log_success "🎉 Deployment setup complete!"
|
|
449
|
+
|
|
450
|
+
if ! $DRY_RUN; then
|
|
451
|
+
echo ""
|
|
452
|
+
log_info "Next steps:"
|
|
453
|
+
echo "1. Add your application code to: $PROJECT_DIR"
|
|
454
|
+
echo "2. Update Dockerfile to bind to unix socket: /var/run/$APP_NAME/$APP_NAME.sock"
|
|
455
|
+
echo "3. Build and start: cd $PROJECT_DIR && bash scripts/start.sh"
|
|
456
|
+
echo "4. Monitor logs: docker-compose logs -f"
|
|
457
|
+
echo "5. Test: curl https://$DOMAIN/health"
|
|
458
|
+
fi
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
# Run main function
|
|
462
|
+
main "$@"
|