Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
149 lines (116 loc) · 4.2 KB
/
Copy pathDockerfile
File metadata and controls
149 lines (116 loc) · 4.2 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Dockerfile (Multi-stage)
# ==========================================
# Stage 0: Node + pnpm
# ==========================================
FROM node:24.22.2-trixie-slim AS node-pnpm
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/*
RUN npm config set fetch-retries 5 \
&& npm config set fetch-retry-factor 2 \
&& npm config set fetch-retry-mintimeout 20000 \
&& npm config set fetch-retry-maxtimeout 120000 \
&& npm config set registry https://registry.npmjs.org/ \
&& npm install -g pnpm@12.16.1
# ==========================================
# Stage 1: Builder
# ==========================================
FROM node-pnpm AS builder
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
python3 \
make \
g++ \
&& rm -rf /var/lib/apt/lists/*
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile --prod=false
ENV NODE_ENV=production
# Build Args need to be declared BEFORE the build step
# Vite bakes VITE_* env vars into the static bundle at build time
ARG VITE_COMMIT_HASH
ARG VITE_BUILD_DATE
ARG VITE_REPO_URL
ARG VITE_BRANCH
ARG VITE_VERSION
# Copy source code
COPY client ./client
COPY server ./server
COPY shared ./shared
COPY scripts ./scripts
COPY tsconfig.json ./
COPY tsup.config.ts ./
COPY vite.config.ts ./
COPY vitest.config.ts ./
COPY vitest.server.config.ts ./
COPY vitest.client.config.ts ./
COPY eslint.config.js ./
COPY docker-entrypoint.sh ./
COPY run.sh ./
COPY run.ps1 ./
# Cache the compact GeoNames dataset in the image so reverse geocoding never
# depends on network access at runtime.
RUN node scripts/download-geonames-data.mjs
# Build the application with VITE_* variables available
RUN pnpm exec vite build \
&& pnpm exec tsup \
&& pnpm prune --prod
# ==========================================
# Stage 2: Shared runner
# ==========================================
FROM node-pnpm AS runner
WORKDIR /app
# Build Args (metadata)
ARG VITE_COMMIT_HASH
ARG VITE_BUILD_DATE
ARG VITE_REPO_URL
ARG VITE_BRANCH
ARG VITE_VERSION
ARG DOCKER_IMAGE_REF=theduffman85/crowdsec-web-ui
# Set Runtime Environment Variables
ENV VITE_COMMIT_HASH=$VITE_COMMIT_HASH
ENV VITE_BUILD_DATE=$VITE_BUILD_DATE
ENV VITE_REPO_URL=$VITE_REPO_URL
ENV VITE_BRANCH=$VITE_BRANCH
ENV VITE_VERSION=$VITE_VERSION
ENV DOCKER_IMAGE_REF=$DOCKER_IMAGE_REF
ENV NODE_ENV=production
# Install gosu (for entrypoint) and apply security updates
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
gosu \
&& rm -rf /var/lib/apt/lists/*
# Copy backend dependencies from builder
COPY --from=builder /app/node_modules ./node_modules
# Copy built application artifacts
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/geonames ./geonames
# Copy runtime files for the existing pnpm start contract
COPY package.json ./
COPY pnpm-workspace.yaml ./
COPY scripts ./scripts
COPY docker-entrypoint.sh /usr/local/bin/
# Set permissions
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Pre-create data directory with correct ownership
# This ensures Docker named volumes inherit the right permissions
RUN mkdir -p /app/data && chown node:node /app/data
# Expose port
EXPOSE 3000
# Health check using Node to hit the health endpoint
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD node -e "fetch('http://localhost:3000/api/health').then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))"
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["node", "dist/server/index.js"]
# ==========================================
# Stage 3: Load-test runner
# ==========================================
FROM runner AS loadtest
# Keep synthetic data away from /app/data so this image can replace the regular
# image in an existing deployment without touching its mounted database.
ENV LOADTEST_DB_DIR="/tmp/crowdsec-web-ui-load-test" \
LOADTEST_PROFILE="default"
COPY docker-loadtest-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-loadtest-entrypoint.sh
ENTRYPOINT ["docker-loadtest-entrypoint.sh"]
CMD ["node", "dist/server/load-test-server.js"]
# Keep the regular image as the default target for plain `docker build` calls.
FROM runner AS production