Skip to main content

Deploy com Docker

Dockerfile

FROM python:3.12-slim

WORKDIR /app

COPY pyproject.toml ./
COPY src/ ./src/

RUN pip install --no-cache-dir .

EXPOSE 8000

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000", "--app-dir", "src"]

Build

docker build -t raro-reviewer .

Executar

docker run --rm -p 8000:8000 \
-e GITLAB_URL="https://gitlab.com/api/v4" \
-e GITLAB_TOKEN="glpat-xxxx" \
-e GITLAB_WEBHOOK_SECRET="seu-segredo" \
-e NVIDIA_API_KEY="nvapi-xxxx" \
raro-reviewer

Docker Compose

version: "3.8"

services:
raro-reviewer:
build: .
ports:
- "8000:8000"
environment:
- GITLAB_URL=https://gitlab.com/api/v4
- GITLAB_TOKEN=${GITLAB_TOKEN}
- GITLAB_WEBHOOK_SECRET=${GITLAB_WEBHOOK_SECRET}
- NVIDIA_API_KEY=${NVIDIA_API_KEY}
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/healthz"]
interval: 30s
timeout: 5s
retries: 3
# Usando arquivo .env
docker compose up -d

Kubernetes (GKE)

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
name: raro-reviewer
spec:
replicas: 2
selector:
matchLabels:
app: raro-reviewer
template:
metadata:
labels:
app: raro-reviewer
spec:
containers:
- name: raro-reviewer
image: gcr.io/seu-projeto/raro-reviewer:latest
ports:
- containerPort: 8000
envFrom:
- secretRef:
name: raro-reviewer-secrets
livenessProbe:
httpGet:
path: /healthz
port: 8000
initialDelaySeconds: 5
periodSeconds: 30
readinessProbe:
httpGet:
path: /healthz
port: 8000
initialDelaySeconds: 3
periodSeconds: 10
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "500m"

Secret

kubectl create secret generic raro-reviewer-secrets \
--from-literal=GITLAB_URL="https://gitlab.com/api/v4" \
--from-literal=GITLAB_TOKEN="glpat-xxxx" \
--from-literal=GITLAB_WEBHOOK_SECRET="seu-segredo" \
--from-literal=NVIDIA_API_KEY="nvapi-xxxx"

Service + Ingress

apiVersion: v1
kind: Service
metadata:
name: raro-reviewer
spec:
selector:
app: raro-reviewer
ports:
- port: 80
targetPort: 8000
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: raro-reviewer
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
rules:
- host: reviewer.seudominio.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: raro-reviewer
port:
number: 80

Health Check

O endpoint /healthz retorna:

{"status": "ok"}

Uso recomendado:

  • Docker: HEALTHCHECK no Dockerfile ou healthcheck no Compose
  • Kubernetes: livenessProbe e readinessProbe
  • Load Balancer: Health check path /healthz