Invoice-Builder / Dockerfile
Bhargavssss's picture
Update Dockerfile
d1bc520 verified
raw
history blame
1.61 kB
FROM node:18-alpine AS build
# Install git and dependencies needed for Puppeteer
RUN apk add --no-cache git chromium
WORKDIR /app
# Clone the repository
RUN git clone https://github.com/al1abb/invoify .
# 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 for Puppeteer in production
RUN apk add --no-cache chromium
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
# 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
USER nextjs
EXPOSE 3000
# Use the start command from package.json
CMD ["npm", "start"]