-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-setup.py
executable file
·403 lines (321 loc) · 10.1 KB
/
github-setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#!/usr/bin/env python3
"""
CyberAegis Project Setup Script
This script automatiza la creación y configuración del proyecto CyberAegis
"""
import os
import subprocess
import json
import shutil
from pathlib import Path
import requests
import sys
import time
class CyberAegisSetup:
def __init__(self):
self.project_name = "cyberaegis"
self.github_repo = "cyberaegis-platform"
self.root_dir = Path.cwd() / self.project_name
def create_directory_structure(self):
"""Crea la estructura de directorios del proyecto"""
print("🚀 Creando estructura de directorios...")
directories = [
"src/components/ui",
"src/pages/api/auth",
"src/pages/api/scan",
"src/pages/api/payments",
"src/styles",
"src/utils",
"src/hooks",
"src/contexts",
"src/types",
"public/images",
"scripts",
"tests/unit",
"tests/integration",
"docs/api",
"docs/deployment",
".github/workflows",
]
for dir_path in directories:
full_path = self.root_dir / dir_path
full_path.mkdir(parents=True, exist_ok=True)
(full_path / '.gitkeep').touch()
print("✅ Estructura de directorios creada")
def create_github_files(self):
"""Crea archivos relacionados con GitHub"""
print("📝 Creando archivos de GitHub...")
# README.md
readme_content = """# CyberAegis Platform
## Plataforma de Seguridad Avanzada Impulsada por IA
CyberAegis es una plataforma de seguridad de última generación que utiliza inteligencia artificial para proteger infraestructuras digitales.
### Características Principales
- 🛡️ Escaneo avanzado de vulnerabilidades
- 🤖 IA para detección de amenazas
- 🔄 Monitoreo continuo 24/7
- 🌐 Protección global
- ⚡ Respuesta automática a incidentes
### Requisitos
- Node.js 18+
- MongoDB
- Redis (opcional)
- Python 3.8+ (para scripts de utilidad)
### Instalación
```bash
git clone https://github.com/yourusername/cyberaegis-platform.git
cd cyberaegis-platform
npm install
npm run dev
```
### Documentación
Visita nuestra [documentación completa](docs/README.md) para más información.
### Licencia
MIT © CyberAegis Platform
"""
# GitHub Actions workflow
workflow_content = """name: CyberAegis CI/CD
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build
- run: npm test
deploy:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v2
- uses: amondnet/vercel-action@v20
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.ORG_ID}}
vercel-project-id: ${{ secrets.PROJECT_ID}}
vercel-args: '--prod'
"""
# .gitignore
gitignore_content = """# dependencies
node_modules/
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts
# IDE
.idea/
.vscode/
"""
# Write files
with open(self.root_dir / "README.md", "w") as f:
f.write(readme_content)
with open(self.root_dir / ".github/workflows/main.yml", "w") as f:
f.write(workflow_content)
with open(self.root_dir / ".gitignore", "w") as f:
f.write(gitignore_content)
print("✅ Archivos de GitHub creados")
def initialize_npm_project(self):
"""Inicializa el proyecto NPM y instala dependencias"""
print("📦 Inicializando proyecto NPM...")
package_json = {
"name": "cyberaegis",
"version": "1.0.0",
"private": True,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "jest",
"prepare": "husky install"
},
"dependencies": {
"@stripe/stripe-js": "^1.54.0",
"@vercel/analytics": "^1.0.1",
"next": "^13.4.7",
"next-auth": "^4.22.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"mongodb": "^5.6.0",
"stripe": "^12.9.0",
"@sendgrid/mail": "^7.7.0",
"lucide-react": "^0.263.1",
"tailwindcss": "^3.3.2",
"postcss": "^8.4.24",
"autoprefixer": "^10.4.14"
},
"devDependencies": {
"@types/react": "^18.2.0",
"@types/node": "^20.2.5",
"typescript": "^5.1.3",
"eslint": "^8.42.0",
"eslint-config-next": "^13.4.7",
"husky": "^8.0.3",
"jest": "^29.5.0",
"@testing-library/react": "^14.0.0"
}
}
with open(self.root_dir / "package.json", "w") as f:
json.dump(package_json, f, indent=2)
# Install dependencies
os.chdir(self.root_dir)
subprocess.run(["npm", "install"])
print("✅ Proyecto NPM inicializado")
def setup_git_repository(self):
"""Inicializa el repositorio Git y hace el commit inicial"""
print("🔄 Configurando repositorio Git...")
os.chdir(self.root_dir)
# Initialize git
subprocess.run(["git", "init"])
# Add all files
subprocess.run(["git", "add", "."])
# Initial commit
subprocess.run(["git", "commit", "-m", "🚀 Initial commit - CyberAegis Platform"])
print("✅ Repositorio Git configurado")
def create_env_files(self):
"""Crea los archivos de variables de entorno"""
print("🔒 Creando archivos de entorno...")
env_content = """MONGODB_URI=your_mongodb_uri
MONGODB_DB=cyberaegis
JWT_SECRET=your_jwt_secret
NEXTAUTH_URL=https://cyberaegis.com
NEXTAUTH_SECRET=your_nextauth_secret
STRIPE_SECRET_KEY=your_stripe_secret
STRIPE_PUBLISHABLE_KEY=your_stripe_public
STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret
SENDGRID_API_KEY=your_sendgrid_key
SCANNER_API_KEY=your_scanner_api_key"""
env_example_content = env_content.replace("your_", "YOUR_")
with open(self.root_dir / ".env", "w") as f:
f.write(env_content)
with open(self.root_dir / ".env.example", "w") as f:
f.write(env_example_content)
print("✅ Archivos de entorno creados")
def setup_deployment_files(self):
"""Crea archivos de configuración para despliegue"""
print("🚀 Creando archivos de despliegue...")
# Vercel configuration
vercel_config = {
"version": 2,
"builds": [
{
"src": "package.json",
"use": "@vercel/next"
}
],
"env": {
"MONGODB_URI": "@mongodb_uri",
"JWT_SECRET": "@jwt_secret",
"STRIPE_SECRET_KEY": "@stripe_secret"
}
}
with open(self.root_dir / "vercel.json", "w") as f:
json.dump(vercel_config, f, indent=2)
print("✅ Archivos de despliegue creados")
def create_documentation(self):
"""Crea documentación básica del proyecto"""
print("📚 Generando documentación...")
docs = {
"README.md": """# CyberAegis Documentation
## Contenido
1. [API Documentation](api/README.md)
2. [Deployment Guide](deployment/README.md)
3. [Development Guide](development.md)
""",
"api/README.md": """# API Documentation
## Endpoints
### Authentication
- POST /api/auth/login
- POST /api/auth/register
- POST /api/auth/logout
### Scanning
- POST /api/scan/free
- POST /api/scan/full
- GET /api/scan/history
### Payments
- POST /api/payments/create-checkout
- POST /api/payments/webhook
""",
"deployment/README.md": """# Deployment Guide
## Prerequisites
1. Vercel Account
2. MongoDB Atlas Account
3. Stripe Account
4. SendGrid Account
## Deployment Steps
1. Clone repository
2. Configure environment variables
3. Deploy to Vercel
4. Configure DNS
5. Test deployment
"""
}
for path, content in docs.items():
full_path = self.root_dir / "docs" / path
full_path.parent.mkdir(parents=True, exist_ok=True)
with open(full_path, "w") as f:
f.write(content)
print("✅ Documentación generada")
def setup_all(self):
"""Ejecuta todo el proceso de configuración"""
try:
print("🎯 Iniciando configuración de CyberAegis...")
self.create_directory_structure()
self.create_github_files()
self.initialize_npm_project()
self.setup_git_repository()
self.create_env_files()
self.setup_deployment_files()
self.create_documentation()
print("""
✨ ¡Configuración completada con éxito! ✨
Próximos pasos:
1. Configura las variables de entorno en .env
2. Conecta el repositorio con GitHub
3. Configura el proyecto en Vercel
4. Revisa la documentación en /docs
Para iniciar el desarrollo:
cd cyberaegis
npm run dev
""")
except Exception as e:
print(f"❌ Error durante la configuración: {str(e)}")
raise
if __name__ == "__main__":
setup = CyberAegisSetup()
setup.setup_all()