Template: Docker Compose para Django + PostgreSQL + Redis
Docker Compose completo para desarrollo local de Django. Incluye PostgreSQL, Redis, Celery worker, y hot-reload. Copy-paste y funciona.
Pipeline de CI/CD completo con GitHub Actions. Tests, linting, coverage, build de Docker y deploy automático a Railway/Render.
Pipeline completo que ejecuta tests, linting y deploy automático cada vez que haces push. Configúralo una vez y olvídate de deployar manualmente.
name: CI/CD
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test_db
ports: ["5432:5432"]
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install ruff coverage
- name: Lint with ruff
run: ruff check . --output-format=github
- name: Run tests with coverage
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test_db
SECRET_KEY: test-secret-key-not-for-production
DEBUG: "True"
ALLOWED_HOSTS: "*"
run: |
coverage run manage.py test --verbosity=2
coverage report --fail-under=80
coverage xml
- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.xml
deploy:
needs: test
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy to Railway
uses: bervProject/railway-deploy@main
with:
railway_token: ${{ secrets.RAILWAY_TOKEN }}
service: web
En tu repo de GitHub: Settings → Secrets and variables → Actions
# Agregar cache de pip para builds más rápidos (ya incluido arriba)
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip" # Cachea dependencias entre runs
# Ejecutar tests en paralelo (para suites grandes)
- name: Run tests
run: |
pip install pytest-xdist
pytest -n auto # Usa todos los cores disponibles
# Notificación por Slack al fallar
- name: Notify Slack on failure
if: failure()
uses: slackapi/slack-github-action@v1
with:
payload: |
{"text": "❌ CI falló en ${{ github.repository }} - ${{ github.event.head_commit.message }}"}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
--parallel a Django test si tienes >100 tests para acelerarEste recurso incluye un enlace externo. Regístrate para acceder.
Regístrate gratis para descargar archivos, guardar recursos en favoritos, ganar XP y acceder a cursos y el foro de la comunidad.
¿Ya tienes cuenta? Inicia sesión
Autor
Erik Taveras
Creado por
Erik Taveras
Docker Compose completo para desarrollo local de Django. Incluye PostgreSQL, Redis, Celery worker, y hot-reload. Copy-paste y funciona.
Estructura completa para un microservicio con FastAPI, SQLAlchemy, Alembic, Docker y tests con pytest. Listo para producción.
API REST production-ready con DRF. Incluye serializers, viewsets, paginación, filtros, throttling, documentación con drf-spectacular y tests.