Files
pnger/Dockerfile

82 lines
2.0 KiB
Docker

# Stage 1: Build Frontend
FROM node:20-alpine AS frontend-builder
WORKDIR /app/frontend
# Copy frontend package files
COPY frontend/package*.json ./
# Generate lockfile if it doesn't exist, then install dependencies
RUN if [ ! -f package-lock.json ]; then \
echo "Generating package-lock.json..."; \
npm install --package-lock-only; \
fi && \
npm ci
# Copy frontend source and build
COPY frontend/ ./
RUN npm run build
# Stage 2: Build Backend
FROM node:20-alpine AS backend-builder
WORKDIR /app/backend
# Copy backend package files
COPY backend/package*.json ./
# Generate lockfile if it doesn't exist, then install dependencies
RUN if [ ! -f package-lock.json ]; then \
echo "Generating package-lock.json..."; \
npm install --package-lock-only; \
fi && \
npm ci
# Copy backend source and compile TypeScript
COPY backend/ ./
RUN npm run build
# Stage 3: Production Runtime
FROM node:20-alpine
WORKDIR /app
# Copy backend package files
COPY backend/package*.json ./
# Generate lockfile if it doesn't exist, then install production dependencies only
RUN if [ ! -f package-lock.json ]; then \
echo "Generating package-lock.json..."; \
npm install --package-lock-only; \
fi && \
npm ci --omit=dev && \
npm cache clean --force
# Copy compiled backend from builder
COPY --from=backend-builder /app/backend/dist ./dist
# Copy built frontend into public directory for Express to serve
COPY --from=frontend-builder /app/frontend/dist ./dist/public
# Create temp upload directory
RUN mkdir -p /app/temp && \
chown -R node:node /app
# Switch to non-root user
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 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
# Start server
CMD ["node", "dist/index.js"]