jbilcke-hf HF staff commited on
Commit
8ace6c1
β€’
1 Parent(s): a571e1e

change Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +54 -28
Dockerfile CHANGED
@@ -1,37 +1,63 @@
1
- FROM node:18
2
-
3
-
4
- ARG DEBIAN_FRONTEND=noninteractive
5
-
6
- RUN apt update
7
-
8
- RUN apt --yes install ffmpeg
9
-
10
- # Set up a new user named "user" with user ID 1000
11
- RUN useradd -o -u 1000 user
12
-
13
- # Switch to the "user" user
14
- USER user
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- # Set home to the user's home directory
17
- ENV HOME=/home/user \
18
- PATH=/home/user/.local/bin:$PATH
19
 
20
- # Set the working directory to the user's home directory
21
- WORKDIR $HOME/app
 
22
 
23
- # Install app dependencies
24
- # A wildcard is used to ensure both package.json AND package-lock.json are copied
25
- # where available (npm@5+)
26
- COPY --chown=user package*.json $HOME/app
27
 
28
- RUN npm install
29
 
30
- RUN npm run build
 
 
 
31
 
32
- # Copy the current directory contents into the container at $HOME/app setting the owner to the user
33
- COPY --chown=user . $HOME/app
34
 
35
  EXPOSE 3000
36
 
37
- CMD [ "npm", "run", "start" ]
 
 
 
1
+ FROM node:18-alpine AS base
2
+
3
+ # Install dependencies only when needed
4
+ FROM base AS deps
5
+ # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
6
+ RUN apk add --no-cache libc6-compat
7
+ WORKDIR /app
8
+
9
+ # Install dependencies based on the preferred package manager
10
+ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
11
+ RUN \
12
+ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
13
+ elif [ -f package-lock.json ]; then npm ci; \
14
+ elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
15
+ else echo "Lockfile not found." && exit 1; \
16
+ fi
17
+
18
+ # Uncomment the following lines if you want to use a secret at buildtime,
19
+ # for example to access your private npm packages
20
+ # RUN --mount=type=secret,id=HF_EXAMPLE_SECRET,mode=0444,required=true \
21
+ # $(cat /run/secrets/HF_EXAMPLE_SECRET)
22
+
23
+ # Rebuild the source code only when needed
24
+ FROM base AS builder
25
+ WORKDIR /app
26
+ COPY --from=deps /app/node_modules ./node_modules
27
+ COPY . .
28
+
29
+ # Next.js collects completely anonymous telemetry data about general usage.
30
+ # Learn more here: https://nextjs.org/telemetry
31
+ # Uncomment the following line in case you want to disable telemetry during the build.
32
+ # ENV NEXT_TELEMETRY_DISABLED 1
33
+
34
+ # RUN yarn build
35
+
36
+ # If you use yarn, comment out this line and use the line above
37
+ RUN npm run build
38
 
39
+ # Production image, copy all the files and run next
40
+ FROM base AS runner
41
+ WORKDIR /app
42
 
43
+ ENV NODE_ENV production
44
+ # Uncomment the following line in case you want to disable telemetry during runtime.
45
+ # ENV NEXT_TELEMETRY_DISABLED 1
46
 
47
+ RUN addgroup --system --gid 1001 nodejs
48
+ RUN adduser --system --uid 1001 nextjs
 
 
49
 
50
+ COPY --from=builder /app/public ./public
51
 
52
+ # Automatically leverage output traces to reduce image size
53
+ # https://nextjs.org/docs/advanced-features/output-file-tracing
54
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
55
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
56
 
57
+ USER nextjs
 
58
 
59
  EXPOSE 3000
60
 
61
+ ENV PORT 3000
62
+
63
+ CMD ["node", "server.js"]