feat: docker config
This commit is contained in:
76
Dockerfile
76
Dockerfile
@@ -4,39 +4,67 @@ WORKDIR /app
|
|||||||
|
|
||||||
# Copy shared package.json and install dependencies
|
# Copy shared package.json and install dependencies
|
||||||
COPY package.json package-lock.json ./
|
COPY package.json package-lock.json ./
|
||||||
|
COPY maxun-core/package.json ./maxun-core/package.json
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|
||||||
# --- Backend Stage ---
|
# --- Backend Build Stage ---
|
||||||
FROM base AS backend
|
FROM base AS backend-build
|
||||||
WORKDIR /app/server
|
|
||||||
|
|
||||||
# Copy backend code
|
|
||||||
COPY server/src ./src
|
|
||||||
COPY maxun-core ./maxun-core
|
|
||||||
|
|
||||||
EXPOSE 8080
|
|
||||||
CMD ["npm", "run", "start:server"] # Add an npm script for backend start in package.json
|
|
||||||
|
|
||||||
# --- Frontend Stage ---
|
|
||||||
FROM base AS frontend
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy frontend code, including root-level index.html
|
# Copy TypeScript configs
|
||||||
|
COPY tsconfig*.json ./
|
||||||
|
COPY server/tsconfig.json ./server/
|
||||||
|
|
||||||
|
# Copy ALL source code (both frontend and backend)
|
||||||
|
COPY src ./src
|
||||||
|
# Copy backend code and maxun-core
|
||||||
|
COPY server/src ./server/src
|
||||||
|
COPY maxun-core ./maxun-core
|
||||||
|
|
||||||
|
# Install TypeScript globally and build
|
||||||
|
RUN npm install -g typescript
|
||||||
|
RUN npm run build:server
|
||||||
|
|
||||||
|
# --- Frontend Build Stage ---
|
||||||
|
FROM base AS frontend-build
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy frontend code and configs
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
COPY index.html ./index.html
|
COPY index.html ./index.html
|
||||||
COPY public ./public
|
COPY public ./public
|
||||||
COPY vite.config.js ./
|
COPY vite.config.js ./
|
||||||
|
COPY tsconfig.json ./
|
||||||
|
|
||||||
# Run the Vite build
|
# Build frontend
|
||||||
RUN npm run build && \
|
RUN npm run build
|
||||||
ls -la && \
|
|
||||||
ls -la build # This will help us verify the build output
|
|
||||||
|
|
||||||
# --- Final Stage: Nginx ---
|
# --- Production Stage ---
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine AS production
|
||||||
COPY --from=frontend /app/build /usr/share/nginx/html
|
|
||||||
COPY --from=frontend /app/public/img /usr/share/nginx/html/img
|
|
||||||
|
|
||||||
EXPOSE 80
|
# Install Node.js in the production image
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
RUN apk add --update nodejs npm
|
||||||
|
|
||||||
|
# Copy nginx configuration
|
||||||
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
# Copy built frontend
|
||||||
|
COPY --from=frontend-build /app/build /usr/share/nginx/html
|
||||||
|
COPY --from=frontend-build /app/public/img /usr/share/nginx/html/img
|
||||||
|
|
||||||
|
# Copy built backend and its dependencies
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=backend-build /app/package*.json ./
|
||||||
|
COPY --from=backend-build /app/server/dist ./server/dist
|
||||||
|
COPY --from=backend-build /app/maxun-core ./maxun-core
|
||||||
|
COPY --from=backend-build /app/node_modules ./node_modules
|
||||||
|
|
||||||
|
# Copy start script
|
||||||
|
COPY docker-entrypoint.sh /
|
||||||
|
RUN chmod +x /docker-entrypoint.sh
|
||||||
|
|
||||||
|
EXPOSE 80 8080
|
||||||
|
|
||||||
|
# Start both nginx and node server
|
||||||
|
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||||
|
|
||||||
Reference in New Issue
Block a user