Programmer-RD-AI
commited on
Commit
·
dc27f0a
1
Parent(s):
8952ed0
Update Dockerfile
Browse files- Dockerfile +8 -33
Dockerfile
CHANGED
|
@@ -1,21 +1,16 @@
|
|
| 1 |
-
# Use Node.js 18 Alpine for smaller image size
|
| 2 |
FROM node:18-alpine AS base
|
| 3 |
|
| 4 |
-
# Install dependencies only when needed
|
| 5 |
FROM base AS deps
|
| 6 |
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
| 7 |
RUN apk add --no-cache libc6-compat
|
| 8 |
WORKDIR /app
|
| 9 |
|
| 10 |
-
|
| 11 |
-
COPY package*.json pnpm-lock.yaml* ./
|
| 12 |
RUN \
|
| 13 |
-
if [ -f
|
| 14 |
-
|
| 15 |
-
elif [ -f
|
| 16 |
-
|
| 17 |
-
else \
|
| 18 |
-
echo "Lockfile not found." && exit 1; \
|
| 19 |
fi
|
| 20 |
|
| 21 |
# Rebuild the source code only when needed
|
|
@@ -24,46 +19,26 @@ WORKDIR /app
|
|
| 24 |
COPY --from=deps /app/node_modules ./node_modules
|
| 25 |
COPY . .
|
| 26 |
|
| 27 |
-
|
| 28 |
-
RUN \
|
| 29 |
-
if [ -f pnpm-lock.yaml ]; then \
|
| 30 |
-
corepack enable pnpm && pnpm run build; \
|
| 31 |
-
else \
|
| 32 |
-
npm run build; \
|
| 33 |
-
fi
|
| 34 |
-
|
| 35 |
-
# Create public directory if it doesn't exist
|
| 36 |
-
RUN mkdir -p ./public
|
| 37 |
|
| 38 |
# Production image, copy all the files and run next
|
| 39 |
FROM base AS runner
|
| 40 |
WORKDIR /app
|
| 41 |
|
| 42 |
-
ENV NODE_ENV
|
| 43 |
-
# Uncomment the following line in case you want to disable telemetry during runtime.
|
| 44 |
-
# ENV NEXT_TELEMETRY_DISABLED 1
|
| 45 |
|
| 46 |
RUN addgroup --system --gid 1001 nodejs
|
| 47 |
RUN adduser --system --uid 1001 nextjs
|
| 48 |
|
| 49 |
COPY --from=builder /app/public ./public
|
| 50 |
|
| 51 |
-
# Set the correct permission for prerender cache
|
| 52 |
-
RUN mkdir .next
|
| 53 |
-
RUN chown nextjs:nodejs .next
|
| 54 |
-
|
| 55 |
-
# Automatically leverage output traces to reduce image size
|
| 56 |
-
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
| 57 |
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
| 58 |
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
| 59 |
|
| 60 |
USER nextjs
|
| 61 |
|
| 62 |
-
# Expose port 3000 (Next.js default)
|
| 63 |
EXPOSE 3000
|
| 64 |
|
| 65 |
-
ENV PORT
|
| 66 |
-
ENV HOSTNAME="0.0.0.0"
|
| 67 |
|
| 68 |
-
# Run the application
|
| 69 |
CMD ["node", "server.js"]
|
|
|
|
|
|
|
| 1 |
FROM node:18-alpine AS base
|
| 2 |
|
|
|
|
| 3 |
FROM base AS deps
|
| 4 |
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
| 5 |
RUN apk add --no-cache libc6-compat
|
| 6 |
WORKDIR /app
|
| 7 |
|
| 8 |
+
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
|
|
|
|
| 9 |
RUN \
|
| 10 |
+
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
| 11 |
+
elif [ -f package-lock.json ]; then npm ci; \
|
| 12 |
+
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
|
| 13 |
+
else echo "Lockfile not found." && exit 1; \
|
|
|
|
|
|
|
| 14 |
fi
|
| 15 |
|
| 16 |
# Rebuild the source code only when needed
|
|
|
|
| 19 |
COPY --from=deps /app/node_modules ./node_modules
|
| 20 |
COPY . .
|
| 21 |
|
| 22 |
+
RUN pnpm run build
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# Production image, copy all the files and run next
|
| 25 |
FROM base AS runner
|
| 26 |
WORKDIR /app
|
| 27 |
|
| 28 |
+
ENV NODE_ENV production
|
|
|
|
|
|
|
| 29 |
|
| 30 |
RUN addgroup --system --gid 1001 nodejs
|
| 31 |
RUN adduser --system --uid 1001 nextjs
|
| 32 |
|
| 33 |
COPY --from=builder /app/public ./public
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
| 36 |
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
| 37 |
|
| 38 |
USER nextjs
|
| 39 |
|
|
|
|
| 40 |
EXPOSE 3000
|
| 41 |
|
| 42 |
+
ENV PORT 3000
|
|
|
|
| 43 |
|
|
|
|
| 44 |
CMD ["node", "server.js"]
|