Files
prayer-app/Dockerfile
T
nmemmert 6b0713612d Implement scheduled email reminders
- Add cron service to Docker container for automated email sending
- Create /api/send-scheduled-emails endpoint for cron job calls
- Modify prayer submission to store user reminder preferences instead of sending immediate emails
- Update Firestore rules to allow server-side API access for scheduled emails
- Add userId to prayers for proper user association
- Cron runs every 5 minutes to check and send scheduled reminders
2025-10-22 14:20:21 -04:00

75 lines
2.3 KiB
Docker

# Use the official Node.js 20 Alpine image as the base
FROM node:20-alpine AS base
# Install dependencies and build in the same stage for simplicity
FROM base AS builder
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Copy package files
COPY package.json package-lock.json* ./
# Install all dependencies (including dev dependencies)
RUN npm ci
# Copy source code
COPY . .
# Set environment for build
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
RUN npm run build || (echo "Build failed, showing logs:" && cat /tmp/build.log 2>/dev/null || echo "No build log found" && exit 1)
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Install cron and curl for scheduled tasks
RUN apk add --no-cache dcron curl
# Create cron log directory
RUN mkdir -p /var/log/cron && chown nextjs:nodejs /var/log/cron
COPY --from=builder /app/public ./public
# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT=3000
# set hostname to localhost
ENV HOSTNAME="0.0.0.0"
# Create cron jobs for scheduled emails
RUN echo "*/5 * * * * curl -s http://localhost:3000/api/send-scheduled-emails >> /var/log/cron/scheduled-emails.log 2>&1" > /etc/crontabs/nextjs
# Make sure cron files have correct permissions
RUN chown nextjs:nodejs /etc/crontabs/nextjs
# Create startup script
RUN echo '#!/bin/sh' > /app/start.sh && \
echo 'crond -f -l 8 &' >> /app/start.sh && \
echo 'exec "$@"' >> /app/start.sh && \
chmod +x /app/start.sh
# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD ["/app/start.sh", "node", "server.js"]