Spaces:
Sleeping
Sleeping
Praneeth Yerrapragada commited on
Commit ·
51cce4f
1
Parent(s): 3739969
build: fix docker file for next server
Browse filesBased on https://github.com/xenova/transformers.js/blob/main/examples/next-server/Dockerfile
- Dockerfile +51 -13
Dockerfile
CHANGED
|
@@ -1,24 +1,62 @@
|
|
| 1 |
-
FROM node:20-alpine as
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
PATH=/home/user/.local/bin:$PATH
|
| 7 |
-
WORKDIR $HOME/app
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
# Build the application
|
| 18 |
-
COPY . .
|
| 19 |
RUN npm run build
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# ====================================
|
| 22 |
-
FROM
|
| 23 |
|
| 24 |
CMD ["npm", "run", "start"]
|
|
|
|
| 1 |
+
FROM node:20-alpine as base
|
| 2 |
|
| 3 |
+
# Install dependencies only when needed
|
| 4 |
+
FROM base AS deps
|
| 5 |
+
WORKDIR /app
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Install dependencies based on the preferred package manager
|
| 8 |
+
COPY --link 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
|
| 17 |
+
FROM base AS builder
|
| 18 |
+
WORKDIR /app
|
| 19 |
+
COPY --from=deps --link /app/node_modules ./node_modules
|
| 20 |
+
COPY --link . .
|
| 21 |
|
| 22 |
+
# Next.js collects completely anonymous telemetry data about general usage.
|
| 23 |
+
# Learn more here: https://nextjs.org/telemetry
|
| 24 |
+
# Uncomment the following line in case you want to disable telemetry during the build.
|
| 25 |
+
# ENV NEXT_TELEMETRY_DISABLED 1
|
| 26 |
|
| 27 |
# Build the application
|
|
|
|
| 28 |
RUN npm run build
|
| 29 |
|
| 30 |
+
# If using yarn comment out above and use below instead
|
| 31 |
+
# RUN yarn build
|
| 32 |
+
|
| 33 |
+
# Production image, copy all the files and run next
|
| 34 |
+
FROM base AS runner
|
| 35 |
+
WORKDIR /app
|
| 36 |
+
|
| 37 |
+
ENV NODE_ENV production
|
| 38 |
+
# Uncomment the following line in case you want to disable telemetry during runtime.
|
| 39 |
+
# ENV NEXT_TELEMETRY_DISABLED 1
|
| 40 |
+
|
| 41 |
+
RUN \
|
| 42 |
+
addgroup --system --gid 1001 nodejs; \
|
| 43 |
+
adduser --system --uid 1001 nextjs
|
| 44 |
+
|
| 45 |
+
COPY --from=builder --link /app/public ./public
|
| 46 |
+
|
| 47 |
+
# Automatically leverage output traces to reduce image size
|
| 48 |
+
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
| 49 |
+
COPY --from=builder --link --chown=1001:1001 /app/.next/standalone ./
|
| 50 |
+
COPY --from=builder --link --chown=1001:1001 /app/.next/static ./.next/static
|
| 51 |
+
|
| 52 |
+
USER nextjs
|
| 53 |
+
|
| 54 |
+
EXPOSE 3000
|
| 55 |
+
|
| 56 |
+
ENV PORT 3000
|
| 57 |
+
ENV HOSTNAME 0.0.0.0
|
| 58 |
+
|
| 59 |
# ====================================
|
| 60 |
+
FROM base as release
|
| 61 |
|
| 62 |
CMD ["npm", "run", "start"]
|