[英]Cloud build error when deploying to cloud run
I have been running a cloud build service which deploys a nextjs application to a cloud run container for a year now.我一直在运行云构建服务,该服务将 nextjs 应用程序部署到云运行容器一年了。 This week, after making some commits, I was unable to successfully deploy the changes even though I have not changed anything on GCP.
本周,在进行了一些提交之后,即使我没有在 GCP 上进行任何更改,我也无法成功部署更改。 On cloud build, the error reads:
在云构建上,错误显示为:
"Deploy": ERROR: (gcloud.run.services.update) Cloud Run error: The user-provided container failed to start and listen on the port defined provided by the PORT=3000 environment variable. Logs for this revision might contain more information.
after it downloads this image下载此图像后
ERROR: build step 2 "gcr.io/google.com/cloudsdktool/cloud-sdk:slim" failed: step exited with non-zero status: 1
My steps on my cloudbuild.yaml file have been:我在 cloudbuild.yaml 文件上的步骤是:
download.env file下载.env文件
build the container image构建容器镜像
push the container image to gcr将容器镜像推送到 gcr
deploy container image to Cloud Run Anthos将容器映像部署到 Cloud Run Anthos
I have even increased my timeout to 900s because that is the first error that I received.我什至将超时时间增加到 900 秒,因为这是我收到的第一个错误。 These steps have successfully deployed the application in the past and I have only changed the timeout time in cloudbuild.yaml
这些步骤过去已经成功部署了应用程序,我只是在cloudbuild.yaml中更改了超时时间
My dockerfile only has the following:我的 dockerfile 只有以下内容:
FROM node:14-alpine
WORKDIR /app
COPY . .
RUN npm install
RUN npm rebuild node-sass
RUN npm run build
EXPOSE 3000
CMD ["npm","start"]
尝试在端口 8080 而不是 3000 上运行它
This is a very generic error that GCP throws.这是 GCP 抛出的一个非常普遍的错误。 I've ran into the same one just the other day and it had nothing to do with the port itself.
前几天我遇到了同样的问题,它与港口本身无关。
In my case, I happened to forget to create a directory before changing the permission in the Dockerfile.就我而言,我碰巧忘记在更改 Dockerfile 中的权限之前创建一个目录。
Try to check under the "Logs" tab.尝试在“日志”选项卡下进行检查。 There you can usually find better information about the cause.
在那里,您通常可以找到有关原因的更好信息。 GCP Logs
GCP 日志
The issue most likely is that you do not allow your Dockerfile to use $PORT environment variable anywhere - customize your CMD directive to include $PORT so that your container might accept it from Cloud Run environment and start the app on that port.问题很可能是您不允许您的 Dockerfile 在任何地方使用 $PORT 环境变量 - 自定义您的 CMD 指令以包含 $PORT 以便您的容器可以从 Cloud Run 环境接受它并在该端口上启动应用程序。 The idea is that Cloud Run passes this environment variable and your container must accept it - a container will not be able to start on Cloud Run otherwise (it says so in the docs).
这个想法是 Cloud Run 传递这个环境变量并且你的容器必须接受它 - 否则容器将无法在 Cloud Run 上启动(它在文档中这样说)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.