65 lines
1.6 KiB
Docker
65 lines
1.6 KiB
Docker
# HealthSync - AI 건강 코치 Dockerfile
|
|
# Multi-stage build for optimized React application
|
|
|
|
# Stage 1: Dependencies installation
|
|
FROM node:18-alpine AS deps
|
|
WORKDIR /app
|
|
|
|
# Copy package files for better caching
|
|
COPY package*.json ./
|
|
|
|
# Install ALL dependencies (needed for build)
|
|
RUN npm ci && npm cache clean --force
|
|
|
|
# Stage 2: Build application
|
|
FROM node:18-alpine AS builder
|
|
WORKDIR /app
|
|
|
|
# Copy dependencies from previous stage
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Set build environment variables
|
|
ENV CI=false
|
|
ENV NODE_ENV=production
|
|
|
|
# Build the application
|
|
RUN npm run build
|
|
|
|
# Stage 3: Production runtime
|
|
FROM node:18-alpine AS runner
|
|
|
|
# Install wget for health check (alpine doesn't have curl by default)
|
|
RUN apk add --no-cache wget
|
|
|
|
# Create non-root user for security
|
|
RUN addgroup -g 1001 -S healthsync && \
|
|
adduser -S healthsync -u 1001 -G healthsync
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Install serve locally for better security
|
|
RUN npm init -y && npm install serve@14.2.1
|
|
|
|
# Copy built application from builder stage
|
|
COPY --from=builder /app/build ./build
|
|
|
|
# Change ownership to non-root user
|
|
RUN chown -R healthsync:healthsync /app
|
|
|
|
# Expose port 3000
|
|
EXPOSE 3000
|
|
|
|
# Switch to non-root user
|
|
USER healthsync
|
|
|
|
# Health check using wget instead of curl
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1
|
|
|
|
# Start the application using npx to run local serve
|
|
CMD ["npx", "serve", "-s", "build", "-l", "3000", "--no-clipboard"]
|