mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00
🐋 ci: Dockerfile.multi rewrite, maintain package integrity (#3772)
* chore: touch server * chore: dockerfile.multi first pass * refactor: remove prod-stage build, share dist files instead
This commit is contained in:
parent
d54458b3a6
commit
88d8706757
4 changed files with 30 additions and 33 deletions
|
@ -1,43 +1,40 @@
|
||||||
|
# Dockerfile.multi
|
||||||
# v0.7.4
|
# v0.7.4
|
||||||
|
|
||||||
# Build API, Client and Data Provider
|
# Base for all builds
|
||||||
FROM node:20-alpine AS base
|
FROM node:20-alpine AS base
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package*.json ./
|
||||||
|
COPY packages/data-provider/package*.json ./packages/data-provider/
|
||||||
|
COPY client/package*.json ./client/
|
||||||
|
COPY api/package*.json ./api/
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
# Build data-provider
|
# Build data-provider
|
||||||
FROM base AS data-provider-build
|
FROM base AS data-provider-build
|
||||||
WORKDIR /app/packages/data-provider
|
WORKDIR /app/packages/data-provider
|
||||||
COPY ./packages/data-provider ./
|
COPY packages/data-provider ./
|
||||||
RUN npm install; npm cache clean --force
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
RUN npm prune --production
|
RUN npm prune --production
|
||||||
|
|
||||||
# React client build
|
# Client build
|
||||||
FROM base AS client-build
|
FROM base AS client-build
|
||||||
WORKDIR /app/client
|
WORKDIR /app/client
|
||||||
COPY ./client/package*.json ./
|
COPY client ./
|
||||||
# Copy data-provider to client's node_modules
|
COPY --from=data-provider-build /app/packages/data-provider/dist /app/packages/data-provider/dist
|
||||||
COPY --from=data-provider-build /app/packages/data-provider/ /app/client/node_modules/librechat-data-provider/
|
|
||||||
RUN npm install; npm cache clean --force
|
|
||||||
COPY ./client/ ./
|
|
||||||
ENV NODE_OPTIONS="--max-old-space-size=2048"
|
ENV NODE_OPTIONS="--max-old-space-size=2048"
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
RUN npm prune --production
|
||||||
|
|
||||||
# Node API setup
|
# API setup (including client dist)
|
||||||
FROM base AS api-build
|
FROM base AS api-build
|
||||||
|
WORKDIR /app
|
||||||
|
COPY api ./api
|
||||||
|
COPY config ./config
|
||||||
|
COPY --from=data-provider-build /app/packages/data-provider/dist ./packages/data-provider/dist
|
||||||
|
COPY --from=client-build /app/client/dist ./client/dist
|
||||||
WORKDIR /app/api
|
WORKDIR /app/api
|
||||||
COPY api/package*.json ./
|
RUN npm prune --production
|
||||||
COPY api/ ./
|
|
||||||
# Copy helper scripts
|
|
||||||
COPY config/ ./
|
|
||||||
# Copy data-provider to API's node_modules
|
|
||||||
COPY --from=data-provider-build /app/packages/data-provider/ /app/api/node_modules/librechat-data-provider/
|
|
||||||
RUN npm install --include prod; npm cache clean --force
|
|
||||||
COPY --from=client-build /app/client/dist /app/client/dist
|
|
||||||
EXPOSE 3080
|
EXPOSE 3080
|
||||||
ENV HOST=0.0.0.0
|
ENV HOST=0.0.0.0
|
||||||
CMD ["node", "server/index.js"]
|
CMD ["node", "server/index.js"]
|
||||||
|
|
||||||
# Nginx setup
|
|
||||||
FROM nginx:1.27.0-alpine AS prod-stage
|
|
||||||
COPY ./client/nginx.conf /etc/nginx/conf.d/default.conf
|
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ const startServer = async () => {
|
||||||
|
|
||||||
app.get('/health', (_req, res) => res.status(200).send('OK'));
|
app.get('/health', (_req, res) => res.status(200).send('OK'));
|
||||||
|
|
||||||
// Middleware
|
/* Middleware */
|
||||||
app.use(noIndex);
|
app.use(noIndex);
|
||||||
app.use(errorController);
|
app.use(errorController);
|
||||||
app.use(express.json({ limit: '3mb' }));
|
app.use(express.json({ limit: '3mb' }));
|
||||||
|
@ -48,7 +48,7 @@ const startServer = async () => {
|
||||||
app.use(staticCache(app.locals.paths.dist));
|
app.use(staticCache(app.locals.paths.dist));
|
||||||
app.use(staticCache(app.locals.paths.fonts));
|
app.use(staticCache(app.locals.paths.fonts));
|
||||||
app.use(staticCache(app.locals.paths.assets));
|
app.use(staticCache(app.locals.paths.assets));
|
||||||
app.set('trust proxy', 1); // trust first proxy
|
app.set('trust proxy', 1); /* trust first proxy */
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
||||||
if (DISABLE_COMPRESSION !== 'true') {
|
if (DISABLE_COMPRESSION !== 'true') {
|
||||||
|
@ -61,12 +61,12 @@ const startServer = async () => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// OAUTH
|
/* OAUTH */
|
||||||
app.use(passport.initialize());
|
app.use(passport.initialize());
|
||||||
passport.use(await jwtLogin());
|
passport.use(await jwtLogin());
|
||||||
passport.use(passportLogin());
|
passport.use(passportLogin());
|
||||||
|
|
||||||
// LDAP Auth
|
/* LDAP Auth */
|
||||||
if (process.env.LDAP_URL && process.env.LDAP_USER_SEARCH_BASE) {
|
if (process.env.LDAP_URL && process.env.LDAP_USER_SEARCH_BASE) {
|
||||||
passport.use(ldapLogin);
|
passport.use(ldapLogin);
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ const startServer = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
app.use('/oauth', routes.oauth);
|
app.use('/oauth', routes.oauth);
|
||||||
// API Endpoints
|
/* API Endpoints */
|
||||||
app.use('/api/auth', routes.auth);
|
app.use('/api/auth', routes.auth);
|
||||||
app.use('/api/keys', routes.keys);
|
app.use('/api/keys', routes.keys);
|
||||||
app.use('/api/user', routes.user);
|
app.use('/api/user', routes.user);
|
||||||
|
|
|
@ -30,11 +30,10 @@ services:
|
||||||
target: /app/librechat.yaml
|
target: /app/librechat.yaml
|
||||||
- ./images:/app/client/public/images
|
- ./images:/app/client/public/images
|
||||||
- ./logs:/app/api/logs
|
- ./logs:/app/api/logs
|
||||||
|
- client-dist:/app/client/dist # Share client dist files
|
||||||
|
|
||||||
client:
|
client:
|
||||||
build:
|
image: nginx:1.27.0-alpine
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile.multi
|
|
||||||
target: prod-stage
|
|
||||||
container_name: LibreChat-NGINX
|
container_name: LibreChat-NGINX
|
||||||
ports:
|
ports:
|
||||||
- 80:80
|
- 80:80
|
||||||
|
@ -44,6 +43,7 @@ services:
|
||||||
restart: always
|
restart: always
|
||||||
volumes:
|
volumes:
|
||||||
- ./client/nginx.conf:/etc/nginx/conf.d/default.conf
|
- ./client/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||||
|
- client-dist:/usr/share/nginx/html # Use shared client dist files
|
||||||
mongodb:
|
mongodb:
|
||||||
container_name: chat-mongodb
|
container_name: chat-mongodb
|
||||||
# ports: # Uncomment this to access mongodb from outside docker, not safe in deployment
|
# ports: # Uncomment this to access mongodb from outside docker, not safe in deployment
|
||||||
|
@ -88,3 +88,4 @@ services:
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
pgdata2:
|
pgdata2:
|
||||||
|
client-dist: # Define a named volume for client dist files
|
||||||
|
|
|
@ -48,7 +48,6 @@
|
||||||
"test:api": "cd api && npm run test",
|
"test:api": "cd api && npm run test",
|
||||||
"e2e:update": "playwright test --config=e2e/playwright.config.js --update-snapshots",
|
"e2e:update": "playwright test --config=e2e/playwright.config.js --update-snapshots",
|
||||||
"e2e:report": "npx playwright show-report e2e/playwright-report",
|
"e2e:report": "npx playwright show-report e2e/playwright-report",
|
||||||
"prepare": "node config/prepare.js",
|
|
||||||
"lint:fix": "eslint --fix \"{,!(node_modules|venv)/**/}*.{js,jsx,ts,tsx}\"",
|
"lint:fix": "eslint --fix \"{,!(node_modules|venv)/**/}*.{js,jsx,ts,tsx}\"",
|
||||||
"lint": "eslint \"{,!(node_modules|venv)/**/}*.{js,jsx,ts,tsx}\"",
|
"lint": "eslint \"{,!(node_modules|venv)/**/}*.{js,jsx,ts,tsx}\"",
|
||||||
"format": "prettier-eslint --write \"{,!(node_modules|venv)/**/}*.{js,jsx,ts,tsx}\"",
|
"format": "prettier-eslint --write \"{,!(node_modules|venv)/**/}*.{js,jsx,ts,tsx}\"",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue