-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Dockerfile
53 lines (40 loc) 路 1.48 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Use the official Node.js 20 image.
# https://hub.docker.com/_/node
FROM node:20-alpine
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
# Create and change to the app directory.
WORKDIR /app
# Declare build arguments.
ARG REDDIT_CLIENT_ID
ARG REDDIT_CLIENT_SECRET
# Set environment variable.
ENV REDDIT_CLIENT_ID=$REDDIT_CLIENT_ID
ENV REDDIT_CLIENT_SECRET=$REDDIT_CLIENT_SECRET
ENV NEXT_TELEMETRY_DISABLED 1
ENV PORT 3000
# Install dependencies based on the preferred package manager.
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
# Install PM2.
RUN npm install -g pm2
# Install production dependencies.
RUN npm ci
# Set the user to non-root and create necessary directories.
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Change the ownership of the app directory to the nodejs user.
RUN chown nextjs:nodejs /app
# Copy local code to the container image.
COPY . .
# Expose the port the app runs on.
EXPOSE 3000
# Build the application for production.
RUN npm run build
# Run the web service on container startup.
CMD ["pm2-runtime", "start", "npm", "--", "start"]