2023-09-21 09:04:02 -05:00
|
|
|
|
# Stage 1: Frontend dependencies
|
|
|
|
|
FROM node:20-alpine AS frontend-dependencies
|
2022-10-11 15:30:06 -05:00
|
|
|
|
WORKDIR /opt/app
|
|
|
|
|
COPY frontend/package.json frontend/package-lock.json ./
|
|
|
|
|
RUN npm ci
|
2022-12-10 09:34:01 -05:00
|
|
|
|
|
2023-09-21 09:04:02 -05:00
|
|
|
|
# Stage 2: Build frontend
|
|
|
|
|
FROM node:20-alpine AS frontend-builder
|
2022-12-10 09:34:01 -05:00
|
|
|
|
WORKDIR /opt/app
|
2022-10-11 15:30:06 -05:00
|
|
|
|
COPY ./frontend .
|
2022-12-10 09:34:01 -05:00
|
|
|
|
COPY --from=frontend-dependencies /opt/app/node_modules ./node_modules
|
2022-10-11 15:30:06 -05:00
|
|
|
|
RUN npm run build
|
|
|
|
|
|
2023-09-21 09:04:02 -05:00
|
|
|
|
# Stage 3: Backend dependencies
|
|
|
|
|
FROM node:20-alpine AS backend-dependencies
|
2023-10-22 09:09:53 -05:00
|
|
|
|
RUN apk add --no-cache python3
|
2022-10-11 15:30:06 -05:00
|
|
|
|
WORKDIR /opt/app
|
|
|
|
|
COPY backend/package.json backend/package-lock.json ./
|
|
|
|
|
RUN npm ci
|
2022-12-10 09:34:01 -05:00
|
|
|
|
|
2023-09-21 09:04:02 -05:00
|
|
|
|
# Stage 4: Build backend
|
|
|
|
|
FROM node:20-alpine AS backend-builder
|
2024-12-18 10:22:03 -05:00
|
|
|
|
RUN apk add openssl
|
|
|
|
|
|
2022-12-10 09:34:01 -05:00
|
|
|
|
WORKDIR /opt/app
|
2022-10-11 15:30:06 -05:00
|
|
|
|
COPY ./backend .
|
2022-12-10 09:34:01 -05:00
|
|
|
|
COPY --from=backend-dependencies /opt/app/node_modules ./node_modules
|
2022-10-11 15:30:06 -05:00
|
|
|
|
RUN npx prisma generate
|
2023-09-21 09:04:02 -05:00
|
|
|
|
RUN npm run build && npm prune --production
|
2022-10-11 15:30:06 -05:00
|
|
|
|
|
2022-12-10 09:34:01 -05:00
|
|
|
|
# Stage 5: Final image
|
2023-09-21 09:04:02 -05:00
|
|
|
|
FROM node:20-alpine AS runner
|
2023-01-13 04:16:35 -05:00
|
|
|
|
ENV NODE_ENV=docker
|
2023-09-11 09:14:42 -05:00
|
|
|
|
|
2024-12-18 10:08:45 -05:00
|
|
|
|
# Delete default node user
|
|
|
|
|
RUN deluser --remove-home node
|
|
|
|
|
|
2024-02-29 08:41:45 -05:00
|
|
|
|
RUN apk update --no-cache \
|
|
|
|
|
&& apk upgrade --no-cache \
|
2024-12-18 10:24:01 -05:00
|
|
|
|
&& apk add --no-cache curl caddy su-exec openssl
|
2023-10-09 04:14:51 -05:00
|
|
|
|
|
2022-12-08 17:21:31 -05:00
|
|
|
|
WORKDIR /opt/app/frontend
|
2022-10-11 15:30:06 -05:00
|
|
|
|
COPY --from=frontend-builder /opt/app/public ./public
|
2022-12-10 09:34:01 -05:00
|
|
|
|
COPY --from=frontend-builder /opt/app/.next/standalone ./
|
|
|
|
|
COPY --from=frontend-builder /opt/app/.next/static ./.next/static
|
2023-03-04 17:29:00 -05:00
|
|
|
|
COPY --from=frontend-builder /opt/app/public/img /tmp/img
|
2022-10-11 15:30:06 -05: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 17:21:31 -05:00
|
|
|
|
WORKDIR /opt/app
|
2023-09-11 09:14:42 -05:00
|
|
|
|
|
2024-12-18 10:08:45 -05:00
|
|
|
|
COPY ./reverse-proxy /etc/caddy
|
|
|
|
|
COPY ./scripts ./scripts
|
|
|
|
|
|
2022-10-11 15:30:06 -05:00
|
|
|
|
EXPOSE 3000
|
2023-09-21 09:04:02 -05:00
|
|
|
|
|
2023-04-27 15:31:06 -05:00
|
|
|
|
HEALTHCHECK --interval=10s --timeout=3s CMD curl -f http://localhost:3000/api/health || exit 1
|
|
|
|
|
|
2024-12-18 10:08:45 -05:00
|
|
|
|
ENTRYPOINT ["sh", "./scripts/docker/create-user.sh"]
|
|
|
|
|
CMD ["sh", "./scripts/docker/entrypoint.sh"]
|