backend: Update Dockerfile and create_image.sh for improved build process and dependency management
This commit is contained in:
parent
d713edcc28
commit
0573a98109
@ -1,75 +1,58 @@
|
|||||||
### Stage 0: Build common types library
|
# ====================================================
|
||||||
FROM node:20 as build-common-types
|
# Stage 1: builder
|
||||||
|
# ====================================================
|
||||||
|
FROM node:22.14.0-alpine3.21 AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN mkdir -p types frontend backend && chown -R node:node /app
|
||||||
|
|
||||||
USER node
|
USER node
|
||||||
|
|
||||||
WORKDIR /app/meet-common-types
|
COPY --chown=node:node frontend/package*.json ./frontend/
|
||||||
|
COPY --chown=node:node backend/package*.json ./backend/
|
||||||
COPY --chown=node:node types/ ./
|
COPY --chown=node:node types/package*.json ./types/
|
||||||
|
COPY --chown=node:node . .
|
||||||
RUN npm install && \
|
|
||||||
npm run build:prod && \
|
|
||||||
npm pack && \
|
|
||||||
rm -rf node_modules dist
|
|
||||||
|
|
||||||
|
|
||||||
### Stage 1: Build the frontend
|
|
||||||
FROM node:20 as build-frontend
|
|
||||||
|
|
||||||
USER node
|
|
||||||
|
|
||||||
WORKDIR /app/frontend
|
WORKDIR /app/frontend
|
||||||
|
|
||||||
ARG BASE_HREF=/
|
ARG BASE_HREF=/
|
||||||
|
|
||||||
COPY --chown=node:node frontend/ ./
|
RUN npm install
|
||||||
COPY --from=build-common-types /app/meet-common-types/openvidu-meet-common-types-**.tgz ./
|
# Sync types from the types package
|
||||||
|
RUN npm run types:sync
|
||||||
RUN npm install && \
|
# Build the fronted for production
|
||||||
npm run lib:build && \
|
RUN npm run build:prod ${BASE_HREF}
|
||||||
npm run lib:pack && \
|
|
||||||
mv dist/shared-meet-components/shared-meet-components-**.tgz . && \
|
|
||||||
npm install shared-meet-components-**.tgz && \
|
|
||||||
npm run build:prod ${BASE_HREF}
|
|
||||||
|
|
||||||
### Stage 2: Build the backend
|
|
||||||
FROM node:20 as build-backend
|
|
||||||
|
|
||||||
USER node
|
|
||||||
|
|
||||||
WORKDIR /app/backend
|
WORKDIR /app/backend
|
||||||
|
|
||||||
COPY --chown=node:node backend/package*.json ./
|
|
||||||
COPY --from=build-common-types /app/meet-common-types/openvidu-meet-common-types-**.tgz ./
|
|
||||||
|
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
# Sync types from the types package
|
||||||
COPY --chown=node:node backend/ ./
|
RUN npm run types:sync
|
||||||
|
# Build the backend for production
|
||||||
RUN mkdir -p /app/backend/dist/src && chown -R node:node /app/backend/dist
|
|
||||||
|
|
||||||
# Copy static files from the frontend build
|
|
||||||
COPY --from=build-frontend /app/frontend/dist/openvidu-meet /app/backend/dist/public
|
|
||||||
|
|
||||||
RUN npm run build:prod
|
RUN npm run build:prod
|
||||||
|
|
||||||
|
# ====================================================
|
||||||
### Stage 3: Final production image
|
# Stage 2: production
|
||||||
FROM node:20-alpine as production
|
# ====================================================
|
||||||
|
FROM node:22.14.0-alpine3.21 AS production
|
||||||
|
|
||||||
WORKDIR /opt/openvidu-meet
|
WORKDIR /opt/openvidu-meet
|
||||||
|
|
||||||
COPY --from=build-common-types /app/meet-common-types/openvidu-meet-common-types-**.tgz ./
|
COPY backend/package*.json ./
|
||||||
COPY --from=build-backend /app/backend/dist ./dist
|
RUN npm ci --production
|
||||||
COPY --from=build-backend /app/backend/package*.json ./
|
|
||||||
|
|
||||||
RUN npm install --production && npm cache clean --force
|
# Copy the frontend and backend from the builder
|
||||||
|
COPY --from=builder /app/backend/dist ./dist
|
||||||
|
COPY --from=builder /app/backend/public ./dist/public
|
||||||
|
|
||||||
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
|
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||||
|
|
||||||
RUN chmod +x /usr/local/bin/entrypoint.sh && \
|
RUN chmod +x /usr/local/bin/entrypoint.sh && \
|
||||||
chown -R node:node /opt/openvidu-meet
|
chown -R node:node /opt/openvidu-meet
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
EXPOSE $SERVER_PORT
|
EXPOSE $SERVER_PORT
|
||||||
|
|
||||||
CMD ["/usr/local/bin/entrypoint.sh"]
|
CMD ["/usr/local/bin/entrypoint.sh"]
|
||||||
|
|||||||
@ -3,7 +3,8 @@
|
|||||||
IMAGE=${1:-?echo "Error: You need to specify an image name as first argument"?}
|
IMAGE=${1:-?echo "Error: You need to specify an image name as first argument"?}
|
||||||
if [[ -n $IMAGE ]]; then
|
if [[ -n $IMAGE ]]; then
|
||||||
cd ..
|
cd ..
|
||||||
export BUILDKIT_PROGRESS=plain && docker build --pull --no-cache --rm=true -f docker/Dockerfile -t "$IMAGE" --build-arg BASE_HREF=/ .
|
export BUILDKIT_PROGRESS=plain && \
|
||||||
|
docker build --pull --no-cache --rm=true -f docker/Dockerfile -t "$IMAGE" --build-arg BASE_HREF=/ .
|
||||||
echo "Docker image '$IMAGE' built successfully."
|
echo "Docker image '$IMAGE' built successfully."
|
||||||
else
|
else
|
||||||
echo "Error: You need to specify an image name as first argument"
|
echo "Error: You need to specify an image name as first argument"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user