Running gcloud run deploy from inside Cloud Build results in error

Viewed 2412

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 Answers

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.

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.

Related