diff --git a/docker/zero-ui/Dockerfile b/docker/zero-ui/Dockerfile index 70212d0..4c70900 100644 --- a/docker/zero-ui/Dockerfile +++ b/docker/zero-ui/Dockerfile @@ -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 -RUN corepack enable -RUN mkdir -p /app/frontend -WORKDIR /app/ +# Enable corepack and create necessary directories in one layer +RUN corepack enable && mkdir -p /app/frontend + +WORKDIR /app + +# Copy package-related files and install dependencies COPY tsconfig.json package.json yarn.lock* .yarnrc.yml ./ 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 -COPY ./frontend /app/frontend +COPY ./frontend /app/frontend/ 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 -COPY --from=frontend-build /app/frontend/build /app/frontend/build/ +WORKDIR /app -RUN corepack enable -RUN mkdir -p /app/backend -WORKDIR /app/ +# Copy package-related files and install dependencies COPY package.json yarn.lock* .yarnrc.yml ./ 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 +# Copy the backend source files 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 ZU_SECURE_HEADERS=true ENV ZU_SERVE_FRONTEND=true -CMD [ "node", "./bin/www" ] +# Expose the application port +EXPOSE 4000 + +# Start the application +CMD ["node", "bin/www.js"] \ No newline at end of file