discount/Dockerfile
jmcqueen 086edd5fe0 Add admin token-protected REST API and web UI for managing codes/members
- Require ADMIN_TOKEN bearer auth on /members and new /schedule CRUD routes
- Validate JSON body shape and reject empty/malformed writes so a
  bad multipart POST can no longer wipe authorized.json
- Make saveJSON atomic (tmp -> rename) with a one-generation .bak file
- Serve a self-contained admin SPA at /admin (public/admin.html) for
  editing the discount schedule and authorized members without hand-
  editing JSON, with a /preview endpoint that renders the bot's
  fallback text for draft entries
- Dockerfile now copies public/ into the image

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 11:50:21 -04:00

49 lines
No EOL
1.3 KiB
Docker

# ====================== BUILD STAGE ======================
FROM node:20-alpine AS builder
WORKDIR /app
# Copy package files first for better caching
COPY package*.json ./
# Install production dependencies only
RUN npm ci --only=production
# Copy only the application code (NO config folder)
COPY index.js ./
COPY public ./public
# ====================== PRODUCTION STAGE ======================
FROM node:20-alpine AS production
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && \
adduser -S -u 1001 -G nodejs nodejs
WORKDIR /app
# Copy built artifacts from builder stage
COPY --from=builder --chown=nodejs:nodejs /app/package*.json ./
COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=nodejs:nodejs /app/index.js ./
COPY --from=builder --chown=nodejs:nodejs /app/public ./public
# Create logs directory (will be mounted)
RUN mkdir -p /app/logs && chown nodejs:nodejs /app/logs
# Default environment
ENV NODE_ENV=production
ENV PORT=1977
# Switch to non-root user
USER nodejs
# Expose port
EXPOSE 1977
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:1977/status || exit 1
# Start the bot
CMD ["node", "index.js"]