I am following the Google documentation to upload my docker file into the cloud console:
https://cloud.google.com/run/docs/quickstarts/build-and-deploy#python_1
I changed the main.py
file to my own app.py
which uses Flask. My local Dockerfile is defined as:
# Copyright 2020 Google, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# [START cloudrun_helloworld_dockerfile]
# [START run_helloworld_dockerfile]
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.9-slim
# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True
# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
# Install production dependencies.
RUN pip install Flask gunicorn
# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
ENTRYPOINT ["app.py"]
# [END run_helloworld_dockerfile]
# [END cloudrun_helloworld_dockerfile]
I am not sure if ENTRYPOINT
is need but without it the service does nothing, complains about not main.py
has been found. I can upload the image to the Cloud Run usinggcloud builds submit --tag gcr.io/projectid/webhook
, but the deployment will fail both using gcloud console or locally. The error says:
Invalid ENTRYPOINT. [\
name: "gcr.io/projectid/webhook@sha256:706cd97430e6537f91b0ac8c67262ba6a0c10f961c04a4d918ea1649bcead4e3" \
error: "Invalid command \"app.py\": \
file not found anywhere in PATH \"/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"" ].
Why is the file not found? I thought the Dockerfile will instruct to copy everything in the local directory.