62 lines
2.1 KiB
Docker
62 lines
2.1 KiB
Docker
# Etapa 1: Build del servidor
|
|
FROM node:22-alpine AS build-server
|
|
|
|
WORKDIR /app/server
|
|
COPY server/package*.json ./
|
|
RUN npm install --production --omit=dev \
|
|
&& npm cache clean --force \
|
|
&& rm -rf /root/.npm /tmp/* # Limpiar caché de npm y archivos temporales
|
|
|
|
COPY server ./
|
|
RUN npx tsoa spec-and-routes && npm run build \
|
|
&& rm -rf /app/server/src /app/server/tests # Eliminar archivos innecesarios de source y test
|
|
|
|
# Etapa 2: Build del cliente
|
|
FROM node:22-alpine AS build-client
|
|
|
|
WORKDIR /app/txclient
|
|
COPY txclient/package*.json ./
|
|
RUN npm install --production --omit=dev \
|
|
&& npm cache clean --force \
|
|
&& rm -rf /root/.npm /tmp/* # Limpiar caché de npm y archivos temporales
|
|
|
|
COPY txclient ./
|
|
RUN npm run build \
|
|
&& rm -rf /app/txclient/src /app/txclient/tests /app/txclient/node_modules # Eliminar archivos innecesarios de source y test
|
|
|
|
# Etapa final: Solo lo necesario para correr
|
|
FROM node:22-alpine AS production
|
|
|
|
ENV NODE_ENV=production \
|
|
TZ=America/Argentina/Buenos_Aires
|
|
|
|
# Configurar timezone y bash
|
|
RUN apk add --no-cache tzdata bash && \
|
|
cp /usr/share/zoneinfo/${TZ} /etc/localtime && \
|
|
echo "${TZ}" > /etc/timezone
|
|
|
|
# Crear estructura final
|
|
WORKDIR /app
|
|
|
|
# Copiar sólo los archivos de distribución y node_modules necesarios
|
|
# Server
|
|
COPY --from=build-server /app/server/build ./server/build
|
|
COPY --from=build-server /app/server/package.json ./server/
|
|
COPY --from=build-server /app/server/node_modules ./server/node_modules
|
|
|
|
# Cliente
|
|
COPY --from=build-client /app/txclient/.next ./txclient/.next
|
|
COPY --from=build-client /app/txclient/package.json ./txclient/
|
|
|
|
# Limpiar los archivos innecesarios del entorno de producción
|
|
RUN rm -rf /app/txclient/tests /app/server/tests /app/txclient/src /app/server/src \
|
|
&& rm -rf /app/server/package*.json /app/txclient/package*.json \
|
|
&& rm -rf /app/txclient/node_modules /app/server/node_modules \
|
|
&& rm -rf /app/server/.npm /app/txclient/.npm /tmp/* # Limpiar caches y node_modules no necesarios
|
|
|
|
# Puertos que usas
|
|
EXPOSE 3000 3001 3021
|
|
|
|
# Comando de inicio
|
|
CMD [ "sh", "-c", "npm --prefix /app/server start & npm --prefix /app/txclient start" ]
|