forked from hegedus-mark/real-quick-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
85 lines (66 loc) · 2.32 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Build stage
FROM node:20-slim AS builder
# Set environment variables
ENV NODE_ENV=production \
NPM_CONFIG_LOGLEVEL=warn \
NODE_OPTIONS=--max-old-space-size=2048 \
PNPM_HOME="/pnpm" \
PATH="$PNPM_HOME:$PATH"
# Install system dependencies and security updates
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends dumb-init && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
corepack enable && \
corepack prepare [email protected] --activate
# Create app directory and set permissions
WORKDIR /app
RUN chown -R node:node /app
# Switch to non-root user
USER node
# Copy package files with correct ownership
COPY --chown=node:node package.json pnpm-lock.yaml ./
# Install dependencies
RUN pnpm install --frozen-lockfile --prod=false
# Copy source files with correct ownership
COPY --chown=node:node . .
# Build the application
RUN pnpm build
# Production stage
FROM node:20-slim AS production
# Set environment variables
ENV NODE_ENV=production \
NPM_CONFIG_LOGLEVEL=warn \
PNPM_HOME="/pnpm" \
PATH="$PNPM_HOME:$PATH" \
HOST=0.0.0.0 \
PORT=3000
# Install system dependencies and security updates
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends dumb-init && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
corepack enable && \
corepack prepare [email protected] --activate
# Create app directory and set permissions
WORKDIR /app
RUN chown -R node:node /app
# Switch to non-root user
USER node
# Copy built application with correct ownership
COPY --chown=node:node --from=builder /app/.output /app/.output
COPY --chown=node:node --from=builder /app/package.json /app/package.json
COPY --chown=node:node --from=builder /app/pnpm-lock.yaml /app/pnpm-lock.yaml
# Install production dependencies only
RUN pnpm install --frozen-lockfile --prod
# Add healthcheck
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "try { require('http').get('http://localhost:' + (process.env.PORT || 3000) + '/api/_health', (res) => res.statusCode === 200 ? process.exit(0) : process.exit(1)); } catch (err) { process.exit(1); }"
# Use dumb-init as PID 1
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
# Start the application
CMD ["node", ".output/server/index.mjs"]
# Expose port
EXPOSE 3000