尝试在 google 云 运行 上安装日志记录,但失败了

Trying to install logging on google cloud run but it's failing

我正在尝试按照这些说明从 java 正确登录到登录云 运行...

https://cloud.google.com/logging/docs/setup/java

如果我使用 jdk8,我会遇到 alpn missing jetty 问题,所以我转移到 Docker 图像 openjdk:10-jre-slim

我的Docker文件很简单

FROM openjdk:10-jre-slim
RUN mkdir -p ./webpieces
COPY . ./webpieces/
COPY config/logback.cloudrun.xml ./webpieces/config/logback.xml
WORKDIR "/webpieces"
ENTRYPOINT ./bin/customerportal -http.port=:$PORT -hibernate.persistenceunit=cloud-production

唯一的区别是我将图像从 openjdk:8-jdk-alpine 切换到效果很好!!!

当我部署到 google 云时,出现此错误...

Deploying container to Cloud Run service [staging-customerportal] in project [orderly-gcp] region [us-west1]
⠏ Deploying... Cloud Run error: Invalid argument error. Invalid ENTRYPOINT. [name: "gcr.io/orderly-gcp/customerportal2@sha256:6c1c2e7531684d8f50a3120f1de60cade841ab1d9069b
704ee3fd8499c5b7779"
error: "Invalid command \"/bin/sh\": file not found"
]. 
X Deploying... Cloud Run error: Invalid argument error. Invalid ENTRYPOINT. [name: "gcr.io/orderly-gcp/customerportal2@sha256:6c1c2e7531684d8f50a3120f1de60cade841ab1d9069b
 704ee3fd8499c5b7779"
error: "Invalid command \"/bin/sh\": file not found"
].
 . Routing traffic...


Deployment failed
ERROR: (gcloud.run.deploy) Cloud Run error: Invalid argument error. Invalid ENTRYPOINT. [name: "gcr.io/orderly-gcp/customerportal2@sha256:6c1c2e7531684d8f50a3120f1de60cade841ab1d9069b704ee3fd8499c5b7779"
error: "Invalid command \"/bin/sh\": file not found"
 ].

但是,当我 运行 在本地进行测试时,我在需要项目 ID 时收到此错误,所以它似乎可以正常工作。附带问题:如何模拟此项目 ID,以便我仍然可以在本地 运行?

03:10:08,650 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [CLOUD]
03:10:09,868 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@14:13 - RuntimeException in Action for tag [appender] java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment.  Please set a project ID using the builder.
at java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment.  Please set a project ID using the builder.
at  at com.google.common.base.Preconditions.checkArgument(Preconditions.java:142)
at  at com.google.cloud.ServiceOptions.<init>(ServiceOptions.java:285)
at  at com.google.cloud.logging.LoggingOptions.<init>(LoggingOptions.java:98)
at  at com.google.cloud.logging.LoggingOptions$Builder.build(LoggingOptions.java:92)
at  at com.google.cloud.logging.LoggingOptions.getDefaultInstance(LoggingOptions.java:52)
at  at com.google.cloud.logging.logback.LoggingAppender.getLoggingOptions(LoggingAppender.java:246)
at  at com.google.cloud.logging.logback.LoggingAppender.getProjectId(LoggingAppender.java:209)
at  at com.google.cloud.logging.logback.LoggingAppender.start(LoggingAppender.java:194)
at  at ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:90)
at  at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:309)
at  at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:193)
at  at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:179)
at  at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62)
at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:165)
at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152)
at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)

由于您当前的问题是如何模拟项目ID进行本地测试:

您应该从 https://console.cloud.google.com/iam-admin/serviceaccounts/project?project=MY_PROJECT 下载服务帐户密钥文件,使其在 docker 容器内可访问并通过

激活它
gcloud auth activate-service-account --key-file my_service_account.json

gcloud config set project MY_PROJECT

Java10版本停产,官方图片已被移除。更多详情 here

更喜欢 Java 11 版本。

反正大家用的时候版本有些优化了,默认不安装bash(为了减小体积),要自己安装

对于本地运行,我不建议使用JSON密钥文件(一般情况下,不要使用JSON密钥文件,除了自动系统输出GCP)由于安全约束、密钥轮换、安全存储...

要设置项目,只需执行此命令gcloud config set project MY_PROJECT。您不需要凭据。

这个问题可能是因为alpine没有bash: "/bin/sh" 因此,解决方案可能是通过不使用 bash 或使用 exec 而不是 bash 来消除对 bash 本身的依赖。 在我的例子中,我通过使用更完整的基础图像而不是 alpine 解决了这个问题。

HTH