-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
47 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |