Invoice-Builder / Dockerfile
Bhargavssss's picture
Update Dockerfile
169ba80 verified
FROM node:18-alpine AS build
# Install git and dependencies needed for Puppeteer
RUN apk add --no-cache git chromium nss freetype harfbuzz ca-certificates ttf-freefont
WORKDIR /app
# Clone the repository
RUN git clone https://github.com/Bhargav-Ravinuthala/invoify.git .
# Create .npmrc file to skip Puppeteer download
RUN echo "puppeteer_skip_chromium_download=true" > .npmrc
# Set environment variables for Puppeteer
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
# Remove the postinstall script from package.json to prevent it from running
RUN sed -i 's/"postinstall": "node node_modules\/puppeteer\/install.js"/"postinstall": "echo Skipping puppeteer install"/g' package.json || echo "No puppeteer postinstall script found"
# First install all dependencies
RUN npm install
# Build the application
RUN npm run build
FROM node:18-alpine AS production
# Install chromium and dependencies for Puppeteer in production
RUN apk add --no-cache chromium nss freetype harfbuzz ca-certificates ttf-freefont
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
WORKDIR /app
# Copy only what's needed for production
COPY --from=build --chown=nextjs:nodejs /app/.next ./.next
COPY --from=build --chown=nextjs:nodejs /app/node_modules ./node_modules
COPY --from=build --chown=nextjs:nodejs /app/package.json ./package.json
COPY --from=build --chown=nextjs:nodejs /app/public ./public
COPY --from=build --chown=nextjs:nodejs /app/i18n ./i18n
# Set environment variables for Puppeteer in production
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
ENV NODE_ENV production
ENV PORT 3000
# This is critical - make sure temp directories exist and are writable
RUN mkdir -p /tmp/chromium-data-dir && chmod -R 777 /tmp
USER nextjs
EXPOSE 3000
# Use the start command from package.jsonss
CMD ["npm", "start"]