# Multi-stage Dockerfile for Quickawards # Uses official Bun runtime image # ============================================ # Stage 1: Dependencies & Database Init # ============================================ FROM oven/bun:1 AS builder WORKDIR /app # Install ALL dependencies (including devDependencies for drizzle-kit) COPY package.json bun.lock ./ RUN bun install --frozen-lockfile # Copy source code (node_modules excluded by .dockerignore) COPY . . # Reinstall frontend dependencies to get correct platform binaries RUN cd src/frontend && bun install # Initialize database using custom script # This creates a fresh database with the correct schema using bun:sqlite RUN bun src/backend/scripts/init-db.js # Build frontend RUN bun run build # ============================================ # Stage 2: Production Image # ============================================ FROM oven/bun:1 AS production WORKDIR /app # Install production dependencies only COPY package.json bun.lock ./ RUN bun install --frozen-lockfile --production # Copy backend source and schema files COPY src/backend ./src/backend COPY award-definitions ./award-definitions COPY drizzle.config.ts ./ # Copy frontend build from builder stage COPY --from=builder /app/src/frontend/build ./src/frontend/build # Copy initialized database from builder (will be used as template) COPY --from=builder /app/src/backend/award.db /app/award.db.template # Copy drizzle migrations (if they exist) COPY --from=builder /app/drizzle ./drizzle # Create directory for database volume mount RUN mkdir -p /data # Copy entrypoint script COPY docker-entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/docker-entrypoint.sh # Set environment variables ENV NODE_ENV=production \ PORT=3001 \ LOG_LEVEL=info # Expose the application port EXPOSE 3001 # Use entrypoint script to handle database initialization ENTRYPOINT ["docker-entrypoint.sh"] # Start the backend server CMD ["bun", "run", "src/backend/index.js"]