refactor: docker implementation + health endpoint

This commit is contained in:
Shrev Dev
2025-10-21 10:51:12 -05:00
parent 2389e37286
commit 1d79fca115
7 changed files with 155 additions and 57 deletions
+25 -24
View File
@@ -1,46 +1,47 @@
# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
# Copy package files
# Install deps
COPY package*.json ./
COPY tsconfig.json ./
# Install dependencies
RUN npm ci
# Copy source code
# Build
COPY src ./src
# Build TypeScript
RUN npm run build
# Production stage
# Runtime stage
FROM node:20-alpine
WORKDIR /app
# Copy package files
ENV NODE_ENV=production
# Copy package files and install production deps
COPY package*.json ./
RUN npm ci --only=production && npm cache clean --force
# Install production dependencies only
RUN npm ci --only=production && \
npm cache clean --force
# Copy built application
# Copy built app (make sure dist exists)
COPY --from=builder /app/dist ./dist
# Create non-root user
RUN addgroup -g 1001 -S appuser && \
adduser -u 1001 -S appuser -G appuser
# Create a data directory now (final perms fixed at runtime)
RUN mkdir -p /app/data
# Change ownership
RUN chown -R appuser:appuser /app
# Install su-exec for privilege drop and wget for health checks
RUN apk add --no-cache su-exec wget
# Switch to non-root user
USER appuser
# Add entrypoint
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Start the application
CMD ["node", "dist/index.js"]
# Encourage a named volume by default (optional but nice)
VOLUME ["/app/data"]
# Default PUID/PGID can be overridden at runtime
ENV PUID=1001 PGID=1001 DATA_DIR=/app/data HEALTH_PORT=3000
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1
ENTRYPOINT ["/entrypoint.sh"]
CMD ["node", "dist/index.js"]