Create Dockerfile
Browse files- Dockerfile +66 -0
Dockerfile
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Adapted from https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
|
2 |
+
# For more information, see https://nextjs.org/docs/pages/building-your-application/deploying#docker-image
|
3 |
+
|
4 |
+
# Use a base image for building
|
5 |
+
FROM node:18-slim AS base
|
6 |
+
|
7 |
+
# Install git
|
8 |
+
RUN apt-get update && apt-get install -y git
|
9 |
+
|
10 |
+
# Clone the repository and navigate to the next-client folder
|
11 |
+
WORKDIR /app
|
12 |
+
RUN git clone https://github.com/huggingface/transformers.js-examples .
|
13 |
+
|
14 |
+
# Set the working directory to the next-client folder
|
15 |
+
WORKDIR /app/next-client
|
16 |
+
|
17 |
+
# Install dependencies only when needed
|
18 |
+
FROM base AS deps
|
19 |
+
|
20 |
+
# Install dependencies based on the preferred package manager
|
21 |
+
RUN \
|
22 |
+
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
23 |
+
elif [ -f package-lock.json ]; then npm ci; \
|
24 |
+
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
|
25 |
+
else echo "Lockfile not found." && exit 1; \
|
26 |
+
fi
|
27 |
+
|
28 |
+
# Rebuild the source code only when needed
|
29 |
+
FROM base AS builder
|
30 |
+
WORKDIR /app/next-client
|
31 |
+
COPY --from=deps /app/next-client/node_modules ./node_modules
|
32 |
+
COPY . .
|
33 |
+
|
34 |
+
RUN \
|
35 |
+
if [ -f yarn.lock ]; then yarn run build; \
|
36 |
+
elif [ -f package-lock.json ]; then npm run build; \
|
37 |
+
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
|
38 |
+
else echo "Lockfile not found." && exit 1; \
|
39 |
+
fi
|
40 |
+
|
41 |
+
# Production image, copy all the files and run next
|
42 |
+
FROM base AS runner
|
43 |
+
WORKDIR /app/next-client
|
44 |
+
|
45 |
+
ENV NODE_ENV=production
|
46 |
+
|
47 |
+
RUN addgroup --system --gid 1001 nodejs
|
48 |
+
RUN adduser --system --uid 1001 nextjs
|
49 |
+
|
50 |
+
COPY --from=builder /app/next-client/public ./public
|
51 |
+
|
52 |
+
# Set the correct permission for prerender cache
|
53 |
+
RUN mkdir .next
|
54 |
+
RUN chown nextjs:nodejs .next
|
55 |
+
|
56 |
+
# Automatically leverage output traces to reduce image size
|
57 |
+
COPY --from=builder --chown=nextjs:nodejs /app/next-client/.next/standalone ./
|
58 |
+
COPY --from=builder --chown=nextjs:nodejs /app/next-client/.next/static ./.next/static
|
59 |
+
|
60 |
+
USER nextjs
|
61 |
+
|
62 |
+
EXPOSE 3000
|
63 |
+
|
64 |
+
ENV PORT=3000
|
65 |
+
ENV HOSTNAME="0.0.0.0"
|
66 |
+
CMD ["node", "server.js"]
|