From 95fe2e050efc9fc6448e3eff850bca221c6821da Mon Sep 17 00:00:00 2001 From: Jennifer Davis Date: Mon, 15 May 2023 12:21:41 -0700 Subject: [PATCH 1/7] fix: add region tag, move code around for docs pair with @nicain; this is not typical usage of if __name__ == .. but to make sure documentation and intent of the sample for atlas this should work. Co-authored-by: Nick Cain --- run/pubsub/main.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/run/pubsub/main.py b/run/pubsub/main.py index 4051f73d018..b0dfc40f7cc 100644 --- a/run/pubsub/main.py +++ b/run/pubsub/main.py @@ -14,6 +14,7 @@ # [START cloudrun_pubsub_server_setup] # [START run_pubsub_server_setup] +# [START cloudrun_pubsub_server] import base64 import os @@ -21,9 +22,17 @@ app = Flask(__name__) + +if __name__ == "__main__": + PORT = int(os.getenv("PORT")) if os.getenv("PORT") else 8080 + + # This is used when running locally. Gunicorn is used to run the + # application on Cloud Run. See entrypoint in Dockerfile. + app.run(host="127.0.0.1", port=PORT, debug=True) + # [END run_pubsub_server_setup] # [END cloudrun_pubsub_server_setup] - +# [END cloudrun_pubsub_server] # [START cloudrun_pubsub_handler] # [START run_pubsub_handler] @@ -53,11 +62,3 @@ def index(): # [END run_pubsub_handler] # [END cloudrun_pubsub_handler] - - -if __name__ == "__main__": - PORT = int(os.getenv("PORT")) if os.getenv("PORT") else 8080 - - # This is used when running locally. Gunicorn is used to run the - # application on Cloud Run. See entrypoint in Dockerfile. - app.run(host="127.0.0.1", port=PORT, debug=True) From 3ef40cb222424255c317a47c4c35cf7b542d45fa Mon Sep 17 00:00:00 2001 From: Jennifer Davis Date: Mon, 15 May 2023 12:28:19 -0700 Subject: [PATCH 2/7] Fix: linting Update main.py I deleted one too many empty lines. --- run/pubsub/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/run/pubsub/main.py b/run/pubsub/main.py index b0dfc40f7cc..a11f90350b4 100644 --- a/run/pubsub/main.py +++ b/run/pubsub/main.py @@ -34,6 +34,7 @@ # [END cloudrun_pubsub_server_setup] # [END cloudrun_pubsub_server] + # [START cloudrun_pubsub_handler] # [START run_pubsub_handler] @app.route("/", methods=["POST"]) From bfbe4e934e3b4faa0ac2b047c416b554d9d338dc Mon Sep 17 00:00:00 2001 From: Jennifer Davis Date: Mon, 15 May 2023 13:40:32 -0700 Subject: [PATCH 3/7] fix: change debug to False --- run/pubsub/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/pubsub/main.py b/run/pubsub/main.py index a11f90350b4..6886df09089 100644 --- a/run/pubsub/main.py +++ b/run/pubsub/main.py @@ -28,7 +28,7 @@ # This is used when running locally. Gunicorn is used to run the # application on Cloud Run. See entrypoint in Dockerfile. - app.run(host="127.0.0.1", port=PORT, debug=True) + app.run(host="127.0.0.1", port=PORT, debug=False) # [END run_pubsub_server_setup] # [END cloudrun_pubsub_server_setup] From 93b2c5d6e1c90ac615aad6fa82b907d6141c51ce Mon Sep 17 00:00:00 2001 From: Jennifer Davis Date: Mon, 15 May 2023 13:41:36 -0700 Subject: [PATCH 4/7] fix: remove old region tag that is no longer used --- run/pubsub/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/run/pubsub/main.py b/run/pubsub/main.py index 6886df09089..6841c93deec 100644 --- a/run/pubsub/main.py +++ b/run/pubsub/main.py @@ -13,7 +13,6 @@ # limitations under the License. # [START cloudrun_pubsub_server_setup] -# [START run_pubsub_server_setup] # [START cloudrun_pubsub_server] import base64 import os @@ -30,7 +29,6 @@ # application on Cloud Run. See entrypoint in Dockerfile. app.run(host="127.0.0.1", port=PORT, debug=False) -# [END run_pubsub_server_setup] # [END cloudrun_pubsub_server_setup] # [END cloudrun_pubsub_server] From 92b351f0d1450c9282bc7a79a47c0ad734f5895d Mon Sep 17 00:00:00 2001 From: Jennifer Davis Date: Mon, 15 May 2023 15:04:10 -0700 Subject: [PATCH 5/7] fix: standardize on server remote region tag server_setup --- run/pubsub/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/run/pubsub/main.py b/run/pubsub/main.py index 6841c93deec..279ad2f58f2 100644 --- a/run/pubsub/main.py +++ b/run/pubsub/main.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# [START cloudrun_pubsub_server_setup] # [START cloudrun_pubsub_server] import base64 import os @@ -29,7 +28,6 @@ # application on Cloud Run. See entrypoint in Dockerfile. app.run(host="127.0.0.1", port=PORT, debug=False) -# [END cloudrun_pubsub_server_setup] # [END cloudrun_pubsub_server] From 1712acc82902ec3959e1ac000a879fb0b780217a Mon Sep 17 00:00:00 2001 From: Jennifer Davis Date: Mon, 15 May 2023 15:28:20 -0700 Subject: [PATCH 6/7] fix: bring back region tag process for changing the name for a region tag is to add the second one, update docs, then remove the old tag. So this requires both region tags currently. Second, remove the if statement. Even if this is not matching the intent of the other samples, this is the preferred method from @engelke --- run/pubsub/main.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/run/pubsub/main.py b/run/pubsub/main.py index 279ad2f58f2..44f02361147 100644 --- a/run/pubsub/main.py +++ b/run/pubsub/main.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +# [START cloudrun_pubsub_server_setup] # [START cloudrun_pubsub_server] import base64 import os @@ -21,13 +22,7 @@ app = Flask(__name__) -if __name__ == "__main__": - PORT = int(os.getenv("PORT")) if os.getenv("PORT") else 8080 - - # This is used when running locally. Gunicorn is used to run the - # application on Cloud Run. See entrypoint in Dockerfile. - app.run(host="127.0.0.1", port=PORT, debug=False) - +# [END cloudrun_pubsub_server_setup] # [END cloudrun_pubsub_server] From 97a2f734fb3e94dead83774a0ca4339856de67d1 Mon Sep 17 00:00:00 2001 From: Jennifer Davis Date: Mon, 15 May 2023 16:21:58 -0700 Subject: [PATCH 7/7] fix: remove os as no longer using it --- run/pubsub/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/run/pubsub/main.py b/run/pubsub/main.py index 44f02361147..e204943b395 100644 --- a/run/pubsub/main.py +++ b/run/pubsub/main.py @@ -15,7 +15,6 @@ # [START cloudrun_pubsub_server_setup] # [START cloudrun_pubsub_server] import base64 -import os from flask import Flask, request