3

I have a custom build step in Google Cloud Build, which first builds a docker image and then deploys it as a cloud run service.

This last step fails, with the following log output;

Step #2: Deploying... Step #2: Setting IAM Policy.........done Step 2: Creating Revision............................................................................................................................failed Step #2: Deployment failed Step #2: ERROR: (gcloud.run.deploy) Cloud Run error: Invalid argument error. Invalid ENTRYPOINT. [name: "gcr.io/opencobalt/silo@sha256:fb860e758eb1957b90ff3761fcdf68dedb9d10f832f2bb21375915d3de2aaed5" Step #2: error: "Invalid command \"/bin/sh\": file not found" Step #2: ]. Finished Step #2 ERROR ERROR: build step 2 "gcr.io/cloud-builders/gcloud" failed: step exited with non-zero status: 1

The build steps look like this;

["run","deploy","silo","--image","gcr.io/opencobalt/silo","--region","us-central1","--platform","managed","--allow-unauthenticated"]}

The image is built an exists in the registry, and if I change the last build step to deploy a compute engine VM instead, it works. Those build steps looks like this;

{"name":"gcr.io/cloud-builders/gcloud","args":["compute","instances", "create-with-container","silo","--container-image","gcr.io/opencobalt/silo","--zone","us-central1-a","--tags","silo,pharo"]}

I can also build the image locally but run into the same error when running gcloud run deploy locally.

I am trying to figure out how to solve this problem. The image works, since it runs fine locally and runs fine when deployed as a Compute Engine VM, the error only show up when I'm trying to deploy the image as a Cloud Run service.

(added) The Dockerfile looks like this;

###################################### # Based on Ubuntu image ###################################### FROM ubuntu ###################################### # Basic project infos ###################################### LABEL maintainer="PeterSvensson" ###################################### # Update Ubuntu apt and install some tools ###################################### RUN apt-get update \ && apt-get install -y wget \ && apt-get install -y git \ && apt-get install -y unzip \ && rm -rf /var/lib/apt/lists/* ###################################### # Have an own directory for the tool ###################################### RUN mkdir webapp WORKDIR webapp ###################################### # Download Pharo using Zeroconf & start script ###################################### RUN wget -O- https://get.pharo.org/64/80+vm | bash COPY service_account.json service_account.json RUN export certificate="$(cat service_account.json)" COPY load.st load.st COPY setup.sh setup.sh RUN chmod +x setup.sh RUN ./setup.sh; echo 0 RUN ./pharo Pharo.image load.st; echo 0 ###################################### # Expose port 8080 of Zinc outside the container ###################################### EXPOSE 8080 ###################################### # Finally run headless as server ###################################### CMD ./pharo --headless Pharo.image --no-quit 

Any advice warmly welcome. Thank you.

6
  • Include the Dockerfile in your question. The error message indicates that /bin/sh does not exist which is true for some very stripped images. Commented May 25, 2020 at 4:13
  • Thank you. I now added the Dockerfile. The reason I omitted it first was due to brevity and that it works well when deploying the image to Compute Engine. Also, I do not use /bin/sh in it, so it seems to be an artifact of the cloud run deploy process somehow. But I am not certain, it is a bit of a mystery, this. Commented May 25, 2020 at 5:42
  • You are using it here: RUN ./setup.sh; echo 0 Commented May 25, 2020 at 5:52
  • I would argue that it is a script that runs without explicitly invoking /bin/sh (which is included in standard Ubuntu, btw). But I did remove this file and running of it, and the end result was the same. Note that the image builds and is present in registry, and can run as a Container Engine VM service, returning values when being sent requests. It is only the specific cloud run build step that produces the error. And the same error happens again even after I removed any mention of setup.sh. Commented May 25, 2020 at 6:12
  • what's the ./pharo program/script? Commented May 25, 2020 at 7:06

3 Answers 3

3

After a lot of testing, I managed to come further. It seems that the /bin/sh missing file thing is a red herring.

I tried to change the startup command from CMD to ENTRYPOINT, since that was mentioned in the error, but it did not work. However, when I copied the startup instruction into a new file 'startup.sh' and changed the last line of the Dockerfile to;

ENTRYPOINT ./startup.sh

It did work. I needed to chmod +x the new file of course, but the strange thing is that ENTRYPOINT ./pharo --headless Pharo.image --no-quit gave the same error, and even ENTRYPOINT ["./pharo", "--headless", "Pharo.image", "--no-quit"] also gave the same error.

But having just one argument to ENTRYPOINT made cloud run work. Go figure.

Sign up to request clarification or add additional context in comments.

6 Comments

Phew. It was more complicated than that. This is what works properly, not sure why cloud run in particular is so picky about Dockerfile minutiae when the compute engine process is not; ENTRYPOINT ["./pharo"] CMD ["--headless", "Pharo.image", "--no-quit"]'
Cloud Run is not different than Docker when it comes to CMD/ENTRYPOINTs. Please run your container locally first as shown here cloud.google.com/run/docs/testing/local to test if it would work on Cloud Run.
Hi Ahmed, thank you for you comment. I agree that it shouldn't be. My current findings are; 1) I can build and run my container locally fine, 2) I can build the image using google cloud build fine and as a separate build step deploy it as a compute engine VM (and it runs fine there too), 3) for some reason Cloud Run specifically only accept ENTRYPOINT and with the specific bracket syntax ["foo","bar,..]. This changed from some months ago.
That doesn’t sound right. I use it all the time. When you don’t use brackets, “docker” is the one adding /bin/sh -c “...” around it. If you have a small repro feel free to link that.
I am also running into this issue. It works in skaffold/minikube, which is used as the local Cloud Run emulator, so something is off with Cloud Run specifically.
|
3

It appears that Google Cloud Run has a dislike for the ubuntu:20.04 image. I have the exact same problem with a Play framework application.

The command

ENTRYPOINT /opt/play-codecheck/bin/play-codecheck -Dconfig.file=/opt/codecheck/production.conf 

failed with

error: "Invalid command \"/bin/sh\": file not found" 

I also tried

ENTRYPOINT ["/bin/bash", "/opt/play-codecheck/bin/play-codecheck", "-Dconfig.file=/opt/codecheck/production.conf"] 

and was rewarded with

error: "Invalid command \"/bin/bash\": file not found" 

The trick of putting the command in a shell script didn't work for me either. However, when I changed

FROM ubuntu:20.04 

to

FROM ubuntu:18.04 

the image deployed. At this point, that's an acceptable fix for me, but it seems like something that Google needs to address.

Comments

3

See also:

Unable to deploy Ubuntu 20.04 Docker container on Google Cloud Run

My workaround was to use a CMD directive that calls Python directly rather than a shell (either /bin/sh or /bin/bash). It's working well so far.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.