124 lines
4.4 KiB
Docker
124 lines
4.4 KiB
Docker
# syntax=docker/dockerfile:1.7-labs
|
|
|
|
ARG COMPANY
|
|
ARG NODE_IMAGE=node:24-bookworm-slim
|
|
ARG PNPM_VERSION=10.20.0
|
|
|
|
########################
|
|
# 0) Base común
|
|
########################
|
|
FROM ${NODE_IMAGE} AS base
|
|
|
|
ARG COMPANY
|
|
ENV COMPANY=${COMPANY}
|
|
|
|
ENV CI=1 \
|
|
NODE_ENV=production
|
|
RUN corepack enable && corepack prepare pnpm@${PNPM_VERSION} --activate
|
|
|
|
# Librería para FastReport .NET CLI
|
|
RUN apt-get update && apt-get -y install libgdiplus
|
|
|
|
# Instalación de Java & AutoFirma para Debian
|
|
RUN apt-get -y install curl unzip default-jre libnss3-tools
|
|
RUN curl https://firmaelectronica.gob.es/content/dam/firmaelectronica/descargas-software/autofirma19/Autofirma_Linux_Debian.zip --output /tmp/autofirma.zip
|
|
RUN unzip /tmp/autofirma.zip autofirma_*.deb -d /tmp
|
|
RUN dpkg -i /tmp/autofirma_*.deb
|
|
|
|
WORKDIR /repo
|
|
|
|
########################
|
|
# 1) Turborepo prune (reduce contexto)
|
|
########################
|
|
FROM base AS pruner
|
|
|
|
# Copiar archivos raíz necesarios
|
|
COPY turbo.json package.json pnpm-workspace.yaml pnpm-lock.yaml ./
|
|
|
|
# Copiar los directorios relevantes del monorepo
|
|
COPY packages ./packages
|
|
COPY apps ./apps
|
|
COPY modules ./modules
|
|
|
|
# Ejecuta prune para @erp/factuges-server
|
|
RUN npx --yes turbo@2.5.8 prune @erp/factuges-server --docker
|
|
|
|
########################
|
|
# 2) Builder: código + link deps y build
|
|
########################
|
|
FROM base AS builder
|
|
|
|
# Copiamos todo lo “pruned” (json, lock, full)
|
|
COPY --from=pruner /repo/out/full/ ./
|
|
COPY --from=pruner /repo/out/pnpm-lock.yaml ./pnpm-lock.yaml
|
|
|
|
# Instalamos solo lo necesario para prod de los workspaces
|
|
RUN pnpm install --frozen-lockfile --prefer-offline
|
|
|
|
# IMPORTANTE: build de paquetes buildables (utils, logger, etc.) primero
|
|
# Turborepo asegura orden con "dependsOn". Un único comando:
|
|
RUN pnpm -w turbo run build --filter=@erp/factuges-server...
|
|
|
|
########################
|
|
# 3) Runner minimal
|
|
########################
|
|
#FROM ${NODE_IMAGE} AS runner
|
|
FROM base AS runner
|
|
|
|
# Puppeteer / Chrome dependencies - BEGIN
|
|
#
|
|
# Configure default locale (important for chrome-headless-shell).
|
|
#ENV NODE_ENV=production TZ=UTC LANG=es_ES.UTF-8
|
|
|
|
# Install Google Chrome Stable and fonts
|
|
# Note: this installs the necessary libs to make the browser work with Puppeteer.
|
|
# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
|
|
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
|
|
# installs, work.
|
|
#RUN apt-get update \
|
|
# && apt-get install -y wget gnupg \
|
|
# && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
|
|
# && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
|
|
# && apt-get update \
|
|
# && apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
|
|
# --no-install-recommends \
|
|
# && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
# PUPPETEER CONFIG
|
|
#ENV PUPPETEER_SKIP_DOWNLOAD=true \
|
|
# PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome
|
|
#
|
|
# Puppeteer / Chrome dependencies - END
|
|
|
|
# Don't run production as root
|
|
#RUN addgroup --system --gid 1001 expressjs
|
|
#RUN adduser --system --uid 1001 expressjs
|
|
#USER expressjs
|
|
|
|
#COPY --from=builder /repo .
|
|
COPY --from=builder /repo/node_modules ./node_modules
|
|
COPY --from=builder /repo/packages ./packages
|
|
COPY --from=builder /repo/package.json ./package.json
|
|
COPY --from=builder /repo/pnpm-lock.yaml ./pnpm-lock.yaml
|
|
COPY --from=builder /repo/pnpm-workspace.yaml ./pnpm-workspace.yaml
|
|
|
|
COPY --from=builder /repo/apps/server/dist ./apps/server/dist
|
|
#COPY --from=builder /repo/apps/server/.env.${COMPANY} ./apps/server/dist/.env
|
|
COPY --from=builder /repo/apps/server/node_modules ./apps/server/node_modules
|
|
COPY --from=builder /repo/apps/server/package.json ./apps/server/package.json
|
|
|
|
COPY tools/fastreport-cli/publish/linux/FastReportCliGenerator ./tools/FastReportCliGenerator
|
|
RUN chmod +x ./tools/FastReportCliGenerator
|
|
|
|
# Las plantillas estarán en un volumen apuntando a /shared/templates
|
|
|
|
|
|
# Salud del contenedor (ajusta puerto/endpoint)
|
|
#HEALTHCHECK --interval=20s --timeout=3s --retries=5 \
|
|
# CMD node -e "fetch('http://127.0.0.1:'+(process.env.PORT||3002)+'/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
|
|
|
|
EXPOSE 3002
|
|
#CMD ["pnpm","exec", "node", "--env-file=apps/server/dist/.env", "apps/server/dist/index.js"]
|
|
CMD ["pnpm", "exec", "node", "apps/server/dist/index.js"]
|