Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use Cloud SQL Proxy v2 in READMEs #3998

Merged
merged 8 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions cloudsql/mysql/database-sql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ Note the connection string, database user, and database password that you create
[instructions](https://cloud.google.com/sql/docs/mysql/create-manage-databases).
Note the database name.

1. Create a service account with the 'Cloud SQL Client' permissions by following these
[instructions](https://cloud.google.com/sql/docs/mysql/connect-external-app#4_if_required_by_your_authentication_method_create_a_service_account).
Download a JSON key to use to authenticate your connection.
1. Set up [Application Default Credentials][adc] and ensure you have
added the 'Cloud SQL Client' role to your IAM principal.

[adc]: https://cloud.google.com/docs/authentication/provide-credentials-adc

## Running locally

Expand All @@ -34,7 +35,6 @@ To run the sample locally with a TCP connection, set environment variables and l
#### Linux / Mac OS
Use these terminal commands to initialize environment variables:
```bash
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account/key.json
export INSTANCE_HOST='127.0.0.1'
export DB_PORT='3306'
export DB_USER='<DB_USER_NAME>'
Expand All @@ -44,13 +44,12 @@ export DB_NAME='<DB_NAME>'

Then use this command to launch the proxy in the background:
```bash
./cloud_sql_proxy -instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>=tcp:3306 -credential_file=$GOOGLE_APPLICATION_CREDENTIALS &
./cloud-sql-proxy <PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --port=3306 &
```

#### Windows/PowerShell
Use these PowerShell commands to initialize environment variables:
```powershell
$env:GOOGLE_APPLICATION_CREDENTIALS="<CREDENTIALS_JSON_FILE>"
$env:INSTANCE_HOST="127.0.0.1"
$env:DB_PORT="3306"
$env:DB_USER="<YOUR_DB_USER_NAME>"
Expand All @@ -60,7 +59,7 @@ $env:DB_NAME="<YOUR_DB_NAME>"

Then use this command to launch the proxy in a separate PowerShell session:
```powershell
Start-Process -filepath "C:\<path to proxy exe>" -ArgumentList "-instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>=tcp:3306 -credential_file=<CREDENTIALS_JSON_FILE>"
Start-Process -filepath "C:\<path to proxy exe>" -ArgumentList "<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --port=3306"
```

### Launch proxy with Unix Domain Socket
Expand All @@ -74,7 +73,6 @@ sudo chown -R $USER ./cloudsql

Use these terminal commands to initialize environment variables:
```bash
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account/key.json
export INSTANCE_UNIX_SOCKET='./cloudsql/<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>'
export DB_USER='<YOUR_DB_USER_NAME>'
export DB_PASS='<YOUR_DB_PASSWORD>'
Expand All @@ -83,7 +81,8 @@ export DB_NAME='<YOUR_DB_NAME>'

Then use this command to launch the proxy in the background:
```bash
./cloud_sql_proxy -dir=./cloudsql --instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --credential_file=$GOOGLE_APPLICATION_CREDENTIALS &
./cloud-sql-proxy --unix-socket=./cloudsql \
<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> &
```

### Testing the application
Expand Down Expand Up @@ -236,8 +235,9 @@ the Cloud SQL Auth Proxy, one for a TCP connection and one for a Unix socket
connection.

```
cloud_sql_proxy -instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>=tcp:3306
cloud_sql_proxy -instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> -dir /cloudsql
cloud-sql-proxy <PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --port=3306
cloud-sql-proxy <PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> \
--unix-socket=/cloudsql
```

To run integration tests, use the following command, setting environment
Expand Down
16 changes: 7 additions & 9 deletions cloudsql/postgres/database-sql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ This repo contains the Go source code for a simple web app that can be deployed
[instructions](https://cloud.google.com/sql/docs/postgres/create-manage-databases).
Note the database name.

1. Create a service account with the 'Cloud SQL Client' permissions by following these
[instructions](https://cloud.google.com/sql/docs/mysql/connect-external-app#4_if_required_by_your_authentication_method_create_a_service_account).
Download a JSON key to use to authenticate your connection.
1. Set up [Application Default Credentials][adc] and ensure you have
added the 'Cloud SQL Client' role to your IAM principal.

[adc]: https://cloud.google.com/docs/authentication/provide-credentials-adc

## Running locally

Expand All @@ -36,7 +37,6 @@ To run the sample locally with a TCP connection, set environment variables and l
Use these terminal commands to initialize environment variables:

```bash
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account/key.json
export INSTANCE_HOST='127.0.0.1'
export DB_PORT='5432'
export DB_USER='<YOUR_DB_USER_NAME>'
Expand All @@ -47,15 +47,14 @@ export DB_NAME='<YOUR_DB_NAME>'
Then use this command to launch the proxy in the background:

```bash
./cloud_sql_proxy -instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>=tcp:5432 -credential_file=$GOOGLE_APPLICATION_CREDENTIALS &
./cloud-sql-proxy <PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --port=5432 &
```

#### Windows/PowerShell

Use these PowerShell commands to initialize environment variables:

```powershell
$env:GOOGLE_APPLICATION_CREDENTIALS="<CREDENTIALS_JSON_FILE>"
$env:INSTANCE_HOST="127.0.0.1"
$env:DB_PORT="5432"
$env:DB_USER="<YOUR_DB_USER_NAME>"
Expand All @@ -66,7 +65,7 @@ $env:DB_NAME="<YOUR_DB_NAME>"
Then use this command to launch the proxy in a separate PowerShell session:

```powershell
Start-Process -filepath "C:\<path to proxy exe>" -ArgumentList "-instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>=tcp:5432 -credential_file=<CREDENTIALS_JSON_FILE>"
Start-Process -filepath "C:\<path to proxy exe>" -ArgumentList "<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --port=5432"
```

### Launch proxy with Unix Domain Socket
Expand All @@ -83,7 +82,6 @@ sudo chown -R $USER ./cloudsql
Use these terminal commands to initialize environment variables:

```bash
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account/key.json
export INSTANCE_UNIX_SOCKET='./cloudsql/<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>'
export DB_USER='<YOUR_DB_USER_NAME>'
export DB_PASS='<YOUR_DB_PASSWORD>'
Expand All @@ -93,7 +91,7 @@ export DB_NAME='<YOUR_DB_NAME>'
Then use this command to launch the proxy in the background:

```bash
./cloud_sql_proxy -dir=./cloudsql --instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --credential_file=$GOOGLE_APPLICATION_CREDENTIALS &
./cloud-sql-proxy --unix-socket=./cloudsql <PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> &
```

### Testing the application
Expand Down
13 changes: 6 additions & 7 deletions cloudsql/sqlserver/database-sql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ Note the connection string, database user, and database password that you create
[instructions](https://cloud.google.com/sql/docs/sqlserver/create-manage-databases).
Note the database name.

1. Create a service account with the 'Cloud SQL Client' permissions by following these
[instructions](https://cloud.google.com/sql/docs/mysql/connect-external-app#4_if_required_by_your_authentication_method_create_a_service_account).
Download a JSON key to use to authenticate your connection.
1. Set up [Application Default Credentials][adc] and ensure you have
added the 'Cloud SQL Client' role to your IAM principal.

[adc]: https://cloud.google.com/docs/authentication/provide-credentials-adc

## Running locally

Expand All @@ -34,7 +35,6 @@ To run the sample locally with a TCP connection, set environment variables and l
#### Linux / Mac OS
Use these terminal commands to initialize environment variables:
```bash
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account/key.json
export INSTANCE_HOST='127.0.0.1'
export DB_PORT='1433'
export DB_USER='<YOUR_DB_USER_NAME>'
Expand All @@ -44,13 +44,12 @@ export DB_NAME='<YOUR_DB_NAME>'

Then use this command to launch the proxy in the background:
```bash
./cloud_sql_proxy -instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>=tcp:1433 -credential_file=$GOOGLE_APPLICATION_CREDENTIALS &
./cloud-sql-proxy <PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --port=1433 &
```

#### Windows/PowerShell
Use these PowerShell commands to initialize environment variables:
```powershell
$env:GOOGLE_APPLICATION_CREDENTIALS="<CREDENTIALS_JSON_FILE>"
$env:INSTANCE_HOST="127.0.0.1"
$env:DB_PORT="1433"
$env:DB_USER="<YOUR_DB_USER_NAME>"
Expand All @@ -60,7 +59,7 @@ $env:DB_NAME="<YOUR_DB_NAME>"

Then use this command to launch the proxy in a separate PowerShell session:
```powershell
Start-Process -filepath "C:\<path to proxy exe>" -ArgumentList "-instances=<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME>=tcp:1433 -credential_file=<CREDENTIALS_JSON_FILE>"
Start-Process -filepath "C:\<path to proxy exe>" -ArgumentList "<PROJECT-ID>:<INSTANCE-REGION>:<INSTANCE-NAME> --port=1433"
```

### Testing the application
Expand Down
Loading