[go: up one dir, main page]

Skip to content

Commit

Permalink
chore(cloudsql): update samples to gen2 functions and v2 proxy (#9854)
Browse files Browse the repository at this point in the history
* chore(cloudsql): update samples to gen2 Cloud Functions

* chore: update samples to v2 proxy

* chore: address PR comments
  • Loading branch information
jackwotherspoon committed May 3, 2023
1 parent d06561c commit 9606fc2
Show file tree
Hide file tree
Showing 18 changed files with 695 additions and 256 deletions.
352 changes: 280 additions & 72 deletions cloud-sql/mysql/sqlalchemy/README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cloud-sql/mysql/sqlalchemy/app.flexible.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ entrypoint: gunicorn -b :$PORT app:app
# Cloud Secret Manager (https://cloud.google.com/secret-manager) to help
# keep secrets safe.
env_variables:
INSTANCE_UNIX_SOCKET: /cloudsql/<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>
INSTANCE_UNIX_SOCKET: /cloudsql/<PROJECT_ID>:<INSTANCE_REGION>:<INSTANCE_NAME>
DB_USER: <YOUR_DB_USER_NAME>
DB_PASS: <YOUR_DB_PASSWORD>
DB_NAME: <YOUR_DB_NAME>

beta_settings:
cloud_sql_instances: <PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>
cloud_sql_instances: <PROJECT_ID>:<INSTANCE_REGION>:<INSTANCE_NAME>
4 changes: 2 additions & 2 deletions cloud-sql/mysql/sqlalchemy/app.standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

runtime: python37
runtime: python310
entrypoint: gunicorn -b :$PORT app:app

# Note: Saving credentials in environment variables is convenient, but not
# secure - consider a more secure solution such as
# Cloud Secret Manager (https://cloud.google.com/secret-manager) to help
# keep secrets safe.
env_variables:
INSTANCE_UNIX_SOCKET: /cloudsql/<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>
INSTANCE_UNIX_SOCKET: /cloudsql/<PROJECT_ID>:<INSTANCE_REGION>:<INSTANCE_NAME>
DB_USER: <YOUR_DB_USER_NAME>
DB_PASS: <YOUR_DB_PASSWORD>
DB_NAME: <YOUR_DB_NAME>
11 changes: 5 additions & 6 deletions cloud-sql/mysql/sqlalchemy/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,17 @@ spec:
# This uses the latest version of the Cloud SQL proxy
# It is recommended to use a specific version for production environments.
# See: https://github.com/GoogleCloudPlatform/cloudsql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:latest
command:
- "/cloud_sql_proxy"

image: gcr.io/cloud-sql-connectors/cloud-sql-proxy:latest
args:
# If connecting from a VPC-native GKE cluster, you can use the
# following flag to have the proxy connect over private IP
# - "-ip_address_types=PRIVATE"
# - "--private-ip"

# tcp should be set to the port the proxy should listen on
# and should match the DB_PORT value set above.
# Defaults: MySQL: 3306, Postgres: 5432, SQLServer: 1433
- "-instances=<INSTANCE_CONNECTION_NAME>=tcp:3306"
- "--port=3306"
- "<INSTANCE_CONNECTION_NAME>"
securityContext:
# The default Cloud SQL proxy image runs as the
# "nonroot" user and group (uid: 65532) by default.
Expand Down
3 changes: 3 additions & 0 deletions cloud-sql/mysql/sqlalchemy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from flask import render_template, Response

import functions_framework

from app import get_index_context, init_connection_pool, migrate_db, save_vote

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


@functions_framework.http
def votes(request):
if request.method == "GET":
context = get_index_context(db)
Expand Down
1 change: 1 addition & 0 deletions cloud-sql/mysql/sqlalchemy/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ SQLAlchemy==2.0.12
PyMySQL==1.0.3
gunicorn==20.1.0
cloud-sql-python-connector==1.2.2
functions-framework==3.3.0

0 comments on commit 9606fc2

Please sign in to comment.