🐛 fix: sharp missing in docker production (#603)

This commit is contained in:
Mikey 2023-12-11 08:58:41 +08:00 committed by GitHub
parent da9c3a670b
commit d89b48d107
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View file

@ -1,5 +1,15 @@
FROM node:20-slim AS base
## Sharp dependencies, copy all the files for production
FROM base AS sharp
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
WORKDIR /app
RUN pnpm add sharp
## Install dependencies only when needed
FROM base AS builder
ENV PNPM_HOME="/pnpm"
@ -14,9 +24,6 @@ COPY package.json ./
# RUN npm config set registry https://registry.npmmirror.com/
RUN pnpm i
# https://nextjs.org/docs/messages/sharp-missing-in-production
ENV NEXT_SHARP_PATH /app/node_modules/sharp
COPY . .
RUN pnpm run build:docker # run build standalone for docker version
@ -39,6 +46,7 @@ RUN chown nextjs:nodejs .next
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=sharp --chown=nextjs:nodejs /app/node_modules/.pnpm ./node_modules/.pnpm
USER nextjs

View file

@ -42,6 +42,10 @@ $ docker run -d -p 3210:3210 \
> - The password set in the official Docker image is `lobe66` by default. Replace it with your own password to improve security.
> - For a complete list of environment variables supported by LobeChat, please refer to the [Environment Variables](https://github.com/lobehub/lobe-chat/wiki/Environment-Variable.zh-CN) section.
> \[!WARNING]
>
> If the architecture of your **deployed server differs from the container architecture**, you may need to perform cross-compilation for **Sharp**. For further details, please refer to the documentation on [Sharp Cross-platform](https://sharp.pixelplumbing.com/install#cross-platform).
#### Use a proxy address
If you need to use OpenAI service through a proxy, you can use the `OPENAI_PROXY_URL` environment variable to configure the proxy address:

View file

@ -42,6 +42,10 @@ $ docker run -d -p 3210:3210 \
> - 官方 Docker 镜像中设定的密码默认为 `lobe66`,请将其替换为自己的密码以提升安全性
> - LobeChat 支持的完整环境变量列表请参考 [环境变量](https://github.com/lobehub/lobe-chat/wiki/Environment-Variable.zh-CN) 部分
> \[!WARNING]
>
> 注意,当**部署架构与镜像的不一致时**,需要对 **Sharp** 进行交叉编译,详见 [Sharp 交叉编译](https://sharp.pixelplumbing.com/install#cross-platform)
#### 使用代理地址
如果你需要通过代理使用 OpenAI 服务,你可以使用 `OPENAI_PROXY_URL` 环境变量来配置代理地址: