Home > database >  How to run a "hello world" python script with Google Cloud Run
How to run a "hello world" python script with Google Cloud Run

Time:12-15

Forgive my ignorance..

I'm trying to learn how to schedule python scripts with Google Cloud. After a bit of research, I've seen many people suggest Docker enter image description here

  • Deploy to Google Cloud Run

    enter image description here enter image description here enter image description here

  • Error

    At this point, I get the error

    The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable.

    I've seen posts like enter image description here

    Confusingly, you cannot deploy a cloud run job directly from Artifact Registry. You have to start from the cloud run dashboard.

    CodePudding user response:

    Your Flask application should be something like below:

    import os
    
    from flask import Flask
    
    app = Flask(__name__)
    
    
    @app.route("/")
    def hello_world():     
        return "Hello World!"
    
    
    if __name__ == "__main__":
        app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))
    

    See this official documentation for step by step instruction: Deploy a Python service to Cloud Run

    There is a plugin called: Cloud Code IDE plugin which makes the test and deployment easy. I am using it for VS code, once the initial setups and permissions are taken care, few clicks, you will be able to run locally, debug and deploy Cloud run services from your local instance.

    • Related