简体   繁体   English

在 Google Cloud Run 上运行 go 程序而不监听传入的 HTTP 请求

[英]Running go program on Google Cloud Run without listening for incoming HTTP requests

I wrote a Go program which doesn't need to retrieve external http calls at all by default.我编写了一个 Go 程序,默认情况下根本不需要检索外部 http 调用。 I tried to deploy it on Google Cloud Run and received the following error:我尝试在 Google Cloud Run 上部署它并收到以下错误:

The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable.用户提供的容器无法启动和侦听 PORT=8080 环境变量提供的端口。 Logs for this revision might contain more information.此修订的日志可能包含更多信息。

I understand it happens because my code doesn't provide a port.我理解这是因为我的代码没有提供端口。 As this answer states:正如这个答案所说:

container must listen for incoming HTTP requests on the port that is defined by Cloud Run and provided in the $PORT environment variable容器必须在 Cloud Run 定义并在 $PORT 环境变量中提供的端口上侦听传入的 HTTP 请求

My question is what can I do if wouldn't like define any ports and just want to run the same code I run locally?我的问题是,如果不想定义任何端口并且只想运行我在本地运行的相同代码,我该怎么办? Is there an alternate solution to deploy my code without it, or I must add it anyway if I want run the code from Cloud Run?是否有替代解决方案可以在没有它的情况下部署我的代码,或者如果我想从 Cloud Run 运行代码,我必须添加它?

For containers that do not require an HTTP listener (HTTP server), use Cloud Run Jobs.对于不需要 HTTP 侦听器(HTTP 服务器)的容器,请使用 Cloud Run Jobs。

  • Cloud Run Jobs is in preview. Cloud Run Jobs 处于预览阶段。
  • Your Go program must exit with exit code 0 for success and non-zero for failure.您的 Go 程序必须退出,退出代码 0 表示成功,非零表示失败。
  • Your container should not listen on a port or start a web server.您的容器不应侦听端口或启动 web 服务器。
  • Environment variables are different from Cloud Run.环境变量与 Cloud Run 不同。
  • Container instances run until the container instance exits, until the task timeout is reached, or until the container crashes.容器实例一直运行,直到容器实例退出,直到任务超时,或者直到容器崩溃。 Task timeout default is 10 minutes, max is one hour.任务超时默认为 10 分钟,最长为 1 小时。

Cloud Run - Create jobs Cloud Run - 创建工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Cloud Run 中的 PHP 服务突然停止响应所有传入请求 - PHP service in Google Cloud Run suddenly stops responding to all incoming requests Google Cloud Dataflow 可以在 Go 中没有外部 IP 地址的情况下运行吗? - Can Google Cloud Dataflow be run without an external IP address in Go? Google Cloud Run with Angular 通用监听端口错误 - Google Cloud Run with Angular Universal listening port error Python 和 HTTP Google Cloud Functions 上的“导入请求” - Python and "import requests" on HTTP Google Cloud Functions Google Cloud Run 能否用于运行连续侦听的 Python 脚本? - Can Google Cloud Run be used to run a continuously-listening Python script? Nest.js API + Cloud 上的 Google Cloud Storage 运行每个 GET 请求以触发“HTTP/2 框架层中的流错误”(POST 请求工作正常) - Nest.js API + Google Cloud Storage on Cloud Run every GET request to trigger "Stream error in the HTTP/2 framing layer" (POST requests work fine) 从 Google API 网关到 Cloud Run 的请求延迟 - Delay on requests from Google API Gateway to Cloud Run 有没有办法验证从非谷歌应用程序到谷歌云功能的 http 请求? - Is there a way to authenticate http requests from a non-Google app to Google Cloud Functions? Cloud Run - 请求延迟 - Cloud Run - Requests latency go 1.18 在 google.cloud - go 1.18 in google.cloud
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM