# Dockerfile con acceso a docker CLI
FROM node:23-slim

WORKDIR /app

# 1) Instalar dependencias normales
COPY package.json package-lock.json* ./
RUN npm install --omit=dev

# 2) Instalar Docker CLI
RUN apt-get update && \
    apt-get install -y ca-certificates curl gnupg && \
    install -m 0755 -d /etc/apt/keyrings && \
    curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
    chmod a+r /etc/apt/keyrings/docker.gpg && \
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian bookworm stable" \
      > /etc/apt/sources.list.d/docker.list && \
    apt-get update && \
    apt-get install -y docker-ce-cli && \
    rm -rf /var/lib/apt/lists/*

# 3) Copiar el código fuente
COPY . .

# 4) Puerto y arranque
ENV PORT=4000
EXPOSE 4000
CMD ["node", "index.js"]
