0
Fork 0
mirror of https://github.com/stonith404/pingvin-share.git synced 2025-01-15 01:14:27 -05:00
pingvin-share/Dockerfile

51 lines
1.6 KiB
Text
Raw Normal View History

2022-12-10 12:31:39 -05:00
# Using node slim because prisma ORM needs libc for ARM builds
2022-12-10 09:34:01 -05:00
# Stage 1: on frontend dependency change
2022-12-10 12:31:39 -05:00
FROM node:18-slim AS frontend-dependencies
WORKDIR /opt/app
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci
2022-12-10 09:34:01 -05:00
# Stage 2: on frontend change
2022-12-10 12:31:39 -05:00
FROM node:18-slim AS frontend-builder
2022-12-10 09:34:01 -05:00
WORKDIR /opt/app
COPY ./frontend .
2022-12-10 09:34:01 -05:00
COPY --from=frontend-dependencies /opt/app/node_modules ./node_modules
RUN npm run build
2022-12-10 09:34:01 -05:00
# Stage 3: on backend dependency change
2022-12-10 12:31:39 -05:00
FROM node:18-slim AS backend-dependencies
WORKDIR /opt/app
COPY backend/package.json backend/package-lock.json ./
RUN npm ci
2022-12-10 09:34:01 -05:00
# Stage 4:on backend change
2022-12-10 12:31:39 -05:00
FROM node:18-slim AS backend-builder
RUN apt-get update && apt-get install -y openssl
2022-12-10 09:34:01 -05:00
WORKDIR /opt/app
COPY ./backend .
2022-12-10 09:34:01 -05:00
COPY --from=backend-dependencies /opt/app/node_modules ./node_modules
RUN npx prisma generate
2022-12-10 09:34:01 -05:00
RUN npm run build && npm prune --production
2022-12-10 09:34:01 -05:00
# Stage 5: Final image
2022-12-10 12:31:39 -05:00
FROM node:18-slim AS runner
ENV NODE_ENV=production
2022-12-10 12:31:39 -05:00
RUN apt-get update && apt-get install -y openssl
2022-12-10 09:34:01 -05:00
2022-12-08 17:21:31 -05:00
WORKDIR /opt/app/frontend
COPY --from=frontend-builder /opt/app/public ./public
2022-12-10 09:34:01 -05:00
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=frontend-builder /opt/app/.next/standalone ./
COPY --from=frontend-builder /opt/app/.next/static ./.next/static
WORKDIR /opt/app/backend
COPY --from=backend-builder /opt/app/node_modules ./node_modules
COPY --from=backend-builder /opt/app/dist ./dist
COPY --from=backend-builder /opt/app/prisma ./prisma
COPY --from=backend-builder /opt/app/package.json ./
2022-12-08 17:21:31 -05:00
WORKDIR /opt/app
EXPOSE 3000
2022-12-10 09:34:01 -05:00
CMD node frontend/server.js & cd backend && npm run prod