notebrook-notes/dockerfile

50 lines
1.6 KiB
Plaintext
Raw Normal View History

2024-08-26 09:20:12 +00:00
# Use the official Node.js image
FROM node:18 AS base
2024-08-23 14:45:28 +00:00
WORKDIR /usr/src/app
# Install dependencies into temp directories
# This will cache them and speed up future builds
FROM base AS install
# Install dependencies for both backend and frontend
2024-08-26 09:20:12 +00:00
COPY backend/package.json backend/package-lock.json /temp/dev/backend/
COPY frontend/package.json frontend/package-lock.json /temp/dev/frontend/
2024-08-23 14:45:28 +00:00
2024-08-26 09:20:12 +00:00
RUN cd /temp/dev/backend && npm install
RUN cd /temp/dev/frontend && npm install
2024-08-23 14:45:28 +00:00
# Install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod/backend /temp/prod/frontend
2024-08-26 09:20:12 +00:00
COPY backend/package.json backend/package-lock.json /temp/prod/backend/
COPY frontend/package.json frontend/package-lock.json /temp/prod/frontend/
2024-08-23 14:45:28 +00:00
2024-08-26 09:20:12 +00:00
RUN cd /temp/prod/backend && npm install --production
RUN cd /temp/prod/frontend && npm install --production
2024-08-23 14:45:28 +00:00
# Build the frontend project
FROM install AS build-frontend
WORKDIR /usr/src/app/frontend
COPY --from=install /temp/dev/frontend/node_modules node_modules
COPY frontend/ .
2024-08-26 09:20:12 +00:00
RUN npm run build
2024-08-23 14:45:28 +00:00
# Prepare for final release
FROM base AS release
WORKDIR /usr/src/app
# Copy production dependencies
COPY --from=install /temp/prod/backend/node_modules backend/node_modules
COPY --from=install /temp/prod/frontend/node_modules frontend/node_modules
# Copy backend source code
COPY backend/ backend/
# Copy the built frontend assets into the backend public directory
COPY --from=build-frontend /usr/src/app/frontend/dist backend/public
# Set the entrypoint to run the backend server
2024-08-26 09:20:12 +00:00
USER node
WORKDIR /usr/src/app/backend
2024-08-23 14:45:28 +00:00
EXPOSE 3000/tcp
2024-08-26 09:20:12 +00:00
ENTRYPOINT [ "npm", "run", "start"]