Skip to content

Commit

Permalink
🐛 fix: sharp missing in docker production (lobehub#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirname authored Dec 11, 2023
1 parent da9c3a6 commit d89b48d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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

Expand All @@ -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

Expand Down
4 changes: 4 additions & 0 deletions docs/Docker-Deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions docs/Docker-Deployment.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` 环境变量来配置代理地址:
Expand Down

0 comments on commit d89b48d

Please sign in to comment.