2022-12-10 18:31:39 +01:00
|
|
|
# Using node slim because prisma ORM needs libc for ARM builds
|
|
|
|
|
2022-12-10 15:34:01 +01:00
|
|
|
# Stage 1: on frontend dependency change
|
2023-03-14 15:36:35 +01:00
|
|
|
FROM node:19-slim AS frontend-dependencies
|
2022-10-11 22:30:06 +02:00
|
|
|
WORKDIR /opt/app
|
|
|
|
COPY frontend/package.json frontend/package-lock.json ./
|
|
|
|
RUN npm ci
|
2022-12-10 15:34:01 +01:00
|
|
|
|
|
|
|
# Stage 2: on frontend change
|
2023-03-14 15:36:35 +01:00
|
|
|
FROM node:19-slim AS frontend-builder
|
2022-12-10 15:34:01 +01:00
|
|
|
WORKDIR /opt/app
|
2022-10-11 22:30:06 +02:00
|
|
|
COPY ./frontend .
|
2022-12-10 15:34:01 +01:00
|
|
|
COPY --from=frontend-dependencies /opt/app/node_modules ./node_modules
|
2022-10-11 22:30:06 +02:00
|
|
|
RUN npm run build
|
|
|
|
|
2022-12-10 15:34:01 +01:00
|
|
|
# Stage 3: on backend dependency change
|
2023-03-14 15:36:35 +01:00
|
|
|
FROM node:19-slim AS backend-dependencies
|
2022-10-11 22:30:06 +02:00
|
|
|
WORKDIR /opt/app
|
|
|
|
COPY backend/package.json backend/package-lock.json ./
|
|
|
|
RUN npm ci
|
2022-12-10 15:34:01 +01:00
|
|
|
|
|
|
|
# Stage 4:on backend change
|
2023-03-14 15:36:35 +01:00
|
|
|
FROM node:19-slim AS backend-builder
|
2022-12-10 18:31:39 +01:00
|
|
|
RUN apt-get update && apt-get install -y openssl
|
2022-12-10 15:34:01 +01:00
|
|
|
WORKDIR /opt/app
|
2022-10-11 22:30:06 +02:00
|
|
|
COPY ./backend .
|
2022-12-10 15:34:01 +01:00
|
|
|
COPY --from=backend-dependencies /opt/app/node_modules ./node_modules
|
2022-10-11 22:30:06 +02:00
|
|
|
RUN npx prisma generate
|
2022-12-10 15:34:01 +01:00
|
|
|
RUN npm run build && npm prune --production
|
2022-10-11 22:30:06 +02:00
|
|
|
|
2022-12-10 15:34:01 +01:00
|
|
|
# Stage 5: Final image
|
2023-03-14 15:36:35 +01:00
|
|
|
FROM node:19-slim AS runner
|
2023-01-13 10:16:35 +01:00
|
|
|
ENV NODE_ENV=docker
|
2023-04-27 22:31:06 +02:00
|
|
|
RUN apt-get update && apt-get install -y curl openssl
|
2022-12-10 15:34:01 +01:00
|
|
|
|
2022-12-08 23:21:31 +01:00
|
|
|
WORKDIR /opt/app/frontend
|
2022-10-11 22:30:06 +02:00
|
|
|
COPY --from=frontend-builder /opt/app/public ./public
|
2022-12-10 15:34:01 +01:00
|
|
|
COPY --from=frontend-builder /opt/app/.next/standalone ./
|
|
|
|
COPY --from=frontend-builder /opt/app/.next/static ./.next/static
|
2023-03-04 23:29:00 +01:00
|
|
|
COPY --from=frontend-builder /opt/app/public/img /tmp/img
|
2022-10-11 22:30:06 +02:00
|
|
|
|
|
|
|
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 23:21:31 +01:00
|
|
|
WORKDIR /opt/app
|
2022-10-11 22:30:06 +02:00
|
|
|
EXPOSE 3000
|
2023-04-27 22:31:06 +02:00
|
|
|
HEALTHCHECK --interval=10s --timeout=3s CMD curl -f http://localhost:3000/api/health || exit 1
|
|
|
|
|
2023-08-01 12:35:37 +02:00
|
|
|
# HOSTNAME=0.0.0.0 fixes https://github.com/vercel/next.js/issues/51684. It can be removed as soon as the issue is fixed
|
|
|
|
CMD cp -rn /tmp/img /opt/app/frontend/public && HOSTNAME=0.0.0.0 node frontend/server.js & cd backend && npm run prod
|