|
1 | | -# Start from the official LibreChat image (prebuilt) |
2 | | -FROM ghcr.io/danny-avila/librechat:v0.7.9 |
| 1 | +# syntax=docker.io/docker/dockerfile:1.7-labs |
| 2 | +# Enables --exclude in COPY for better caching of layers |
3 | 3 |
|
4 | | -# Switch to app directory and copy customizations |
5 | | -# -> overwrites existing files (JS, CSS, images, etc.) |
| 4 | +# Use the official LibreChat base image |
| 5 | +FROM ghcr.io/danny-avila/librechat:v0.7.9 |
6 | 6 | WORKDIR /app |
7 | | -COPY --chown=node:node . . |
8 | 7 |
|
9 | | -# Temporarily switch to root to install the entrypoint script |
10 | | -USER root |
11 | | -RUN \ |
12 | | - mv entrypoint.sh / && \ |
13 | | - chown root:root /entrypoint.sh && \ |
14 | | - chmod 755 /entrypoint.sh |
| 8 | +# Project currently does not define its own package.json |
| 9 | +# COPY --chown=node:node package*.json . |
| 10 | + |
| 11 | +# Reinstall dependencies to ensure a clean build |
| 12 | +RUN npm config set fetch-retry-maxtimeout 600000 \ |
| 13 | + && npm config set fetch-retries 5 \ |
| 14 | + && npm config set fetch-retry-mintimeout 15000 \ |
| 15 | + && npm install --no-audit |
| 16 | + |
| 17 | +# Copy custom files |
| 18 | +# Exclude entrypoint.sh and librechat.yaml for separate handling |
| 19 | +# Overwrites upstream assets (CSS, JS, images, etc.) |
| 20 | +COPY --chown=node:node \ |
| 21 | + --exclude=entrypoint.sh \ |
| 22 | + --exclude=librechat.yaml \ |
| 23 | + . . |
| 24 | + |
| 25 | +# Rebuild frontend to apply overrides (CSS/JS/images) |
| 26 | +# Prune devDependencies and clean npm cache to reduce image size |
| 27 | +RUN NODE_OPTIONS="--max-old-space-size=2048" npm run frontend \ |
| 28 | + && npm prune --production \ |
| 29 | + && npm cache clean --force |
| 30 | + |
| 31 | +# Copy entrypoint script with root permissions (separate layer for caching) |
| 32 | +COPY --chown=root:root --chmod=755 entrypoint.sh /entrypoint.sh |
15 | 33 |
|
16 | | -# Set the entrypoint for the container |
| 34 | +# Set entrypoint |
17 | 35 | ENTRYPOINT ["/entrypoint.sh"] |
18 | 36 |
|
19 | | -# Redefine the default command from the upstream Dockerfile |
| 37 | +# Set default command (ENTRYPOINT overrides base image CMD) |
20 | 38 | CMD ["npm", "run", "backend"] |
21 | 39 |
|
22 | | -# Revert back to the non-root node user for safety |
23 | | -USER node |
24 | | - |
25 | | -# Reinstall dependencies to ensure a clean rebuild |
26 | | -RUN \ |
27 | | - npm config set fetch-retry-maxtimeout 600000 && \ |
28 | | - npm config set fetch-retries 5 && \ |
29 | | - npm config set fetch-retry-mintimeout 15000 && \ |
30 | | - npm install --no-audit |
31 | | - |
32 | | -# Rebuild the frontend with custom overrides |
33 | | -# -> applies new JS, CSS, images, etc. |
34 | | -RUN \ |
35 | | - NODE_OPTIONS="--max-old-space-size=2048" npm run frontend && \ |
36 | | - npm prune --production && \ |
37 | | - npm cache clean --force |
| 40 | +# Copy configuration file last to avoid rebuilding earlier layers on minor changes |
| 41 | +COPY --chown=node:node librechat.yaml . |
0 commit comments