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

Viewed 957

I am trying to follow these instructions to log correctly from java to logback to cloudrun...

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

If I used jdk8, I get alpn missing jetty issues so I moved to a Docker image openjdk:10-jre-slim

and my DockerFile is simple

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

AND the only difference is I switched the image from openjdk:8-jdk-alpine which worked fine!!!

When I deploy to google cloud I get this error...

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"
 ].

However, when I run locally to test, I get this error on project ID being required so it seems it is working. SIDE QUESTION: How to simulate this project ID so I can still run locally?

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)
3 Answers

The Java 10 version is EOL, and the official images has been removed. More detail here

Prefer a Java 11 version.

Anyway, when you use version, some are optimized and does not install bash by default (for reducing their size) and you have to install it by yourselves.

For a local run, I don't recommend to use a JSON key file (in general, don't use JSON key file, except for automated system out of GCP) due to security constraint, key rotation, secure storage,...

For setting the project, simply perform this command gcloud config set project MY_PROJECT. You don't need credential for this.

This problem may be due to the fact that alpine doesn't have bash: "/bin/sh" therefore a solution could be to remove the dependency on bash itself by not using bash or by using exec instead of bash. in my case I solved the problem by using a more complete base image, instead of alpine for instance.

HTH

Related