Skip to content

Commit 51cda12

Browse files
committed
chore: merge main into feature/karpathy-lab-init - resolve conflicts
- Accept refactored app/main.py from main - Include consolidated CI/CD workflows - Merge architectural improvements and test configurations - All conflicts resolved
2 parents ed2f661 + 26c2031 commit 51cda12

21 files changed

+589
-1806
lines changed

.github/workflows/ci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CI – Quality Gate
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
push:
7+
branches: [ "feature/**" ]
8+
9+
jobs:
10+
quality:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.11"]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- uses: actions/setup-python@v5
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
23+
- name: Install dependencies
24+
run: |
25+
pip install --upgrade pip
26+
pip install -r requirements.txt
27+
pip install black isort bandit safety pytest pytest-asyncio pytest-cov
28+
29+
- name: Lint
30+
run: |
31+
black --check app
32+
isort --check-only app
33+
34+
- name: Security scan
35+
run: |
36+
bandit -r app -ll
37+
safety check -r requirements.txt || true
38+
39+
- name: Run tests
40+
env:
41+
API_KEY: test-api-key-12345678
42+
SECRET_KEY: test-secret-key-87654321
43+
CORS_ORIGINS: '["*"]'
44+
ENVIRONMENT: testing
45+
DEBUG: false
46+
LOG_LEVEL: INFO
47+
run: pytest -q --disable-warnings --maxfail=1

.github/workflows/deploy.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
1-
name: CD – Deploy to Railway
1+
name: CD – NeuroBank Deployment
22

33
on:
44
push:
5-
branches: [main]
5+
branches: [ main ]
66

77
jobs:
88
deploy:
99
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
packages: write
13+
14+
env:
15+
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/neurobank:${{ github.sha }}
16+
RAILWAY_API: https://backboard.railway.app/graphql
1017

1118
steps:
1219
- uses: actions/checkout@v4
1320

14-
- name: Install Railway CLI
21+
- name: Login to GHCR
1522
run: |
16-
curl -fsSL https://railway.app/install.sh | sh
23+
echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
24+
25+
- name: Build Docker image
26+
run: docker build -t $IMAGE_NAME .
1727

18-
- name: Deploy to Railway
28+
- name: Push Docker image
29+
run: docker push $IMAGE_NAME
30+
31+
# Railway CLI (best-effort)
32+
- name: Try Railway CLI
33+
continue-on-error: true
1934
env:
2035
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
21-
run: railway up --ci
36+
run: |
37+
curl -fsSL https://railway.app/install.sh | sh
38+
railway up || true
Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
1-
name: docker-security
1+
name: Docker Security (Trivy)
22

33
on:
44
pull_request:
55
branches: [ main ]
6-
push:
7-
branches: [ main ]
86
workflow_dispatch:
97

108
jobs:
119
trivy:
12-
name: Trivy Security
1310
runs-on: ubuntu-latest
14-
1511
permissions:
1612
contents: read
1713
security-events: write
1814

1915
steps:
20-
- name: Checkout repository
21-
uses: actions/checkout@v6
16+
- uses: actions/checkout@v4
2217

23-
- name: Run Trivy vulnerability scanner (fs)
24-
uses: aquasecurity/[email protected]
18+
- uses: aquasecurity/[email protected]
2519
with:
26-
scan-type: "fs"
27-
format: "sarif"
28-
output: "trivy-results.sarif"
29-
severity: "CRITICAL,HIGH"
20+
scan-type: fs
21+
format: sarif
22+
output: trivy-results.sarif
23+
severity: CRITICAL,HIGH
3024

31-
- name: Upload SARIF results to GitHub Security
32-
uses: github/codeql-action/upload-sarif@v4
25+
- uses: github/codeql-action/upload-sarif@v4
3326
with:
3427
sarif_file: trivy-results.sarif

.github/workflows/lint.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/workflows/security.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,17 @@ name: CI – Security Scan
22

33
on:
44
pull_request:
5-
branches: [main]
6-
push:
7-
branches:
8-
- "feature/**"
5+
branches: [ main ]
96

107
jobs:
118
security:
129
runs-on: ubuntu-latest
13-
1410
steps:
1511
- uses: actions/checkout@v4
16-
17-
- name: Setup Python
18-
uses: actions/setup-python@v5
12+
- uses: actions/setup-python@v5
1913
with:
2014
python-version: "3.11"
2115

22-
- name: Install security tooling
23-
run: pip install bandit safety
24-
25-
- name: Run Bandit
26-
run: bandit -r app -ll
27-
28-
- name: Dependency vulnerability scan
29-
run: safety check -r requirements.txt || true
16+
- run: pip install bandit safety
17+
- run: bandit -r app -ll
18+
- run: safety check -r requirements.txt || true

.github/workflows/test.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12.3

DOCKER_FIX_DEPLOYED.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

Dockerfile

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,61 @@
1-
# NeuroBank FastAPI Toolkit - Production Dockerfile optimized for Railway
2-
FROM python:3.14-slim
1+
# ============================================
2+
# STAGE 1 — BUILDER
3+
# Compilación limpia, reproducible, sin root
4+
# ============================================
5+
FROM python:3.11-slim AS builder
6+
7+
ENV PYTHONDONTWRITEBYTECODE=1 \
8+
PYTHONUNBUFFERED=1
39

4-
# Establecer el directorio de trabajo
510
WORKDIR /app
611

7-
# Instalar dependencias del sistema optimizado para Railway
8-
RUN apt-get update && apt-get install -y \
9-
gcc \
10-
curl \
11-
&& rm -rf /var/lib/apt/lists/* \
12-
&& apt-get clean
12+
# Dependencias del sistema mínimas y suficientes
13+
RUN apt-get update && apt-get install -y --no-install-recommends \
14+
build-essential \
15+
libpq-dev \
16+
&& rm -rf /var/lib/apt/lists/*
1317

14-
# Copiar archivos de dependencias primero para mejor cache de Docker
18+
# Copiamos dependencias del proyecto
1519
COPY requirements.txt .
1620

17-
# Instalar dependencias de Python con optimizaciones
18-
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
19-
pip install --no-cache-dir -r requirements.txt
21+
# Usamos wheels para maximizar reproducibilidad
22+
RUN pip install --upgrade pip wheel && \
23+
pip wheel --no-cache-dir --no-deps -r requirements.txt -w /wheels
2024

21-
# Copiar el código de la aplicación
22-
COPY ./app ./app
23-
COPY lambda_handler.py .
24-
COPY start.sh .
2525

26-
# Hacer ejecutable el script de inicio
27-
RUN chmod +x start.sh
26+
# ============================================
27+
# STAGE 2 — RUNTIME ULTRALIGHT
28+
# Cero herramientas innecesarias, zero trust
29+
# ============================================
30+
FROM python:3.11-slim AS runtime
2831

29-
# Crear usuario no-root para seguridad y configurar permisos
30-
RUN groupadd -r appuser && useradd -r -g appuser appuser && \
31-
chown -R appuser:appuser /app
32-
USER appuser
32+
ENV PYTHONDONTWRITEBYTECODE=1 \
33+
PYTHONUNBUFFERED=1 \
34+
PATH="/home/appuser/.local/bin:${PATH}"
35+
36+
WORKDIR /app
3337

34-
# Exponer el puerto dinámico de Railway
35-
EXPOSE $PORT
38+
# Crear usuario no-root y seguro
39+
RUN useradd -m appuser
3640

37-
# Configurar variables de entorno optimizadas para Railway
38-
ENV PYTHONPATH=/app
39-
ENV PYTHONUNBUFFERED=1
40-
ENV PYTHONDONTWRITEBYTECODE=1
41-
ENV PORT=8000
42-
ENV ENVIRONMENT=production
43-
ENV WORKERS=1
41+
# Copiar wheels + instalar sin red
42+
COPY --from=builder /wheels /wheels
43+
RUN pip install --no-cache-dir /wheels/*
44+
45+
# Copiamos solo el código (sin tests, sin dev)
46+
COPY app ./app
47+
48+
# Ajustar permisos
49+
RUN chown -R appuser:appuser /app
50+
USER appuser
4451

45-
# Health check específico para Railway con puerto dinámico
46-
HEALTHCHECK --interval=30s --timeout=30s --start-period=10s --retries=3 \
47-
CMD sh -c 'curl -f http://localhost:$PORT/health || exit 1'
52+
# ============================================
53+
# EJECUCIÓN — UVICORN KARPATHIAN MODE
54+
# ============================================
55+
EXPOSE 8000
4856

49-
# Comando optimizado para Railway con puerto dinámico
50-
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port $PORT --workers 1 --loop uvloop --timeout-keep-alive 120 --access-log"]
57+
# Workers definidos por CPU (Karpathy-approved)
58+
CMD ["uvicorn", "app.main:app", \
59+
"--host", "0.0.0.0", \
60+
"--port", "8000", \
61+
"--workers", "2"]

0 commit comments

Comments
 (0)