【问题标题】:Trying to install logging on google cloud run but it's failing尝试在谷歌云运行上安装日志记录但它失败了
【发布时间】:2020-06-18 19:24:09
【问题描述】:

我正在尝试按照这些说明正确地从 java 登录到 logback 到 cloudrun...

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

如果我使用 jdk8,我会遇到 alpn 缺少码头问题,所以我转移到 Docker 映像 openjdk:10-jre-slim

我的 DockerFile 很简单

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 切换了图像,效果很好!!!

当我部署到谷歌云时,我收到了这个错误...

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)

【问题讨论】:

    标签: docker google-cloud-platform dockerfile logback google-cloud-run


    【解决方案1】:

    Java 10 版本 EOL,官方镜像已下架。更多详情here

    首选 Java 11 版本。

    反正在你使用版本的时候,有些是优化的,默认不安装bash(为了减小它们的大小),你必须自己安装。

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

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

    【讨论】:

      【解决方案2】:

      由于您当前的问题是如何模拟项目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
      

      【讨论】:

      • 我很困惑 gcloud 命令在本地运行?当我说在本地运行时,我的意思是“docker run gcr.io/orderly-gcp/customerportal2”,所以我当时没有使用 glcoud。
      • 从技术上讲,我指的是在 docker 容器中执行这些命令。因此,在 Dockerfile 中添加到 CMD 行以执行它们,以便您获得密钥的服务帐户的身份将成为使用的身份。 @DeanHiller
      • 哦,有趣。进一步考虑,我们现在只是将 logback 文件换成本地 Docker 开发作为一种更简单的解决方案,然后将日志记录写入应该用于本地开发的容器中。
      【解决方案3】:

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

      HTH

      【讨论】:

        猜你喜欢
        • 2021-04-04
        • 2021-02-12
        • 2014-09-21
        • 2012-07-17
        • 2017-03-14
        • 2019-03-12
        • 1970-01-01
        • 2016-06-18
        • 2016-05-21
        相关资源
        最近更新 更多