diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..96af128 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,43 @@ +# Dependencies +node_modules +.pnp +.pnp.js + +# Testing +coverage + +# Next.js +.next +out + +# Production +build + +# Misc +.DS_Store +*.pem + +# Debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Local env files +.env.local +.env.development.local +.env.test.local +.env.production.local + +# Git +.git +.gitignore + +# IDE +.idea +.vscode +*.swp +*.swo + +# Project specific +README.md +README-old.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..12717aa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,46 @@ +# Build stage +FROM node:alpine AS builder + +# Set working directory +WORKDIR /app + +# Copy package files +COPY package.json yarn.lock ./ + +# Install dependencies +RUN yarn install --frozen-lockfile + +# Copy source files +COPY . . + +# Build application +RUN yarn build + +# Production stage +FROM node:alpine AS runner + +WORKDIR /app + +# Set environment to production +ENV NODE_ENV production + +# Copy necessary files from builder +COPY --from=builder /app/next.config.js ./ +COPY --from=builder /app/public ./public +COPY --from=builder /app/.next ./.next +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/package.json ./package.json + +# Create a non-root user +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs +RUN chown -R nextjs:nodejs /app + +# Switch to non-root user +USER nextjs + +# Expose the port the app runs on +EXPOSE 3000 + +# Start the application +CMD ["yarn", "start"]