Skip to content

Commit 9606fc2

Browse files
chore(cloudsql): update samples to gen2 functions and v2 proxy (GoogleCloudPlatform#9854)
* chore(cloudsql): update samples to gen2 Cloud Functions * chore: update samples to v2 proxy * chore: address PR comments
1 parent d06561c commit 9606fc2

File tree

18 files changed

+695
-256
lines changed

18 files changed

+695
-256
lines changed

cloud-sql/mysql/sqlalchemy/README.md

Lines changed: 280 additions & 72 deletions
Large diffs are not rendered by default.

cloud-sql/mysql/sqlalchemy/app.flexible.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ entrypoint: gunicorn -b :$PORT app:app
2121
# Cloud Secret Manager (https://cloud.google.com/secret-manager) to help
2222
# keep secrets safe.
2323
env_variables:
24-
INSTANCE_UNIX_SOCKET: /cloudsql/<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>
24+
INSTANCE_UNIX_SOCKET: /cloudsql/<PROJECT_ID>:<INSTANCE_REGION>:<INSTANCE_NAME>
2525
DB_USER: <YOUR_DB_USER_NAME>
2626
DB_PASS: <YOUR_DB_PASSWORD>
2727
DB_NAME: <YOUR_DB_NAME>
2828

2929
beta_settings:
30-
cloud_sql_instances: <PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>
30+
cloud_sql_instances: <PROJECT_ID>:<INSTANCE_REGION>:<INSTANCE_NAME>

cloud-sql/mysql/sqlalchemy/app.standard.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
runtime: python37
15+
runtime: python310
1616
entrypoint: gunicorn -b :$PORT app:app
1717

1818
# Note: Saving credentials in environment variables is convenient, but not
1919
# secure - consider a more secure solution such as
2020
# Cloud Secret Manager (https://cloud.google.com/secret-manager) to help
2121
# keep secrets safe.
2222
env_variables:
23-
INSTANCE_UNIX_SOCKET: /cloudsql/<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>
23+
INSTANCE_UNIX_SOCKET: /cloudsql/<PROJECT_ID>:<INSTANCE_REGION>:<INSTANCE_NAME>
2424
DB_USER: <YOUR_DB_USER_NAME>
2525
DB_PASS: <YOUR_DB_PASSWORD>
2626
DB_NAME: <YOUR_DB_NAME>

cloud-sql/mysql/sqlalchemy/deployment.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,17 @@ spec:
6161
# This uses the latest version of the Cloud SQL proxy
6262
# It is recommended to use a specific version for production environments.
6363
# See: https://github.com/GoogleCloudPlatform/cloudsql-proxy
64-
image: gcr.io/cloudsql-docker/gce-proxy:latest
65-
command:
66-
- "/cloud_sql_proxy"
67-
64+
image: gcr.io/cloud-sql-connectors/cloud-sql-proxy:latest
65+
args:
6866
# If connecting from a VPC-native GKE cluster, you can use the
6967
# following flag to have the proxy connect over private IP
70-
# - "-ip_address_types=PRIVATE"
68+
# - "--private-ip"
7169

7270
# tcp should be set to the port the proxy should listen on
7371
# and should match the DB_PORT value set above.
7472
# Defaults: MySQL: 3306, Postgres: 5432, SQLServer: 1433
75-
- "-instances=<INSTANCE_CONNECTION_NAME>=tcp:3306"
73+
- "--port=3306"
74+
- "<INSTANCE_CONNECTION_NAME>"
7675
securityContext:
7776
# The default Cloud SQL proxy image runs as the
7877
# "nonroot" user and group (uid: 65532) by default.

cloud-sql/mysql/sqlalchemy/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
from flask import render_template, Response
1616

17+
import functions_framework
18+
1719
from app import get_index_context, init_connection_pool, migrate_db, save_vote
1820

1921
############ TABS vs. SPACES App for Cloud Functions ############
@@ -24,6 +26,7 @@
2426
migrate_db(db)
2527

2628

29+
@functions_framework.http
2730
def votes(request):
2831
if request.method == "GET":
2932
context = get_index_context(db)

cloud-sql/mysql/sqlalchemy/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ SQLAlchemy==2.0.12
33
PyMySQL==1.0.3
44
gunicorn==20.1.0
55
cloud-sql-python-connector==1.2.2
6+
functions-framework==3.3.0

0 commit comments

Comments
 (0)