Closed liangyimingcom closed 1 year ago
请提供一下部署命令,以及服务端运行时 log 截图。
环境变量更改后,一般需要重新部署,aws 是否有重新部署选项?
环境变量更改后,一般需要重新部署,aws 是否有重新部署选项?
是的,重新部署过。
多次部署试过以下方法,均无作用: 1)AWS Amplify第一次部署配置就输入环境变量,无效果; 2)AWS Amplify第一次部署没有输入环境变量,部署成功后输入环境变量,重新部署后无效果;
我把build的log日志贴在下面了,在里面找到了一些[WARNING],请查看,谢谢。
部署区域:Asia Pacific (Tokyo) ap-northeast-1
部署命令:amplify上选择《Host web app》后,From your existing code “github Repository” 部署:
服务端运行时 log 截图:
1)Provision
FROM amazonlinux:2
LABEL maintainer="Amazon AWS"
ENV VERSION_NODE_8=8.12.0 ENV VERSION_NODE_10=10.16.0 ENV VERSION_NODE_12=12 ENV VERSION_NODE_14=14 ENV VERSION_NODE_16=16 ENV VERSION_NODE_17=17 ENV VERSION_NODE_DEFAULT=$VERSION_NODE_14 ENV VERSION_RUBY_2_4=2.4.6 ENV VERSION_RUBY_2_6=2.6.3 ENV VERSION_BUNDLER=2.0.1 ENV VERSION_RUBY_DEFAULT=$VERSION_RUBY_2_4 ENV VERSION_HUGO=0.75.1 ENV VERSION_YARN=1.22.0 ENV VERSION_AMPLIFY=6.3.1
ENV LANGUAGE en_US:en ENV LANG=en_US.UTF-8 ENV LC_ALL en_US.UTF-8
RUN touch ~/.bashrc RUN yum -y update && \ yum -y install \ alsa-lib-devel \ autoconf \ automake \ bzip2 \ bison \ bzr \ cmake \ expect \ fontconfig \ git \ gcc-c++ \ GConf2-devel \ gtk2-devel \ gtk3-devel \ libnotify-devel \ libpng \ libpng-devel \ libffi-devel \ libtool \ libX11 \ libXext \ libxml2 \ libxml2-devel \ libXScrnSaver \ libxslt \ libxslt-devel \ libyaml \ libyaml-devel \ make \ nss-devel \ openssl-devel \ openssh-clients \ patch \ procps \ python3 \ python3-devel \ readline-devel \ sqlite-devel \ tar \ tree \ unzip \ wget \ which \ xorg-x11-server-Xvfb \ zip \ zlib \ zlib-devel \ yum clean all && \ rm -rf /var/cache/yum
RUN wget https://github.com/gohugoio/hugo/releases/download/v${VERSION_HUGO}/hugo_${VERSION_HUGO}_Linux-64bit.tar.gz && \ tar -xf hugo_${VERSION_HUGO}Linux-64bit.tar.gz hugo -C / && \ mv /hugo /usr/bin/hugo && \ rm -rf hugo${VERSION_HUGO}_Linux-64bit.tar.gz
RUN rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm RUN yum -y install dotnet-host-3.1.4 RUN yum -y install dotnet-sdk-3.1
RUN dotnet tool install -g Amazon.Lambda.Tools RUN dotnet tool install -g Amazon.Lambda.TestTool-3.1
RUN wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz RUN tar xvf Python-3.8.0.tgz WORKDIR Python-3.8.0 RUN ./configure --enable-optimizations --prefix=/usr/local RUN make altinstall
RUN wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz RUN tar xvf Python-3.9.0.tgz WORKDIR Python-3.9.0 RUN ./configure --enable-optimizations --prefix=/usr/local RUN make altinstall
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash RUN /bin/bash -c ". ~/.nvm/nvm.sh && nvm install $VERSION_NODE_8 && nvm use $VERSION_NODE_8 && \ nvm install $VERSION_NODE_10 && nvm use $VERSION_NODE_10 && \ npm install -g yarn@${VERSION_YARN} sm grunt-cli bower vuepress gatsby-cli && \ nvm install $VERSION_NODE_12 && nvm use $VERSION_NODE_12 && \ npm install -g yarn@${VERSION_YARN} sm grunt-cli bower vuepress gatsby-cli && \ nvm install $VERSION_NODE_14 && nvm use $VERSION_NODE_14 && \ npm install -g yarn@${VERSION_YARN} sm grunt-cli bower vuepress gatsby-cli && \ nvm install $VERSION_NODE_16 && nvm use $VERSION_NODE_16 && chown -R root:root /root/.nvm && \ npm install -g yarn@${VERSION_YARN} sm grunt-cli bower vuepress gatsby-cli && \ nvm install $VERSION_NODE_17 && nvm use $VERSION_NODE_17 && chown -R root:root /root/.nvm && \ npm install -g yarn@${VERSION_YARN} sm grunt-cli bower vuepress gatsby-cli && \ nvm alias default ${VERSION_NODE_DEFAULT} && nvm cache clear"
nvm install
in the futureRUN echo "yarn@${VERSION_YARN}" > /root/.nvm/default-packages
RUN curl -sSL https://rvm.io/mpapis.asc | gpg --import - && curl -sSL https://rvm.io/pkuczynski.asc | gpg --import - && curl -sL https://get.rvm.io | bash -s -- --with-gems="bundler"
ENV PATH /usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin RUN /bin/bash --login -c "\ rvm install $VERSION_RUBY_2_4 && rvm use $VERSION_RUBY_2_4 && gem install bundler -v $VERSION_BUNDLER && gem install jekyll && \ rvm install $VERSION_RUBY_2_6 && rvm use $VERSION_RUBY_2_6 && gem install bundler -v $VERSION_BUNDLER && gem install -N jekyll && \ rvm cleanup all"
RUN /bin/bash -c "pip3.8 install awscli && rm -rf /var/cache/apk/" RUN /bin/bash -c "pip3.9 install awscli && rm -rf /var/cache/apk/"
RUN /bin/bash -c "pip3.8 install aws-sam-cli" RUN /bin/bash -c "pip3.9 install aws-sam-cli"
RUN /bin/bash -c ". ~/.nvm/nvm.sh && \ nvm use ${VERSION_NODE_DEFAULT} && \ npm install -g --unsafe-perm=true --allow-root cypress"
RUN /bin/bash -c ". ~/.nvm/nvm.sh && nvm use ${VERSION_NODE_8} && \ npm config set user 0 && npm config set unsafe-perm true && \ npm install -g @aws-amplify/cli@${VERSION_AMPLIFY}" RUN /bin/bash -c ". ~/.nvm/nvm.sh && nvm use ${VERSION_NODE_10} && \ npm config set user 0 && npm config set unsafe-perm true && \ npm install -g @aws-amplify/cli@${VERSION_AMPLIFY}" RUN /bin/bash -c ". ~/.nvm/nvm.sh && nvm use ${VERSION_NODE_12} && \ npm config set user 0 && npm config set unsafe-perm true && \ npm install -g @aws-amplify/cli@${VERSION_AMPLIFY}" RUN /bin/bash -c ". ~/.nvm/nvm.sh && nvm use ${VERSION_NODE_14} && \ npm config set user 0 && npm config set unsafe-perm true && \ npm install -g @aws-amplify/cli@${VERSION_AMPLIFY}" RUN /bin/bash -c ". ~/.nvm/nvm.sh && nvm use ${VERSION_NODE_16} && \ npm config set user 0 && npm config set unsafe-perm true && \ npm install -g @aws-amplify/cli@${VERSION_AMPLIFY}" RUN /bin/bash -c ". ~/.nvm/nvm.sh && nvm use ${VERSION_NODE_17} && \ npm config set user 0 && npm config set unsafe-perm true && \ npm install -g @aws-amplify/cli@${VERSION_AMPLIFY}"
RUN echo export PATH="/usr/local/rvm/gems/ruby-${VERSION_RUBY_DEFAULT}/bin:\ /usr/local/rvm/gems/ruby-${VERSION_RUBY_DEFAULT}@global/bin:\ /usr/local/rvm/rubies/ruby-${VERSION_RUBY_DEFAULT}/bin:\ /usr/local/rvm/bin:\ /root/.nvm/versions/node/${VERSION_NODE_DEFAULT}/bin:\ $(python3 -m site --user-base)/bin:\ $(python3.8 -m site --user-base)/bin:\ $(python3.9 -m site --user-base)/bin:\ $PATH" >> ~/.bashrc && \ echo export GEM_PATH="/usr/local/rvm/gems/ruby-${VERSION_RUBY_DEFAULT}" >> ~/.bashrc && \ echo "nvm use ${VERSION_NODE_DEFAULT} 1> /dev/null" >> ~/.bashrc && \ echo "export PATH=$PATH:/root/.dotnet/tools" >> ~/.bashrc
ENTRYPOINT [ "bash", "-c" ]
2)Build LOG file:
2023-04-14T09:29:15.488Z [INFO]: # Cloning repository: git@github.com:xxxx/ChatGPT-Next-Web.git 2023-04-14T09:29:18.217Z [INFO]: 2023-04-14T09:29:18.219Z [INFO]: Cloning into 'ChatGPT-Next-Web'... 2023-04-14T09:29:18.220Z [INFO]: # Checking for Git submodules at: /codebuild/output/src906065404/src/ChatGPT-Next-Web/.gitmodules 2023-04-14T09:29:18.227Z [INFO]: # Retrieving environment cache... 2023-04-14T09:29:18.278Z [WARNING]: ! Unable to write cache: {"code":"ERR_BAD_REQUEST","message":"Request failed with status code 404"})} 2023-04-14T09:29:18.279Z [INFO]: ---- Setting Up SSM Secrets ---- 2023-04-14T09:29:18.279Z [INFO]: SSM params {"Path":"/amplify/d3erqv6nvuj65d/main/","WithDecryption":true} 2023-04-14T09:29:18.326Z [WARNING]: !Failed to set up process.env.secrets 2023-04-14T09:29:18.327Z [INFO]: No live updates for this build run 2023-04-14T09:29:18.328Z [INFO]: Setting NEXT_PRIVATE_STANDALONE=true to produce .next/standalone directory 2023-04-14T09:29:18.329Z [INFO]: # Retrieving cache... 2023-04-14T09:29:27.521Z [INFO]: # Extracting cache... 2023-04-14T09:29:33.012Z [INFO]: # Extraction completed 2023-04-14T09:29:33.168Z [INFO]: # Retrieved cache 2023-04-14T09:30:20.514Z [INFO]: ## Starting Backend Build
## No backend environment association found, continuing...
## Completed Backend Build
2023-04-14T09:30:20.517Z [INFO]: {"backendDuration": 0}
# Starting phase: preBuild
# Executing command: yarn install
2023-04-14T09:30:21.464Z [INFO]: yarn install v1.22.0 2023-04-14T09:30:21.480Z [WARNING]: warning package.json: License should be a valid SPDX license expression 2023-04-14T09:30:21.527Z [WARNING]: warning chatgpt-next-web@1.9.3: License should be a valid SPDX license expression 2023-04-14T09:30:21.529Z [INFO]: [1/4] Resolving packages... 2023-04-14T09:30:21.787Z [INFO]: success Already up-to-date. 2023-04-14T09:30:21.797Z [INFO]: $ husky install 2023-04-14T09:30:21.849Z [INFO]: husky - Git hooks installed 2023-04-14T09:30:21.853Z [INFO]: Done in 0.39s. 2023-04-14T09:30:21.862Z [INFO]: # Completed phase: preBuild
2023-04-14T09:30:21.862Z [INFO]: # Executing command: yarn run build
2023-04-14T09:30:21.987Z [INFO]: yarn run v1.22.0
2023-04-14T09:30:22.003Z [WARNING]: warning package.json: License should be a valid SPDX license expression
2023-04-14T09:30:22.015Z [INFO]: $ yarn fetch && next build
2023-04-14T09:30:22.164Z [WARNING]: warning package.json: License should be a valid SPDX license expression
2023-04-14T09:30:22.179Z [INFO]: $ node ./scripts/fetch-prompts.mjs
2023-04-14T09:30:22.323Z [INFO]: [Fetch] fetching cn prompts...
2023-04-14T09:30:22.341Z [INFO]: [Fetch] fetching en prompts...
2023-04-14T09:30:22.988Z [INFO]: [Fetch] saved to ./public/prompts.json
2023-04-14T09:30:23.421Z [WARNING]: warn - You have enabled experimental feature (appDir) in next.config.js.
2023-04-14T09:30:23.421Z [WARNING]: warn - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
2023-04-14T09:30:23.421Z [WARNING]:
2023-04-14T09:30:23.421Z [INFO]: info - Thank you for testing appDir
please leave your feedback at https://nextjs.link/app-feedback
2023-04-14T09:30:23.423Z [INFO]: warn - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
2023-04-14T09:30:23.435Z [INFO]: Attention: Next.js now collects completely anonymous telemetry regarding usage.
2023-04-14T09:30:23.435Z [INFO]: This information is used to shape Next.js' roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://nextjs.org/telemetry
2023-04-14T09:30:23.532Z [INFO]: info - Creating an optimized production build...
2023-04-14T09:30:44.605Z [INFO]: info - Compiled successfully
2023-04-14T09:30:44.607Z [INFO]: info - Linting and checking validity of types...
2023-04-14T09:30:46.040Z [WARNING]: Pages directory cannot be found at /codebuild/output/src906065404/src/ChatGPT-Next-Web/pages or /codebuild/output/src906065404/src/ChatGPT-Next-Web/src/pages. If using a custom path, please configure with the no-html-link-for-pages
rule in your eslint config file.
2023-04-14T09:30:49.150Z [INFO]: info - Collecting page data...
2023-04-14T09:30:55.323Z [INFO]: info - Generating static pages (0/5)
2023-04-14T09:30:55.390Z [INFO]: info - Generating static pages (1/5)
2023-04-14T09:30:55.396Z [INFO]: info - Generating static pages (2/5)
2023-04-14T09:30:55.438Z [INFO]: info - Generating static pages (3/5)
2023-04-14T09:30:56.113Z [INFO]: info - Generating static pages (5/5)
2023-04-14T09:30:56.122Z [INFO]: info - Finalizing page optimization...
2023-04-14T09:30:56.124Z [INFO]:
2023-04-14T09:30:56.161Z [INFO]: Route (app) Size First Load JS
┌ ○ / 39.9 kB 109 kB
├ ℇ /api/chat-stream 0 B 0 B
├ λ /api/config 0 B 0 B
└ λ /api/openai 0 B 0 B
2023-04-14T09:30:56.914Z [INFO]: ## Build completed successfully 2023-04-14T09:30:56.915Z [INFO]: # Starting caching... 2023-04-14T09:30:56.925Z [INFO]: # Creating cache artifact... 2023-04-14T09:31:02.850Z [INFO]: # Created cache artifact 2023-04-14T09:31:03.025Z [INFO]: # Uploading cache artifact... 2023-04-14T09:31:06.309Z [INFO]: # Uploaded cache artifact 2023-04-14T09:31:06.413Z [INFO]: # Caching completed 2023-04-14T09:31:06.414Z [INFO]: Setting NEXT_PRIVATE_STANDALONE=true to produce .next/standalone directory 2023-04-14T09:31:06.416Z [INFO]: # No custom headers found. 2023-04-14T09:31:07.492Z [INFO]: # Starting environment caching... 2023-04-14T09:31:07.492Z [INFO]: # Environment caching completed Terminating logging...
Build 阶段没有什么问题,问题应该是出在了 deploy 阶段,所有的环境变量配置都必须通过 yarn start 入口传入,你可以检查一下 deploy 命令,提供一下截图。
顺便,看起来 aws 应该支持直接从 docker 部署?你可以尝试一下用本项目的 docker 镜像部署,在启动 docker 的时候将配置项传入即可。
Build 阶段没有什么问题,问题应该是出在了 deploy 阶段,所有的环境变量配置都必须通过 yarn start 入口传入,你可以检查一下 deploy 命令,提供一下截图。
顺便,看起来 aws 应该支持直接从 docker 部署?你可以尝试一下用本项目的 docker 镜像部署,在启动 docker 的时候将配置项传入即可。
感谢支持🙏
试过用本项目的 docker 镜像部署,部署成功,一切正常。 本项目的代完全没问题。
所以,amplify的编译、部署和运行,看来是需要一些特别的amplify配置才能正常工作。我再去troubleshooting一下👌
写的非常详细,我也遇到了相同问题正在寻求解决,看来只能用Docker了。 再次感谢。
反馈须知
描述问题 [Bug] AWS Amplify环境下部署成功正常工作,但是缺乏"访问密码"选项,已经配置了环境变量“CODE/OPENAI_API_KEY“但是无法生效;
如何复现 相同的fork github项目,配置了环境变量“CODE/OPENAI_API_KEY“后在VERCEL部署成功已经有"访问密码"选项。相同的环境变量在AWS Amplify环境下部署成功正常工作,但是但是缺乏"访问密码"选项。如截图:
截图 请在此提供控制台截图、屏幕截图或者服务端的 log 截图。。
一些必要的信息
补充:
1)除了缺少"访问密码"选项之前,确认AWS Amplify环境下部署可以正常工作(缺省版本的nodejs) 2)自己输入api key 能够很好的工作 3)去看了和环境变量相关的代码 https://github.com/Yidadaa/ChatGPT-Next-Web/blob/0f739f442e1b13a5ed9a4dddac7f88b9ede85dd8/app/config/server.ts ,反复尝试Amplify的部署,没有找到为啥无法获取“Environment variables”原因。 4)初步判断“Environment variables”在Amplify没有生效,所以 OPENAI_API_KEY 其实也存不下。
AWS Amplify 是AWS收费的解决方案,依托于AWS全球region资源和cloudfront cdn加速,使用体验非常好,建议能够适配成功。