mirror of
https://github.com/dec0dOS/zero-ui.git
synced 2024-09-20 06:56:05 +08:00
chore: improve Dockerfile
This commit is contained in:
parent
568b411b28
commit
2b79e9dd80
|
@ -1,38 +1,68 @@
|
||||||
FROM --platform=$BUILDPLATFORM node:lts-alpine as frontend-build
|
# Stage 1: Build frontend
|
||||||
|
FROM --platform=$BUILDPLATFORM node:lts-alpine AS frontend-build
|
||||||
|
|
||||||
ENV GENERATE_SOURCEMAP=false
|
ENV GENERATE_SOURCEMAP=false
|
||||||
|
|
||||||
RUN corepack enable
|
# Enable corepack and create necessary directories in one layer
|
||||||
RUN mkdir -p /app/frontend
|
RUN corepack enable && mkdir -p /app/frontend
|
||||||
WORKDIR /app/
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy package-related files and install dependencies
|
||||||
COPY tsconfig.json package.json yarn.lock* .yarnrc.yml ./
|
COPY tsconfig.json package.json yarn.lock* .yarnrc.yml ./
|
||||||
COPY .yarn/ ./.yarn
|
COPY .yarn/ ./.yarn
|
||||||
WORKDIR /app/frontend/
|
|
||||||
COPY ./frontend/package*.json /app/frontend
|
# Set working directory to frontend and copy package files
|
||||||
|
WORKDIR /app/frontend
|
||||||
|
COPY ./frontend/package*.json /app/frontend/
|
||||||
|
|
||||||
|
# Install frontend dependencies and build the frontend
|
||||||
RUN yarn workspaces focus frontend
|
RUN yarn workspaces focus frontend
|
||||||
COPY ./frontend /app/frontend
|
COPY ./frontend /app/frontend/
|
||||||
RUN yarn build
|
RUN yarn build
|
||||||
|
|
||||||
|
# Stage 2: Build backend
|
||||||
|
FROM node:lts-alpine AS backend-build
|
||||||
|
|
||||||
FROM node:lts-alpine
|
# Enable corepack and create necessary directories in one layer
|
||||||
|
RUN corepack enable && mkdir -p /app/backend
|
||||||
|
|
||||||
WORKDIR /app/frontend/build
|
WORKDIR /app
|
||||||
COPY --from=frontend-build /app/frontend/build /app/frontend/build/
|
|
||||||
|
|
||||||
RUN corepack enable
|
# Copy package-related files and install dependencies
|
||||||
RUN mkdir -p /app/backend
|
|
||||||
WORKDIR /app/
|
|
||||||
COPY package.json yarn.lock* .yarnrc.yml ./
|
COPY package.json yarn.lock* .yarnrc.yml ./
|
||||||
COPY .yarn/ ./.yarn
|
COPY .yarn/ ./.yarn
|
||||||
WORKDIR /app/backend/
|
|
||||||
COPY ./backend/package*.json /app/backend
|
# Set working directory to backend and copy package files
|
||||||
|
WORKDIR /app/backend
|
||||||
|
COPY ./backend/package*.json /app/backend/
|
||||||
|
|
||||||
|
# Install backend dependencies
|
||||||
RUN yarn workspaces focus --production backend && yarn cache clean
|
RUN yarn workspaces focus --production backend && yarn cache clean
|
||||||
|
|
||||||
|
# Copy the backend source files
|
||||||
COPY ./backend /app/backend
|
COPY ./backend /app/backend
|
||||||
|
|
||||||
EXPOSE 4000
|
# Final Stage: Production
|
||||||
|
FROM node:lts-alpine
|
||||||
|
|
||||||
|
# Set the working directory to /app/backend
|
||||||
|
WORKDIR /app/backend
|
||||||
|
|
||||||
|
# Copy the built frontend from the frontend-build stage
|
||||||
|
COPY --from=frontend-build /app/frontend/build /app/frontend/build
|
||||||
|
|
||||||
|
# Copy the backend files from the backend-build stage
|
||||||
|
COPY --from=backend-build /app/backend /app/backend
|
||||||
|
COPY --from=backend-build /app/node_modules /app/backend/node_modules
|
||||||
|
|
||||||
|
# Environment variables
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV ZU_SECURE_HEADERS=true
|
ENV ZU_SECURE_HEADERS=true
|
||||||
ENV ZU_SERVE_FRONTEND=true
|
ENV ZU_SERVE_FRONTEND=true
|
||||||
|
|
||||||
CMD [ "node", "./bin/www" ]
|
# Expose the application port
|
||||||
|
EXPOSE 4000
|
||||||
|
|
||||||
|
# Start the application
|
||||||
|
CMD ["node", "bin/www.js"]
|
Loading…
Reference in a new issue