4
votes

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.

3
Include the Dockerfile in your question. The error message indicates that /bin/sh does not exist which is true for some very stripped images.John Hanley
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.Peter
You are using it here: RUN ./setup.sh; echo 0John Hanley
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.Peter
what's the ./pharo program/script?guillaume blaquiere

3 Answers

3
votes

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.

3
votes

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.

3
votes

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.