代码之家  ›  专栏  ›  技术社区  ›  Dean Hiller

试图在谷歌云上安装日志,但失败了

  •  0
  • Dean Hiller  · 技术社区  · 5 年前

    我正试图按照这些说明正确地从java到logback再到cloudrun进行日志记录。。。

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

    如果我使用jdk8,我会遇到alpn缺少jetty的问题,所以我转向了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)
    
    0 回复  |  直到 5 年前
        1
  •  2
  •   guillaume blaquiere    5 年前

    Java 10版本为EOL,官方镜像已被删除。更多详情 here

    更喜欢Java 11版本。

    不管怎样,当你使用版本时,有些是优化的,不会安装 bash 默认情况下(为了减小它们的大小),您必须自己安装。

    对于本地运行,由于安全约束、密钥轮换、安全存储等原因,我不建议使用JSON密钥文件(一般来说,除了GCP之外的自动化系统,不要使用JSON密钥),。。。

    要设置项目,只需执行以下命令 gcloud config set project MY_PROJECT 。你不需要凭证。

        2
  •  1
  •   Waelmas    5 年前

    由于您当前的问题是如何模拟项目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
    
        3
  •  0
  •   Felipe Valdes    5 年前

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

    HTH