51 lines
1.0 KiB
Docker
51 lines
1.0 KiB
Docker
FROM node:18-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
COPY yarn.lock ./
|
|
|
|
# Install dependencies
|
|
RUN yarn install --frozen-lockfile
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the application
|
|
RUN yarn build
|
|
|
|
# Production stage
|
|
FROM node:18-alpine AS production
|
|
|
|
WORKDIR /app
|
|
|
|
# Install production dependencies only
|
|
COPY package*.json ./
|
|
COPY yarn.lock ./
|
|
RUN yarn install --frozen-lockfile --production && yarn cache clean
|
|
|
|
# Copy built application
|
|
COPY --from=builder /app/dist ./dist
|
|
COPY --from=builder /app/admin ./admin
|
|
|
|
# Create data directory
|
|
RUN mkdir -p data logs
|
|
|
|
# Create non-root user
|
|
RUN addgroup -g 1001 -S nodejs
|
|
RUN adduser -S nodejs -u 1001
|
|
|
|
# Change ownership
|
|
RUN chown -R nodejs:nodejs /app
|
|
USER nodejs
|
|
|
|
# Expose ports
|
|
EXPOSE 8080 8081
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD node -e "require('http').get('http://localhost:8080/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })"
|
|
|
|
# Start the application
|
|
CMD ["node", "dist/server.js"] |