Skip to content

Commit 88d8706

Browse files
authored
🐋 ci: Dockerfile.multi rewrite, maintain package integrity (danny-avila#3772)
* chore: touch server * chore: dockerfile.multi first pass * refactor: remove prod-stage build, share dist files instead
1 parent d54458b commit 88d8706

File tree

4 files changed

+30
-33
lines changed

4 files changed

+30
-33
lines changed

Dockerfile.multi

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,40 @@
1+
# Dockerfile.multi
12
# v0.7.4
23

3-
# Build API, Client and Data Provider
4+
# Base for all builds
45
FROM node:20-alpine AS base
6+
WORKDIR /app
7+
COPY package*.json ./
8+
COPY packages/data-provider/package*.json ./packages/data-provider/
9+
COPY client/package*.json ./client/
10+
COPY api/package*.json ./api/
11+
RUN npm ci
512

613
# Build data-provider
714
FROM base AS data-provider-build
815
WORKDIR /app/packages/data-provider
9-
COPY ./packages/data-provider ./
10-
RUN npm install; npm cache clean --force
16+
COPY packages/data-provider ./
1117
RUN npm run build
1218
RUN npm prune --production
1319

14-
# React client build
20+
# Client build
1521
FROM base AS client-build
1622
WORKDIR /app/client
17-
COPY ./client/package*.json ./
18-
# Copy data-provider to client's node_modules
19-
COPY --from=data-provider-build /app/packages/data-provider/ /app/client/node_modules/librechat-data-provider/
20-
RUN npm install; npm cache clean --force
21-
COPY ./client/ ./
23+
COPY client ./
24+
COPY --from=data-provider-build /app/packages/data-provider/dist /app/packages/data-provider/dist
2225
ENV NODE_OPTIONS="--max-old-space-size=2048"
2326
RUN npm run build
27+
RUN npm prune --production
2428

25-
# Node API setup
29+
# API setup (including client dist)
2630
FROM base AS api-build
31+
WORKDIR /app
32+
COPY api ./api
33+
COPY config ./config
34+
COPY --from=data-provider-build /app/packages/data-provider/dist ./packages/data-provider/dist
35+
COPY --from=client-build /app/client/dist ./client/dist
2736
WORKDIR /app/api
28-
COPY api/package*.json ./
29-
COPY api/ ./
30-
# Copy helper scripts
31-
COPY config/ ./
32-
# Copy data-provider to API's node_modules
33-
COPY --from=data-provider-build /app/packages/data-provider/ /app/api/node_modules/librechat-data-provider/
34-
RUN npm install --include prod; npm cache clean --force
35-
COPY --from=client-build /app/client/dist /app/client/dist
37+
RUN npm prune --production
3638
EXPOSE 3080
3739
ENV HOST=0.0.0.0
3840
CMD ["node", "server/index.js"]
39-
40-
# Nginx setup
41-
FROM nginx:1.27.0-alpine AS prod-stage
42-
COPY ./client/nginx.conf /etc/nginx/conf.d/default.conf
43-
CMD ["nginx", "-g", "daemon off;"]

api/server/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const startServer = async () => {
3939

4040
app.get('/health', (_req, res) => res.status(200).send('OK'));
4141

42-
// Middleware
42+
/* Middleware */
4343
app.use(noIndex);
4444
app.use(errorController);
4545
app.use(express.json({ limit: '3mb' }));
@@ -48,7 +48,7 @@ const startServer = async () => {
4848
app.use(staticCache(app.locals.paths.dist));
4949
app.use(staticCache(app.locals.paths.fonts));
5050
app.use(staticCache(app.locals.paths.assets));
51-
app.set('trust proxy', 1); // trust first proxy
51+
app.set('trust proxy', 1); /* trust first proxy */
5252
app.use(cors());
5353

5454
if (DISABLE_COMPRESSION !== 'true') {
@@ -61,12 +61,12 @@ const startServer = async () => {
6161
);
6262
}
6363

64-
// OAUTH
64+
/* OAUTH */
6565
app.use(passport.initialize());
6666
passport.use(await jwtLogin());
6767
passport.use(passportLogin());
6868

69-
// LDAP Auth
69+
/* LDAP Auth */
7070
if (process.env.LDAP_URL && process.env.LDAP_USER_SEARCH_BASE) {
7171
passport.use(ldapLogin);
7272
}
@@ -76,7 +76,7 @@ const startServer = async () => {
7676
}
7777

7878
app.use('/oauth', routes.oauth);
79-
// API Endpoints
79+
/* API Endpoints */
8080
app.use('/api/auth', routes.auth);
8181
app.use('/api/keys', routes.keys);
8282
app.use('/api/user', routes.user);

deploy-compose.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ services:
3030
target: /app/librechat.yaml
3131
- ./images:/app/client/public/images
3232
- ./logs:/app/api/logs
33+
- client-dist:/app/client/dist # Share client dist files
34+
3335
client:
34-
build:
35-
context: .
36-
dockerfile: Dockerfile.multi
37-
target: prod-stage
36+
image: nginx:1.27.0-alpine
3837
container_name: LibreChat-NGINX
3938
ports:
4039
- 80:80
@@ -44,6 +43,7 @@ services:
4443
restart: always
4544
volumes:
4645
- ./client/nginx.conf:/etc/nginx/conf.d/default.conf
46+
- client-dist:/usr/share/nginx/html # Use shared client dist files
4747
mongodb:
4848
container_name: chat-mongodb
4949
# ports: # Uncomment this to access mongodb from outside docker, not safe in deployment
@@ -88,3 +88,4 @@ services:
8888

8989
volumes:
9090
pgdata2:
91+
client-dist: # Define a named volume for client dist files

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"test:api": "cd api && npm run test",
4949
"e2e:update": "playwright test --config=e2e/playwright.config.js --update-snapshots",
5050
"e2e:report": "npx playwright show-report e2e/playwright-report",
51-
"prepare": "node config/prepare.js",
5251
"lint:fix": "eslint --fix \"{,!(node_modules|venv)/**/}*.{js,jsx,ts,tsx}\"",
5352
"lint": "eslint \"{,!(node_modules|venv)/**/}*.{js,jsx,ts,tsx}\"",
5453
"format": "prettier-eslint --write \"{,!(node_modules|venv)/**/}*.{js,jsx,ts,tsx}\"",

0 commit comments

Comments
 (0)