Nixpacks Β· MegaLeads SaaS β€” Build Sin Dockerfile

ConfiguraciΓ³n completa: Next.js 14 + FastAPI Β· GitHub Actions CI/CD Β· Railway deploy

βœ“ Build OK 2 servicios Nixpacks 1.x
0
Dockerfiles escritos
2
Servicios detectados
<4m
Build time (cachΓ©)
ARM64
Plataforma objetivo

🟦 frontend/nixpacks.toml

TOML
frontend/nixpacks.toml
# Auto-detectado: Next.js 14 + Node 20 (.nvmrc)
# Generado por CULTIVA IA Β· skill nixpacks-build

[phases.setup]
nixPkgs = ["nodejs_20", "openssl"]

[phases.install]
cmds = ["npm ci --include=dev"]

[phases.build]
cmds = [
  "npx prisma generate",
  "npm run build"
]

[start]
cmd = "node server.js"

[variables]
NODE_ENV             = "production"
NEXT_TELEMETRY_DISABLED = "1"
# DATABASE_URL β†’ Railway secret (no en repo)

🐍 backend/nixpacks.toml

TOML
backend/nixpacks.toml
# Auto-detectado: Python 3.12 + FastAPI
# psycopg2 nativo (ARM64) + Pillow + FFmpeg

[phases.setup]
nixPkgs = [
  "python312",
  "postgresql_15",  # psycopg2 compile
  "libffi",
  "ffmpeg",         # procesamiento media
  "libvips"         # Pillow optimizado
]

[phases.install]
cmds = [
  "pip install --upgrade pip",
  "pip install -r requirements.txt"
]

[phases.build]
cmds = [
  "python -m compileall app/"
]

[start]
cmd = "gunicorn app.main:app --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:$PORT --workers 4"

⚑ .github/workflows/deploy.yml β€” CI/CD Pipeline

YAML
.github/workflows/deploy.yml
name: MegaLeads Β· Build & Deploy
on:
  push:
    branches: [main]

env:
  REGISTRY: ghcr.io
  IMAGE_FE: ghcr.io/megaleads/frontend
  IMAGE_BE: ghcr.io/megaleads/backend

jobs:
  build-frontend:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Nixpacks
        run: curl -sSL https://nixpacks.com/install.sh | bash

      - name: Build Frontend Image
        run: |
          nixpacks build ./frontend \
            --name $IMAGE_FE:${{ github.sha }} \
            --env NODE_ENV=production \
            --env NEXT_TELEMETRY_DISABLED=1

      - name: Login GHCR & Push
        run: |
          echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
          docker push $IMAGE_FE:${{ github.sha }}
          docker tag  $IMAGE_FE:${{ github.sha }} $IMAGE_FE:latest
          docker push $IMAGE_FE:latest

  build-backend:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Nixpacks
        run: curl -sSL https://nixpacks.com/install.sh | bash

      - name: Build Backend Image
        run: |
          nixpacks build ./backend \
            --name $IMAGE_BE:${{ github.sha }}

      - name: Login GHCR & Push
        run: |
          echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
          docker push $IMAGE_BE:${{ github.sha }}
          docker tag  $IMAGE_BE:${{ github.sha }} $IMAGE_BE:latest
          docker push $IMAGE_BE:latest

  deploy-railway:
    needs: [build-frontend, build-backend]
    runs-on: ubuntu-latest
    steps:
      - name: Deploy to Railway
        run: npx @railway/cli up --detach
        env:
          RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}

πŸ” nixpacks plan ./frontend

CLI OUTPUT
terminal
$ nixpacks plan ./frontend

────────────────────────────────
  Providers    node
  Framework    Next.js
  Node version 20.x (from .nvmrc)
────────────────────────────────

  Phases:

  setup
    nixPkgs: nodejs_20, openssl

  install
    cmds:
      β–Έ npm ci --include=dev

  build
    cmds:
      β–Έ npx prisma generate
      β–Έ npm run build

  start
    cmd: node server.js

────────────────────────────────
  βœ“ Plan generated in 0.3s

πŸ—οΈ nixpacks build ./backend β€” Log

BUILD LOG
build log
$ nixpacks build ./backend --name megaleads/backend

[1/5] β–Ά Detecting providers...
      βœ“ python (requirements.txt)
      βœ“ version: 3.12 (.python-version)

[2/5] β–Ά Setup phase
      Nix packages:
      + python312
      + postgresql_15      (libpq-dev)
      + ffmpeg
      + libvips
      + libffi

[3/5] β–Ά Install phase
      βœ“ pip install --upgrade pip     1.2s
      βœ“ pip install -r requirements.txt  38.4s
        psycopg2 2.9.9   (native ARM64 βœ“)
        Pillow   10.3.0  (libvips βœ“)
        fastapi  0.111.0
        + 47 more packages

[4/5] β–Ά Build phase
      βœ“ python -m compileall app/      0.8s

[5/5] β–Ά Finalizing image
      βœ“ Image size: 487 MB
      βœ“ megaleads/backend:latest

──────────────────────────────
  βœ“ Build completed in 3m 41s

πŸ“Š Nixpacks vs Dockerfile manual β€” Comparativa para MegaLeads

Criterio Dockerfile manual Nixpacks Ganador
Tiempo de configuraciΓ³n inicial 2–4h (investigar, probar, depurar) ~10 min (detecta automΓ‘tico) βœ“ Nixpacks
psycopg2 nativo ARM64 Requiere 15+ lΓ­neas RUN apt-get nixPkgs = ["postgresql_15"] β€” 1 lΓ­nea βœ“ Nixpacks
Reproducibilidad apt puede dar versiones distintas Nix = hash fijo, siempre idΓ©ntico βœ“ Nixpacks
CachΓ© de capas Manual (COPY package.json primero) AutomΓ‘tico por fase βœ“ Nixpacks
Multi-stage builds Control total, pero complejo AutomΓ‘tico (builder / runner) βœ“ Nixpacks
PersonalizaciΓ³n avanzada Control total nixpacks.toml cubre 95% casos β‰ˆ Empate
Mantenimiento a largo plazo Alto (actualizar base image) Bajo (Railway actualiza builders) βœ“ Nixpacks

πŸ”„ Pipeline de build β€” Fases Nixpacks

1
Detect Auto
Nixpacks escanea package.json / requirements.txt / Cargo.toml y selecciona providers
node (Next.js 14) python 3.12 (FastAPI)
2
Setup Nix store
Instala paquetes del sistema desde Nix store (reproducibles, con hash fijo)
nodejs_20 python312 postgresql_15 ffmpeg libvips openssl
3
Install Cached
Instala dependencias de la app (npm ci / pip install) β€” capa cacheada si no cambia lockfile
npm ci --include=dev pip install -r requirements.txt
4
Build
Compila assets / genera cliente Prisma / compila Python
npx prisma generate npm run build python -m compileall app/
5
Start
Entrypoint final de la imagen Docker lista para producciΓ³n
node server.js gunicorn ... --workers 4