@qubiit/lmagent 2.5.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/.editorconfig +18 -0
- package/AGENTS.md +169 -0
- package/CLAUDE.md +122 -0
- package/CONTRIBUTING.md +90 -0
- package/LICENSE +21 -0
- package/README.md +195 -0
- package/config/commands.yaml +194 -0
- package/config/levels.yaml +135 -0
- package/config/models.yaml +192 -0
- package/config/settings.yaml +405 -0
- package/config/tools-extended.yaml +534 -0
- package/config/tools.yaml +437 -0
- package/docs/assets/logo.png +0 -0
- package/docs/commands.md +132 -0
- package/docs/customization-guide.md +445 -0
- package/docs/getting-started.md +154 -0
- package/docs/how-to-start.md +242 -0
- package/docs/navigation-index.md +227 -0
- package/docs/usage-guide.md +113 -0
- package/install.js +1044 -0
- package/package.json +35 -0
- package/pyproject.toml +182 -0
- package/rules/_bootstrap.md +138 -0
- package/rules/agents-ia.md +607 -0
- package/rules/api-design.md +337 -0
- package/rules/automations-n8n.md +646 -0
- package/rules/code-style.md +570 -0
- package/rules/documentation.md +98 -0
- package/rules/security.md +316 -0
- package/rules/stack.md +395 -0
- package/rules/testing.md +326 -0
- package/rules/workflow.md +353 -0
- package/scripts/create_skill.js +300 -0
- package/scripts/validate_skills.js +283 -0
- package/skills/ai-agent-engineer/SKILL.md +394 -0
- package/skills/ai-agent-engineer/references/agent-patterns.md +149 -0
- package/skills/api-designer/SKILL.md +429 -0
- package/skills/api-designer/references/api-standards.md +13 -0
- package/skills/architect/SKILL.md +285 -0
- package/skills/architect/references/c4-model.md +133 -0
- package/skills/automation-engineer/SKILL.md +352 -0
- package/skills/automation-engineer/references/n8n-patterns.md +127 -0
- package/skills/backend-engineer/SKILL.md +261 -0
- package/skills/backend-engineer/assets/fastapi-project-structure.yaml +74 -0
- package/skills/backend-engineer/references/debugging-guide.md +174 -0
- package/skills/backend-engineer/references/design-patterns.md +208 -0
- package/skills/backend-engineer/scripts/scaffold_backend.py +313 -0
- package/skills/bmad-methodology/SKILL.md +202 -0
- package/skills/bmad-methodology/references/scale-adaptive-levels.md +141 -0
- package/skills/browser-agent/SKILL.md +502 -0
- package/skills/browser-agent/scripts/playwright_setup.ts +16 -0
- package/skills/code-reviewer/SKILL.md +306 -0
- package/skills/code-reviewer/references/code-review-checklist.md +16 -0
- package/skills/data-engineer/SKILL.md +474 -0
- package/skills/data-engineer/assets/pg-monitoring-queries.sql +154 -0
- package/skills/data-engineer/references/index-strategy.md +128 -0
- package/skills/data-engineer/scripts/backup_postgres.py +221 -0
- package/skills/devops-engineer/SKILL.md +547 -0
- package/skills/devops-engineer/references/ci-cd-patterns.md +265 -0
- package/skills/devops-engineer/scripts/docker_healthcheck.py +125 -0
- package/skills/document-generator/SKILL.md +746 -0
- package/skills/document-generator/references/pdf-generation.md +22 -0
- package/skills/frontend-engineer/SKILL.md +532 -0
- package/skills/frontend-engineer/references/accessibility-guide.md +146 -0
- package/skills/frontend-engineer/scripts/audit_bundle.py +144 -0
- package/skills/git-workflow/SKILL.md +374 -0
- package/skills/git-workflow/references/git-flow.md +25 -0
- package/skills/mcp-builder/SKILL.md +471 -0
- package/skills/mcp-builder/references/mcp-server-guide.md +23 -0
- package/skills/mobile-engineer/SKILL.md +502 -0
- package/skills/mobile-engineer/references/platform-guidelines.md +160 -0
- package/skills/orchestrator/SKILL.md +246 -0
- package/skills/orchestrator/references/methodology-routing.md +117 -0
- package/skills/orchestrator/references/persona-mapping.md +85 -0
- package/skills/orchestrator/references/routing-logic.md +110 -0
- package/skills/performance-engineer/SKILL.md +549 -0
- package/skills/performance-engineer/references/caching-patterns.md +181 -0
- package/skills/performance-engineer/scripts/profile_endpoint.py +170 -0
- package/skills/product-manager/SKILL.md +488 -0
- package/skills/product-manager/references/prioritization-frameworks.md +126 -0
- package/skills/prompt-engineer/SKILL.md +433 -0
- package/skills/prompt-engineer/references/prompt-patterns.md +158 -0
- package/skills/qa-engineer/SKILL.md +441 -0
- package/skills/qa-engineer/references/testing-strategy.md +166 -0
- package/skills/qa-engineer/scripts/run_coverage.py +147 -0
- package/skills/scrum-master/SKILL.md +225 -0
- package/skills/scrum-master/references/sprint-ceremonies.md +159 -0
- package/skills/security-analyst/SKILL.md +390 -0
- package/skills/security-analyst/references/owasp-top10.md +188 -0
- package/skills/security-analyst/scripts/audit_security.py +242 -0
- package/skills/seo-auditor/SKILL.md +523 -0
- package/skills/seo-auditor/references/seo-checklist.md +17 -0
- package/skills/spec-driven-dev/SKILL.md +342 -0
- package/skills/spec-driven-dev/references/phase-gates.md +107 -0
- package/skills/supabase-expert/SKILL.md +602 -0
- package/skills/supabase-expert/references/supabase-patterns.md +19 -0
- package/skills/swe-agent/SKILL.md +311 -0
- package/skills/swe-agent/references/trajectory-format.md +134 -0
- package/skills/systematic-debugger/SKILL.md +512 -0
- package/skills/systematic-debugger/references/debugging-guide.md +12 -0
- package/skills/tech-lead/SKILL.md +409 -0
- package/skills/tech-lead/references/code-review-checklist.md +111 -0
- package/skills/technical-writer/SKILL.md +631 -0
- package/skills/technical-writer/references/doc-templates.md +218 -0
- package/skills/testing-strategist/SKILL.md +476 -0
- package/skills/testing-strategist/references/testing-pyramid.md +16 -0
- package/skills/ux-ui-designer/SKILL.md +419 -0
- package/skills/ux-ui-designer/references/design-system-foundation.md +168 -0
- package/skills_overview.txt +94 -0
- package/templates/PROJECT_KICKOFF.md +284 -0
- package/templates/SKILL_TEMPLATE.md +131 -0
- package/templates/USAGE.md +95 -0
- package/templates/agent-python/README.md +71 -0
- package/templates/agent-python/agent.py +272 -0
- package/templates/agent-python/config.yaml +76 -0
- package/templates/agent-python/prompts/system.md +109 -0
- package/templates/agent-python/requirements.txt +7 -0
- package/templates/automation-n8n/README.md +14 -0
- package/templates/automation-n8n/webhook-handler.json +57 -0
- package/templates/backend-node/Dockerfile +12 -0
- package/templates/backend-node/README.md +15 -0
- package/templates/backend-node/package.json +30 -0
- package/templates/backend-node/src/index.ts +19 -0
- package/templates/backend-node/src/routes.ts +7 -0
- package/templates/backend-node/tsconfig.json +22 -0
- package/templates/backend-python/Dockerfile +11 -0
- package/templates/backend-python/README.md +78 -0
- package/templates/backend-python/app/core/config.py +12 -0
- package/templates/backend-python/app/core/database.py +12 -0
- package/templates/backend-python/app/main.py +17 -0
- package/templates/backend-python/app/routers/__init__.py +1 -0
- package/templates/backend-python/app/routers/health.py +7 -0
- package/templates/backend-python/requirements-dev.txt +6 -0
- package/templates/backend-python/requirements.txt +4 -0
- package/templates/backend-python/tests/test_health.py +9 -0
- package/templates/checkpoint.yaml +117 -0
- package/templates/database/README.md +474 -0
- package/templates/frontend-react/README.md +446 -0
- package/templates/plan.yaml +320 -0
- package/templates/session.yaml +125 -0
- package/templates/spec.yaml +229 -0
- package/templates/tasks.yaml +330 -0
- package/workflows/bugfix-backend.md +380 -0
- package/workflows/documentation.md +232 -0
- package/workflows/generate-prd.md +320 -0
- package/workflows/ideation.md +396 -0
- package/workflows/new-agent-ia.md +497 -0
- package/workflows/new-automation.md +374 -0
- package/workflows/new-feature.md +290 -0
- package/workflows/optimize-performance.md +373 -0
- package/workflows/resolve-github-issue.md +524 -0
- package/workflows/security-review.md +291 -0
- package/workflows/spec-driven.md +476 -0
- package/workflows/testing-strategy.md +296 -0
- package/workflows/third-party-integration.md +277 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# CI/CD Patterns Reference — DevOps Engineer
|
|
2
|
+
|
|
3
|
+
> Patrones y mejores prácticas de CI/CD para GitHub Actions y pipelines de despliegue.
|
|
4
|
+
|
|
5
|
+
## Pipeline Estándar
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
|
|
9
|
+
│ COMMIT │──▶│ LINT │──▶│ TEST │──▶│ BUILD │──▶│ DEPLOY │
|
|
10
|
+
└──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘
|
|
11
|
+
│
|
|
12
|
+
┌───────────────┤
|
|
13
|
+
▼ ▼
|
|
14
|
+
┌────────┐ ┌────────┐
|
|
15
|
+
│STAGING │ │ PROD │
|
|
16
|
+
└────────┘ └────────┘
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## GitHub Actions: Patrones Recomendados
|
|
20
|
+
|
|
21
|
+
### 1. CI Básico (Pull Request)
|
|
22
|
+
|
|
23
|
+
```yaml
|
|
24
|
+
# .github/workflows/ci.yml
|
|
25
|
+
name: CI
|
|
26
|
+
|
|
27
|
+
on:
|
|
28
|
+
pull_request:
|
|
29
|
+
branches: [main, dev]
|
|
30
|
+
|
|
31
|
+
concurrency:
|
|
32
|
+
group: ci-${{ github.ref }}
|
|
33
|
+
cancel-in-progress: true
|
|
34
|
+
|
|
35
|
+
jobs:
|
|
36
|
+
lint:
|
|
37
|
+
runs-on: ubuntu-latest
|
|
38
|
+
steps:
|
|
39
|
+
- uses: actions/checkout@v4
|
|
40
|
+
- uses: actions/setup-python@v5
|
|
41
|
+
with:
|
|
42
|
+
python-version: "3.12"
|
|
43
|
+
cache: "pip"
|
|
44
|
+
- run: pip install ruff mypy
|
|
45
|
+
- run: ruff check .
|
|
46
|
+
- run: mypy .
|
|
47
|
+
|
|
48
|
+
test:
|
|
49
|
+
runs-on: ubuntu-latest
|
|
50
|
+
needs: lint
|
|
51
|
+
services:
|
|
52
|
+
postgres:
|
|
53
|
+
image: postgres:16
|
|
54
|
+
env:
|
|
55
|
+
POSTGRES_DB: test_db
|
|
56
|
+
POSTGRES_USER: test_user
|
|
57
|
+
POSTGRES_PASSWORD: test_pass
|
|
58
|
+
ports:
|
|
59
|
+
- 5432:5432
|
|
60
|
+
options: >-
|
|
61
|
+
--health-cmd pg_isready
|
|
62
|
+
--health-interval 10s
|
|
63
|
+
--health-timeout 5s
|
|
64
|
+
--health-retries 5
|
|
65
|
+
steps:
|
|
66
|
+
- uses: actions/checkout@v4
|
|
67
|
+
- uses: actions/setup-python@v5
|
|
68
|
+
with:
|
|
69
|
+
python-version: "3.12"
|
|
70
|
+
cache: "pip"
|
|
71
|
+
- run: pip install -r requirements-dev.txt
|
|
72
|
+
- run: pytest --cov --cov-report=xml
|
|
73
|
+
env:
|
|
74
|
+
DATABASE_URL: postgresql://test_user:test_pass@localhost:5432/test_db
|
|
75
|
+
- uses: codecov/codecov-action@v4
|
|
76
|
+
|
|
77
|
+
build:
|
|
78
|
+
runs-on: ubuntu-latest
|
|
79
|
+
needs: test
|
|
80
|
+
steps:
|
|
81
|
+
- uses: actions/checkout@v4
|
|
82
|
+
- uses: docker/setup-buildx-action@v3
|
|
83
|
+
- uses: docker/build-push-action@v6
|
|
84
|
+
with:
|
|
85
|
+
context: .
|
|
86
|
+
push: false
|
|
87
|
+
tags: app:${{ github.sha }}
|
|
88
|
+
cache-from: type=gha
|
|
89
|
+
cache-to: type=gha,mode=max
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 2. CD con Deploy Automático
|
|
93
|
+
|
|
94
|
+
```yaml
|
|
95
|
+
# .github/workflows/deploy.yml
|
|
96
|
+
name: Deploy
|
|
97
|
+
|
|
98
|
+
on:
|
|
99
|
+
push:
|
|
100
|
+
branches: [main]
|
|
101
|
+
tags: ["v*"]
|
|
102
|
+
|
|
103
|
+
jobs:
|
|
104
|
+
deploy-staging:
|
|
105
|
+
if: github.ref == 'refs/heads/main'
|
|
106
|
+
runs-on: ubuntu-latest
|
|
107
|
+
environment: staging
|
|
108
|
+
steps:
|
|
109
|
+
- uses: actions/checkout@v4
|
|
110
|
+
- name: Deploy to Staging
|
|
111
|
+
run: |
|
|
112
|
+
echo "Deploying to staging..."
|
|
113
|
+
# ssh, docker compose, or cloud CLI
|
|
114
|
+
|
|
115
|
+
deploy-production:
|
|
116
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
117
|
+
runs-on: ubuntu-latest
|
|
118
|
+
environment: production
|
|
119
|
+
needs: deploy-staging
|
|
120
|
+
steps:
|
|
121
|
+
- uses: actions/checkout@v4
|
|
122
|
+
- name: Deploy to Production
|
|
123
|
+
run: |
|
|
124
|
+
echo "Deploying to production..."
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Docker: Mejores Prácticas
|
|
128
|
+
|
|
129
|
+
### Dockerfile Multi-Stage Optimizado
|
|
130
|
+
|
|
131
|
+
```dockerfile
|
|
132
|
+
# Stage 1: Builder
|
|
133
|
+
FROM python:3.12-slim AS builder
|
|
134
|
+
|
|
135
|
+
WORKDIR /app
|
|
136
|
+
RUN pip install --no-cache-dir --upgrade pip
|
|
137
|
+
|
|
138
|
+
COPY requirements.txt .
|
|
139
|
+
RUN pip install --no-cache-dir --user -r requirements.txt
|
|
140
|
+
|
|
141
|
+
# Stage 2: Runtime
|
|
142
|
+
FROM python:3.12-slim
|
|
143
|
+
|
|
144
|
+
# Security: non-root user
|
|
145
|
+
RUN groupadd -r appuser && useradd -r -g appuser appuser
|
|
146
|
+
|
|
147
|
+
WORKDIR /app
|
|
148
|
+
COPY --from=builder /root/.local /root/.local
|
|
149
|
+
COPY . .
|
|
150
|
+
|
|
151
|
+
# Security: set ownership
|
|
152
|
+
RUN chown -R appuser:appuser /app
|
|
153
|
+
USER appuser
|
|
154
|
+
|
|
155
|
+
ENV PATH=/root/.local/bin:$PATH
|
|
156
|
+
ENV PYTHONUNBUFFERED=1
|
|
157
|
+
ENV PYTHONDONTWRITEBYTECODE=1
|
|
158
|
+
|
|
159
|
+
EXPOSE 8000
|
|
160
|
+
|
|
161
|
+
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
|
|
162
|
+
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"
|
|
163
|
+
|
|
164
|
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Docker Compose para Desarrollo
|
|
168
|
+
|
|
169
|
+
```yaml
|
|
170
|
+
# docker-compose.yml
|
|
171
|
+
services:
|
|
172
|
+
api:
|
|
173
|
+
build:
|
|
174
|
+
context: ./backend
|
|
175
|
+
dockerfile: Dockerfile
|
|
176
|
+
ports:
|
|
177
|
+
- "${API_PORT:-8000}:8000"
|
|
178
|
+
env_file: .env
|
|
179
|
+
depends_on:
|
|
180
|
+
db:
|
|
181
|
+
condition: service_healthy
|
|
182
|
+
redis:
|
|
183
|
+
condition: service_healthy
|
|
184
|
+
volumes:
|
|
185
|
+
- ./backend:/app # Hot reload
|
|
186
|
+
restart: unless-stopped
|
|
187
|
+
|
|
188
|
+
frontend:
|
|
189
|
+
build:
|
|
190
|
+
context: ./frontend
|
|
191
|
+
dockerfile: Dockerfile
|
|
192
|
+
ports:
|
|
193
|
+
- "${FRONTEND_PORT:-3000}:3000"
|
|
194
|
+
env_file: .env
|
|
195
|
+
depends_on:
|
|
196
|
+
- api
|
|
197
|
+
restart: unless-stopped
|
|
198
|
+
|
|
199
|
+
db:
|
|
200
|
+
image: postgres:16-alpine
|
|
201
|
+
environment:
|
|
202
|
+
POSTGRES_DB: ${DB_NAME}
|
|
203
|
+
POSTGRES_USER: ${DB_USER}
|
|
204
|
+
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
|
205
|
+
ports:
|
|
206
|
+
- "${DB_PORT:-5432}:5432"
|
|
207
|
+
volumes:
|
|
208
|
+
- pgdata:/var/lib/postgresql/data
|
|
209
|
+
healthcheck:
|
|
210
|
+
test: ["CMD-SHELL", "pg_isready -U ${DB_USER}"]
|
|
211
|
+
interval: 10s
|
|
212
|
+
timeout: 5s
|
|
213
|
+
retries: 5
|
|
214
|
+
restart: unless-stopped
|
|
215
|
+
|
|
216
|
+
redis:
|
|
217
|
+
image: redis:7-alpine
|
|
218
|
+
ports:
|
|
219
|
+
- "${REDIS_PORT:-6379}:6379"
|
|
220
|
+
healthcheck:
|
|
221
|
+
test: ["CMD", "redis-cli", "ping"]
|
|
222
|
+
interval: 10s
|
|
223
|
+
timeout: 5s
|
|
224
|
+
retries: 5
|
|
225
|
+
restart: unless-stopped
|
|
226
|
+
|
|
227
|
+
volumes:
|
|
228
|
+
pgdata:
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Rollback Strategy
|
|
232
|
+
|
|
233
|
+
### Rolling Update (Kubernetes)
|
|
234
|
+
|
|
235
|
+
```yaml
|
|
236
|
+
spec:
|
|
237
|
+
strategy:
|
|
238
|
+
type: RollingUpdate
|
|
239
|
+
rollingUpdate:
|
|
240
|
+
maxSurge: 1
|
|
241
|
+
maxUnavailable: 0
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Blue-Green (Docker Compose)
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
# Deploy new version alongside old
|
|
248
|
+
docker compose -f docker-compose.prod.yml up -d --no-deps --build api-new
|
|
249
|
+
# Test new version
|
|
250
|
+
curl http://localhost:8001/health
|
|
251
|
+
# Switch traffic (update nginx upstream)
|
|
252
|
+
# Remove old version
|
|
253
|
+
docker compose -f docker-compose.prod.yml stop api-old
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Checklist Pre-Deploy
|
|
257
|
+
|
|
258
|
+
- [ ] Tests passing en CI
|
|
259
|
+
- [ ] Docker build exitoso
|
|
260
|
+
- [ ] Environment variables configuradas
|
|
261
|
+
- [ ] Database migrations preparadas
|
|
262
|
+
- [ ] Rollback plan documentado
|
|
263
|
+
- [ ] Monitoring/alertas configuradas
|
|
264
|
+
- [ ] Health check endpoint funcional
|
|
265
|
+
- [ ] Backup de DB antes de migración destructiva
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
LMAgent - Docker Healthcheck Script
|
|
4
|
+
Verifica la salud de servicios Docker: API, DB, Redis.
|
|
5
|
+
|
|
6
|
+
Uso:
|
|
7
|
+
python docker_healthcheck.py --service api --url http://localhost:8000/health
|
|
8
|
+
python docker_healthcheck.py --service postgres --host localhost --port 5432
|
|
9
|
+
python docker_healthcheck.py --service redis --host localhost --port 6379
|
|
10
|
+
python docker_healthcheck.py --all
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import json
|
|
15
|
+
import socket
|
|
16
|
+
import subprocess
|
|
17
|
+
import sys
|
|
18
|
+
import urllib.request
|
|
19
|
+
from datetime import datetime
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def check_http(url: str, timeout: int = 5) -> dict:
|
|
23
|
+
"""Verifica un endpoint HTTP."""
|
|
24
|
+
try:
|
|
25
|
+
req = urllib.request.Request(url, method="GET")
|
|
26
|
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
27
|
+
body = resp.read().decode()
|
|
28
|
+
return {
|
|
29
|
+
"status": "healthy",
|
|
30
|
+
"code": resp.status,
|
|
31
|
+
"response": body[:200],
|
|
32
|
+
}
|
|
33
|
+
except Exception as e:
|
|
34
|
+
return {"status": "unhealthy", "error": str(e)}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def check_tcp(host: str, port: int, timeout: int = 5) -> dict:
|
|
38
|
+
"""Verifica conectividad TCP a un servicio."""
|
|
39
|
+
try:
|
|
40
|
+
sock = socket.create_connection((host, port), timeout=timeout)
|
|
41
|
+
sock.close()
|
|
42
|
+
return {"status": "healthy", "host": host, "port": port}
|
|
43
|
+
except Exception as e:
|
|
44
|
+
return {"status": "unhealthy", "host": host, "port": port, "error": str(e)}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def check_docker_containers() -> dict:
|
|
48
|
+
"""Verifica el estado de contenedores Docker."""
|
|
49
|
+
try:
|
|
50
|
+
result = subprocess.run(
|
|
51
|
+
["docker", "ps", "--format", "{{.Names}}\t{{.Status}}\t{{.Ports}}"],
|
|
52
|
+
capture_output=True, text=True, timeout=10
|
|
53
|
+
)
|
|
54
|
+
containers = []
|
|
55
|
+
for line in result.stdout.strip().split("\n"):
|
|
56
|
+
if line:
|
|
57
|
+
parts = line.split("\t")
|
|
58
|
+
containers.append({
|
|
59
|
+
"name": parts[0] if len(parts) > 0 else "unknown",
|
|
60
|
+
"status": parts[1] if len(parts) > 1 else "unknown",
|
|
61
|
+
"ports": parts[2] if len(parts) > 2 else "",
|
|
62
|
+
})
|
|
63
|
+
return {"status": "ok", "containers": containers}
|
|
64
|
+
except Exception as e:
|
|
65
|
+
return {"status": "error", "error": str(e)}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def check_disk_space() -> dict:
|
|
69
|
+
"""Verifica espacio en disco disponible."""
|
|
70
|
+
try:
|
|
71
|
+
result = subprocess.run(
|
|
72
|
+
["docker", "system", "df", "--format", "{{json .}}"],
|
|
73
|
+
capture_output=True, text=True, timeout=10
|
|
74
|
+
)
|
|
75
|
+
return {"status": "ok", "output": result.stdout.strip()[:500]}
|
|
76
|
+
except Exception as e:
|
|
77
|
+
return {"status": "error", "error": str(e)}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def main():
|
|
81
|
+
parser = argparse.ArgumentParser(
|
|
82
|
+
description="LMAgent Docker Healthcheck — Verifica salud de servicios"
|
|
83
|
+
)
|
|
84
|
+
parser.add_argument("--service", "-s", choices=["api", "postgres", "redis", "docker"])
|
|
85
|
+
parser.add_argument("--url", default="http://localhost:8000/health")
|
|
86
|
+
parser.add_argument("--host", default="localhost")
|
|
87
|
+
parser.add_argument("--port", type=int, default=5432)
|
|
88
|
+
parser.add_argument("--all", action="store_true", help="Verificar todos los servicios")
|
|
89
|
+
|
|
90
|
+
args = parser.parse_args()
|
|
91
|
+
|
|
92
|
+
results = {"timestamp": datetime.now().isoformat(), "checks": {}}
|
|
93
|
+
|
|
94
|
+
if args.all or args.service == "api":
|
|
95
|
+
results["checks"]["api"] = check_http(args.url)
|
|
96
|
+
|
|
97
|
+
if args.all or args.service == "postgres":
|
|
98
|
+
results["checks"]["postgres"] = check_tcp(args.host, 5432)
|
|
99
|
+
|
|
100
|
+
if args.all or args.service == "redis":
|
|
101
|
+
results["checks"]["redis"] = check_tcp(args.host, 6379)
|
|
102
|
+
|
|
103
|
+
if args.all or args.service == "docker":
|
|
104
|
+
results["checks"]["docker"] = check_docker_containers()
|
|
105
|
+
results["checks"]["disk"] = check_disk_space()
|
|
106
|
+
|
|
107
|
+
if args.all and not args.service:
|
|
108
|
+
results["checks"]["api"] = check_http(args.url)
|
|
109
|
+
results["checks"]["postgres"] = check_tcp(args.host, 5432)
|
|
110
|
+
results["checks"]["redis"] = check_tcp(args.host, 6379)
|
|
111
|
+
results["checks"]["docker"] = check_docker_containers()
|
|
112
|
+
|
|
113
|
+
# Output
|
|
114
|
+
print(json.dumps(results, indent=2, ensure_ascii=False))
|
|
115
|
+
|
|
116
|
+
# Exit code
|
|
117
|
+
all_healthy = all(
|
|
118
|
+
c.get("status") in ("healthy", "ok")
|
|
119
|
+
for c in results["checks"].values()
|
|
120
|
+
)
|
|
121
|
+
sys.exit(0 if all_healthy else 1)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
if __name__ == "__main__":
|
|
125
|
+
main()
|