参见上一篇
由于本地部署环境,与之前系统、网络、配置等环境不同,可能会遇见一些新的问题。
取2023年8月27日代码
git checkout -b a02796b063381c10ca9ca8189590b289a4d09129
由于本地情况的网络等环境不太一样,可能需要修改 openai等版本号
openai==0.27.0
当前Dockerfile内容如下。本地pip 用了-i 后,flask反而下载失败
RUN echo -e http://pypi.tuna.tsinghua.edu.cn/simple/ > /etc/apk/repositories
#RUN echo -e http://pypi.douban.com/simple/ > /etc/apk/repositories
#FROM node:20-alpine AS frontend
FROM node:16-alpine3.15 AS frontend
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY ./frontend/package*.json ./
USER node
RUN npm ci
COPY --chown=node:node ./frontend/ ./frontend
COPY --chown=node:node ./static/ ./static
WORKDIR /home/node/app/frontend
RUN npm run build
FROM python:3.11-alpine
RUN apk add --no-cache --virtual .build-deps \
build-base \
libffi-dev \
openssl-dev \
curl \
&& apk add --no-cache \
libpq
COPY requirements.txt /usr/src/app/
RUN python3 -m pip install --user --upgrade pip
#RUN pip3 install flask==1.1.1 -i http://mirrors.aliyun.com/pypi/simple/
#RUN pip3 install flask==1.1.1 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
RUN pip3 --default-timeout=100 install --no-cache-dir -r /usr/src/app/requirements.txt \
&& rm -rf /root/.cache
COPY . /usr/src/app/
COPY --from=frontend /home/node/app/static /usr/src/app/static/
WORKDIR /usr/src/app
EXPOSE 80
CMD ["gunicorn" , "-b", "0.0.0.0:80", "app:app"]
开始编译docker,发现会报错
=> ERROR [frontend 9/9] RUN npm run build 11.2s
------
> [frontend 9/9] RUN npm run build:
0.936
0.936 > frontend@0.0.0 build
0.936 > tsc && vite build
0.936
11.01 tsconfig.json(21,18): error TS6053: File '/home/node/app/frontend/tsconfig.node.json' not found.
------
Dockerfile:17
--------------------
15 | COPY --chown=node:node ./static/ ./static
16 | WORKDIR /home/node/app/frontend
17 | >>> RUN npm run build
18 |
19 | FROM python:3.11-alpine
--------------------
ERROR: failed to solve: process "/bin/sh -c npm run build" did not complete successfully: exit code: 2
这是因为 frontend/tsconfig.node.json 文件并不存在。可以去 tsconfig.json文件中注释掉或删掉引用了tsconfig.node.json文件的最后一行。(注意备份文件)
另外,还会报前端图标相关的问题
=> ERROR [frontend 9/9] RUN npm run build 14.9s
------
> [frontend 9/9] RUN npm run build:
0.902
0.902 > frontend@0.0.0 build
0.902 > tsc && vite build
0.902
13.56 vite v4.1.5 building for production...
13.63 transforming...
14.82 ✓ 29 modules transformed.
14.82 Could not resolve "../../assets/Azure.svg" from "src/pages/layout/Layout.tsx"
14.82 file: /home/node/app/frontend/src/pages/layout/Layout.tsx
14.83 error during build:
14.83 RollupError: Could not resolve "../../assets/Azure.svg" from "src/pages/layout/Layout.tsx"
14.83 at error (file:///home/node/app/node_modules/rollup/dist/es/shared/rollup.js:2091:30)
14.83 at ModuleLoader.handleInvalidResolvedId (file:///home/node/app/node_modules/rollup/dist/es/shared/rollup.js:23325:24)
14.83 at file:///home/node/app/node_modules/rollup/dist/es/shared/rollup.js:23287:26
------
Dockerfile:17
--------------------
15 | COPY --chown=node:node ./static/ ./static
16 | WORKDIR /home/node/app/frontend
17 | >>> RUN npm run build
18 |
19 | FROM python:3.11-alpine
--------------------
ERROR: failed to solve: process "/bin/sh -c npm run build" did not complete successfully: exit code: 1
在frontend/src/pages/layout/Layout.tsx文件注释或删除掉引用svg图标的语句,../../assets/Azure.svg;除此外,在frontend/src/pages/chat/Chat.tsx,src/components/QuestionInput/QuestionInput.tsx文件也需要注释或删除掉引用assets/.svg图标的语句,不知道为什么,这里不支持引用
注意:有时候网页打开后,可以看到需要微软Authorization 或者让等待10分钟,可以在 frontend/src/pages/chat/Chat.tsx 文件中看到这里。
const [showAuthMessage, setShowAuthMessage] = useState<boolean>(true);
然后在下面的<stack>相关代码中注释掉 showAuthMessage 这一部分。