-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathDockerfile
48 lines (33 loc) · 1.33 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
FROM node:18-alpine AS deps
WORKDIR /app
# Copy only the files needed to install dependencies
COPY package.json pnpm-lock.yaml* ./
# Install dependencies for native module builds
RUN apk update && apk add --no-cache python3 py3-pip build-base gcc
# Install dependencies with the preferred package manager
RUN corepack enable pnpm && pnpm i --frozen-lockfile
FROM node:18-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
# Copy the rest of the files
COPY . .
# Run build with the preferred package manager
RUN corepack enable pnpm && pnpm build
# Set NODE_ENV environment variable
ENV NODE_ENV production
# Re-run install only for production dependencies
RUN corepack enable pnpm && pnpm i --frozen-lockfile --prod
FROM node:18-alpine AS runner
WORKDIR /app
# Create the logs directory and give ownership to the node user
RUN mkdir -p /app/logs && chown -R node:node /app
# Copy the bundled code from the builder stage
COPY --from=builder --chown=node:node /app/dist ./dist
COPY --from=builder --chown=node:node /app/node_modules ./node_modules
COPY --from=builder --chown=node:node /app/src/modules/views ./dist/src/modules/views
# Use the node user from the image
USER node
# Expose application port (optional, specify the port your app uses)
EXPOSE 9000 9001 9002
# Start the server
CMD ["node", "dist/src/main.js"]