Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit 53453f2

Browse files
committed
- add that a port from Python 2 to 3 means migrating from Gen1 to Gen2 App Engine platforms
- add Cloud Run deploy steps - update Buildpacks build info & service.yaml format
1 parent 80bfbb0 commit 53453f2

File tree

5 files changed

+47
-13
lines changed

5 files changed

+47
-13
lines changed

step2-flask-cloudndb-py3/README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Porting from Python 2 to 3 is not within the scope of this tutorial, and our sim
1515
1. Delete the `lib` folder for the same reason.
1616
1. Migrate from App Engine NDB to Cloud NDB
1717

18+
In addition to *actually* porting your app from Python 2.x to 3.x, you would also be migrating from the original App Engine runtime ("Gen1") to the next-gen runtime ("Gen2"), and there are some important differences you need to know which are [listed here](https://cloud.google.com/appengine/docs/standard/python3/python-differences).
19+
1820
### Configuration
1921

2022
The only real change for this sample app is to significantly shorten `app.yaml` down to just these lines for the runtime as well as routing:
@@ -27,7 +29,21 @@ handlers:
2729
script: auto
2830
```
2931
30-
`requirements.txt` and `templates/index.html` remain unchanged while the `appengine_config.py` file and `lib` folder are deleted.
32+
An additional improvement you can make is to get rid of the `handlers:` section altogether (especially since `script: auto` is the only accepted directive regardless of URL path) and replace it with an `entrypoint:` directive. In Gen1, handlers were necessary to help route requests to your app, but in Gen2, routing is the responsibility of the web framework, not as an App Engine configuration.
33+
34+
35+
TODO
36+
37+
If you do that, you're `app.yaml` may look like the following (assuming there is a "main" function in your `main.py` which we not have in ours until Step 4):
38+
39+
```yml
40+
runtime: python38
41+
entrypoint: python main.py
42+
```
43+
44+
Check out [this page in the documentation](https://cloud.google.com/appengine/docs/standard/python3/runtime#application_startup) to find out more about the `entrypoint:` directive for `app.yaml` files.
45+
46+
The `requirements.txt` and `templates/index.html` files remain unchanged while the `appengine_config.py` file and `lib` folder are deleted.
3147

3248
---
3349

@@ -36,4 +52,4 @@ handlers:
3652
From here, your options are:
3753

3854
- [**Step 4:**](/step4-cloudds-cloudrun-py3) Migrate your app to a container executing serverlessly on Cloud Run
39-
- [**Step 3:**](/step3-flask-datastore-py3) Further modernize Datastore access from Cloud NDB to the (official) Cloud Datastore library (how users *outside of* App Engine access Cloud Datastore)
55+
- [**Step 3:**](/step3-flask-datastore-py3) Further modernize Datastore access from Cloud NDB to the (official) Cloud Datastore library (how users *outside of* App Engine access Cloud Datastore)

step4-cloudds-cloudrun-py3/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,18 @@ Doublecheck there are no files/folders named, `app.yaml`, `appengine_config.py`,
7575

7676
---
7777

78+
## Deploy
79+
80+
We didn't show you the deploy steps for the App Engine samples, but since some of you will be new to containers and Cloud Run, here is how you build & deploy your container on Cloud Run (fully-managed) once you've got all prior steps completed:
81+
82+
1. Build container: `gcloud builds submit --tag gcr.io/PROJECT_ID/IMG_NAME` (think `docker build` followed by `docker push`)
83+
2. Deploy service: `gcloud run deploy SVC_NAME --image gcr.io/PROJECT_ID/IMG_NAME --platform managed` (think `docker run`)
84+
85+
---
86+
7887
## Next
7988

8089
Congratulations... your app is fully modernized now, concluding this tutorial. From here, there is only one more thing you can investigate:
8190

8291
- [**Step 4a:**](/step4a-cloudrun-bldpks-py3) An alternative to app in *this* tutorial, containerizing your app with [Cloud Buildpacks](https://github.com/GoogleCloudPlatform/buildpacks) instead of Docker.
83-
- [**Step 3a:**](/step3a-flask-firestore-py3) For those who are considering migrating from Cloud Datastore to Firestore (NOTE: that app is not containerized & runs on App Engine)
92+
- [**Step 3a:**](/step3a-flask-firestore-py3) For those who are considering migrating from Cloud Datastore to Firestore (NOTE: that app is not containerized & runs on App Engine)

step4-cloudndb-cloudrun-py2/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ Doublecheck there are no files/folders named, `app.yaml`, `appengine_config.py`,
7575

7676
---
7777

78+
## Deploy
79+
80+
We didn't show you the deploy steps for the App Engine samples, but since some of you will be new to containers and Cloud Run, here is how you build & deploy your container on Cloud Run (fully-managed) once you've got all prior steps completed:
81+
82+
1. Build container: `gcloud builds submit --tag gcr.io/PROJECT_ID/IMG_NAME` (think `docker build` followed by `docker push`)
83+
2. Deploy service: `gcloud run deploy SVC_NAME --image gcr.io/PROJECT_ID/IMG_NAME --platform managed` (think `docker run`)
84+
85+
---
86+
7887
## Next
7988

8089
Congratulations... your app is fully modernized now, concluding this tutorial. From here, there are only a few more things you can investigate:

step4a-cloudrun-bldpks-py3/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Introduction
44

5-
This codelab represents an alternative to Step 4 (just the Python 3 version) where you're migrating your App Engine app to Cloud Run, but using Cloud Buildpacks instead of Docker. As Docker is an industry standard for containers, users choosing to follow this path are those who don't want to be dependent on a single company (and its control) or do not wish to become familiar with the Docker product and instead, opting for a more standardized approach to container-building that has multiple supporters in industry (more below).
5+
This codelab represents an alternative to Step 4 (just the Python 3 version) where you're migrating your App Engine app to Cloud Run, but using Cloud Buildpacks instead of Docker. As Docker is an industry standard for containers, users choosing to follow this path are those who don't want to have to become familiar with working with Docker product or carefully curating their `Dockerfile` and instead, opting for a more standardized approach to container-building that has multiple supporters in industry (more below).
66

77
---
88

@@ -21,7 +21,7 @@ While Docker is an industry standard, some developers may prefer to avoid learni
2121
### Configuration
2222

2323
1. Convert your `app.yaml` to a `service.yaml` with [the tool](http://googlecloudplatform.github.io/app-engine-cloud-run-converter).
24-
1. Update `service.yaml` with your `PROJECT-ID`, `REGION`, and `SERVICE`.
24+
1. Update `service.yaml` with your `PROJECT_ID`, `REGION`, `CONT_NAME`, and `SVC_NAME`.
2525
1. Run the appropriate `gcloud` commands to build the container (see below).
2626
1. Create a [`Procfile`](https://devcenter.heroku.com/articles/procfile) specifying the entrypoint of your app; see [example](https://devcenter.heroku.com/articles/getting-started-with-python#define-a-procfile).
2727

@@ -31,7 +31,7 @@ Since this is only for Gen2 runtimes, we have to paste the contents of `step3-fl
3131
apiVersion: serving.knative.dev/v1
3232
kind: Service
3333
metadata:
34-
name: SERVICE
34+
name: SVC_NAME
3535
labels:
3636
migrated-from: app-engine
3737
cloud.googleapis.com/location: REGION
@@ -41,12 +41,12 @@ spec:
4141
annotations: {}
4242
spec:
4343
containers:
44-
- image: gcr.io/PROJECT-ID/SERVICE
45-
serviceAccountName: PROJECT-ID@appspot.gserviceaccount.com
44+
- image: gcr.io/PROJECT_ID/IMG_NAME
45+
serviceAccountName: PROJECT_NUM-compute@developer.gserviceaccount.com
4646
```
4747
4848
Update the image and service account name, then run one of these build commands, depending on whether your service is public (or not):
49-
- Run `gcloud alpha builds submit --pack image=gcr.io/PROJECT-ID/SERVICE && gcloud beta run services replace service.yaml --region us-central1 --platform managed` (private services)
49+
- Run `gcloud alpha builds submit --pack image=gcr.io/PROJECT_ID/IMG_NAME && gcloud beta run services replace service.yaml --region us-central1 --platform managed` (private services)
5050
- OR `gcloud run services add-iam-policy-binding my-service --member="allUsers" --role="roles/run.invoker" --region us-central1 --platform managed` (public services)
5151

5252
Delete the `app.yaml` (or back it up somewhere) as it is no longer needed. Then create a `Procfile` file specifying the application entry-point. The one for this app:

step4a-cloudrun-bldpks-py3/service.yaml

100644100755
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
apiVersion: serving.knative.dev/v1
1616
kind: Service
1717
metadata:
18-
name: default
18+
name: SVC_NAME
1919
labels:
2020
migrated-from: app-engine
21-
cloud.googleapis.com/location: APP_REGION
21+
cloud.googleapis.com/location: REGION
2222
spec:
2323
template:
2424
metadata:
2525
annotations: {}
2626
spec:
2727
containers:
28-
- image: gcr.io/PROJECT_ID/image
29-
serviceAccountName: docker-client1@PROJECT_ID.iam.gserviceaccount.com
28+
- image: gcr.io/PROJECT_ID/IMG_NAME
29+
serviceAccountName: PROJECT_NUM-compute@developer.gserviceaccount.com

0 commit comments

Comments
 (0)