feat: update Dockerfile with multi-stage TypeScript build and env vars
This commit is contained in:
37
Dockerfile
37
Dockerfile
@@ -3,27 +3,42 @@ FROM node:20-alpine AS frontend-builder
|
|||||||
|
|
||||||
WORKDIR /app/frontend
|
WORKDIR /app/frontend
|
||||||
|
|
||||||
|
# Copy frontend package files and install ALL dependencies (including devDependencies for build)
|
||||||
COPY frontend/package*.json ./
|
COPY frontend/package*.json ./
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
|
|
||||||
|
# Copy frontend source and build
|
||||||
COPY frontend/ ./
|
COPY frontend/ ./
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Stage 2: Production Server
|
# Stage 2: Build Backend
|
||||||
|
FROM node:20-alpine AS backend-builder
|
||||||
|
|
||||||
|
WORKDIR /app/backend
|
||||||
|
|
||||||
|
# Copy backend package files and install ALL dependencies (including TypeScript)
|
||||||
|
COPY backend/package*.json ./
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
# Copy backend source and compile TypeScript
|
||||||
|
COPY backend/ ./
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Stage 3: Production Runtime
|
||||||
FROM node:20-alpine
|
FROM node:20-alpine
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install production dependencies
|
# Install production dependencies only
|
||||||
COPY backend/package*.json ./
|
COPY backend/package*.json ./
|
||||||
RUN npm ci --only=production && \
|
RUN npm ci --only=production && \
|
||||||
npm cache clean --force
|
npm cache clean --force
|
||||||
|
|
||||||
# Copy backend source
|
# Copy compiled backend from builder
|
||||||
COPY backend/ ./
|
COPY --from=backend-builder /app/backend/dist ./dist
|
||||||
|
|
||||||
# Copy built frontend
|
# Copy built frontend into public directory for Express to serve
|
||||||
COPY --from=frontend-builder /app/frontend/dist ./public
|
COPY --from=frontend-builder /app/frontend/dist ./dist/public
|
||||||
|
|
||||||
# Create temp upload directory
|
# Create temp upload directory
|
||||||
RUN mkdir -p /app/temp && \
|
RUN mkdir -p /app/temp && \
|
||||||
@@ -32,12 +47,18 @@ RUN mkdir -p /app/temp && \
|
|||||||
# Switch to non-root user
|
# Switch to non-root user
|
||||||
USER node
|
USER node
|
||||||
|
|
||||||
|
# Environment variables (can be overridden via Unraid UI)
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV PORT=3000
|
||||||
|
ENV MAX_FILE_SIZE=10485760
|
||||||
|
ENV TEMP_DIR=/app/temp
|
||||||
|
|
||||||
# Expose port
|
# Expose port
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Health check
|
# Health check
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||||
CMD node -e "require('http').get('http://localhost:3000/api/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
|
CMD node -e "require('http').get('http://localhost:3000/', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
|
||||||
|
|
||||||
# Start server
|
# Start server
|
||||||
CMD ["node", "src/server.js"]
|
CMD ["node", "dist/index.js"]
|
||||||
Reference in New Issue
Block a user