Skip to content

Commit 7a89ddd

Browse files
Merge branch 'main' into hivanalejandro-migrate-region-step1-386956777
2 parents 4520d97 + e96838c commit 7a89ddd

File tree

10 files changed

+149
-14
lines changed

10 files changed

+149
-14
lines changed

.github/config/nodejs-dev.jsonc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@
100100
"auth",
101101
"batch",
102102
"cloud-language",
103+
"cloud-sql/mysql/mysql",
104+
"cloud-sql/mysql/mysql2",
105+
"cloud-sql/postgres/knex",
103106
"cloud-tasks/snippets",
104107
"cloud-tasks/tutorial-gcf/app",
105108
"cloud-tasks/tutorial-gcf/function",

.github/config/nodejs-prod.jsonc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@
7777
// TODO: fix these
7878
"ai-platform/snippets", // PERMISSION_DENIED: Permission denied: Consumer 'projects/undefined' has been suspended.
7979
"automl", // (untested) FAILED_PRECONDITION: Google Cloud AutoML Natural Language was retired on March 15, 2024. Please migrate to Vertex AI instead
80-
"cloud-sql/mysql/mysql", // (untested) Error: expected 200 "OK", got 500 "Internal Server Error"
81-
"cloud-sql/mysql/mysql2", // (untested) Error: Cannot find module './connect-connector-with-iam-authn.js'
82-
"cloud-sql/postgres/knex", // (untested) CloudSQLConnectorError: Malformed instance connection name provided: expected format of "PROJECT:REGION:INSTANCE", got undefined
8380
"cloud-sql/sqlserver/mssql", // (untested) TypeError: The "config.server" property is required and must be of type string.
8481
"cloud-sql/sqlserver/tedious", // (untested) TypeError: The "config.server" property is required and must be of type string.
8582
"compute", // GoogleError: The resource 'projects/long-door-651/zones/us-central1-a/disks/disk-from-pool-name' was not found
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash -ex
2+
3+
# Copyright 2025 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Shared Cloud SQL Proxy setup
18+
# Presumes the following variables in ci-setup.json:
19+
# * CLOUD_SQL_CONNECTION_NAME - the project:region:instance of a Cloud SQL instance.
20+
# * UNIX_SOCKET_DIR - a local directory to set the proxy to (default tmp/cloudsql)
21+
#
22+
# Note: in GitHub Actions environments, `/cloudsql` is not valid.
23+
# Ensure any INSTANCE_UNIX_SOCKET value is ~= $UNIX_SOCKET_DIR/$CLOUD_SQL_CONNECTION_NAME
24+
25+
usage() {
26+
cat << EOF
27+
# Usage:
28+
# CLOUD_SQL_CONNECTION_NAME=project:region:instance sql-proxy.sh [..]
29+
#
30+
# Defaults to TCP socket proxy. Set `SOCKET=unix` for Unix sockets.
31+
#
32+
# Usage in package.json:
33+
#
34+
# "proxy": "$GITHUB_WORKSPACE/.github/workflows/utils/sql-proxy.sh",
35+
# "system-test": "npm run proxy -- c8 mocha test/... ",
36+
# "system-test-unix": "SOCKET=unix npm run proxy -- c8 mocha test/... ",
37+
EOF
38+
}
39+
40+
41+
PROXY_VERSION="v2.15.1"
42+
SOCKET=${SOCKET:-tcp}
43+
44+
echop(){ # Print Echo
45+
echo "👾 $1"
46+
}
47+
48+
exit_message() { # Error Echo
49+
echo "$1"
50+
usage
51+
exit 1
52+
}
53+
54+
if [[ -z "$CLOUD_SQL_CONNECTION_NAME" ]]; then
55+
exit_message "Must provide CLOUD_SQL_CONNECTION_NAME"
56+
fi
57+
58+
if [[ $SOCKET == "unix" ]]; then
59+
UNIX_SOCKET_DIR=${UNIX_SOCKET_DIR:-"tmp/cloudsql"}
60+
61+
if [[ $UNIX_SOCKET_DIR == "/cloudsql" ]]; then
62+
exit_message "Cannot use /cloudsql in a GitHub Actions context"
63+
fi
64+
65+
mkdir -p $UNIX_SOCKET_DIR && chmod 777 $UNIX_SOCKET_DIR
66+
socket="--unix-socket $UNIX_SOCKET_DIR"
67+
fi
68+
echop "Setting up cloud-sql-proxy for $SOCKET socket connections"
69+
70+
# Download the Cloud SQL Auth Proxy (only once)
71+
if [[ ! -f cloud-sql-proxy ]]; then
72+
curl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/${PROXY_VERSION}/cloud-sql-proxy.linux.amd64
73+
if [[ $? -ne 0 ]]; then
74+
echo "Failed to download cloud-sql-proxy"
75+
exit 1
76+
fi
77+
chmod +x cloud-sql-proxy
78+
else
79+
echo "cloud-sql-proxy already downloaded"
80+
fi
81+
82+
# Setup proxy
83+
./cloud-sql-proxy $socket $CLOUD_SQL_CONNECTION_NAME &
84+
sleep 5
85+
echop "Proxy ready for use"
86+
87+
# Run whatever command was passed to this script
88+
$@ || STATUS=$?
89+
90+
# Cleanup
91+
echop "Shutting down proxy process"
92+
pkill -f "cloud-sql-proxy" || echo "cloud-sql-proxy process not found. Was it already stopped?"
93+
94+
# Fail if the tests failed
95+
exit $STATUS
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"env": {
3+
"INSTANCE_HOST": "127.0.0.1",
4+
"INSTANCE_CONNECTION_NAME": "nodejs-docs-samples-tests:us-central1:mysql-ci",
5+
"UNIX_SOCKET_DIR": "tmp/cloudsql",
6+
"CLOUD_SQL_CONNECTION_NAME": "$INSTANCE_CONNECTION_NAME",
7+
"INSTANCE_UNIX_SOCKET": "$UNIX_SOCKET_DIR/$INSTANCE_CONNECTION_NAME",
8+
"DB_NAME": "kokoro_ci",
9+
"DB_USER": "kokoro_ci"
10+
},
11+
"secrets": {
12+
"DB_PASS": "nodejs-docs-samples-tests/nodejs-docs-samples-sql-password"
13+
}
14+
}

cloud-sql/mysql/mysql/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
},
1414
"scripts": {
1515
"start": "node server/server.js",
16-
"system-test": "c8 mocha -p -j 2 test/server.test.js --timeout=60000 --exit",
17-
"system-test-unix": "c8 mocha -p -j 2 test/server-unix.test.js --timeout=60000 --exit",
16+
"proxy": "$GITHUB_WORKSPACE/.github/workflows/utils/sql-proxy.sh",
17+
"system-test": "npm run proxy -- c8 mocha -p -j 2 test/server.test.js --colors --timeout=60000 --exit",
18+
"system-test-unix": "SOCKET=unix npm run proxy -- c8 mocha -p -j 2 test/server-unix.test.js --colors --timeout=60000 --exit",
1819
"test": "npm run system-test && npm run system-test-unix"
1920
},
2021
"dependencies": {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"env": {
3+
"INSTANCE_HOST": "127.0.0.1",
4+
"INSTANCE_CONNECTION_NAME": "nodejs-docs-samples-tests:us-central1:mysql-ci",
5+
"UNIX_SOCKET_DIR": "tmp/cloudsql",
6+
"CLOUD_SQL_CONNECTION_NAME": "$INSTANCE_CONNECTION_NAME",
7+
"INSTANCE_UNIX_SOCKET": "$UNIX_SOCKET_DIR/$INSTANCE_CONNECTION_NAME",
8+
"DB_NAME": "kokoro_ci",
9+
"DB_USER": "kokoro_ci"
10+
},
11+
"secrets": {
12+
"DB_PASS": "nodejs-docs-samples-tests/nodejs-docs-samples-sql-password"
13+
}
14+
}

cloud-sql/mysql/mysql2/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'use strict';
1616

1717
const express = require('express');
18-
const createConnectorIAMAuthnPool = require('./connect-connector-with-iam-authn.js');
18+
const createConnectorIAMAuthnPool = require('./connect-connector-auto-iam-authn.js');
1919
const createConnectorPool = require('./connect-connector.js');
2020
const createTcpPool = require('./connect-tcp.js');
2121
const createUnixSocketPool = require('./connect-unix.js');
@@ -65,9 +65,7 @@ const createPool = async () => {
6565
// 'connectTimeout' is the maximum number of milliseconds before a timeout
6666
// occurs during the initial connection to the database.
6767
connectTimeout: 10000, // 10 seconds
68-
// 'acquireTimeout' is the maximum number of milliseconds to wait when
69-
// checking out a connection from the pool before a timeout error occurs.
70-
acquireTimeout: 10000, // 10 seconds
68+
// 'acquireTimeout' is currently unsupported by mysql2
7169
// 'waitForConnections' determines the pool's action when no connections are
7270
// free. If true, the request will queued and a connection will be presented
7371
// when ready. If false, the pool will call back with an error.
@@ -172,7 +170,7 @@ const httpGet = app.get('/', async (req, res) => {
172170

173171
// Run queries concurrently, and wait for them to complete
174172
// This is faster than await-ing each query object as it is created
175-
const recentVotes = await recentVotesQuery;
173+
const [recentVotes] = await recentVotesQuery; // Return only the results, not the field metadata
176174
const [tabsVotes] = await tabsQuery;
177175
const [spacesVotes] = await spacesQuery;
178176

cloud-sql/mysql/mysql2/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
"scripts": {
1515
"start": "node server/server.js",
1616
"system-test": "c8 mocha -p -j 2 test/server.test.js --timeout=60000 --exit",
17-
"system-test-tcp": "c8 mocha -p -j 2 test/server-unix.test.js --timeout=60000 --exit",
18-
"system-test-unix": "c8 mocha -p -j 2 test/server-unix.test.js --timeout=60000 --exit",
19-
"test": "npm run system-test && npm run system-test-tcp && npm run system-test-unix"
17+
"test": "npm run system-test"
2018
},
2119
"dependencies": {
2220
"@google-cloud/cloud-sql-connector": "^1.0.0",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"env": {
3+
"INSTANCE_HOST": "127.0.0.1",
4+
"INSTANCE_CONNECTION_NAME": "nodejs-docs-samples-tests:us-central1:postgres-ci",
5+
"UNIX_SOCKET_DIR": "tmp/cloudsql",
6+
"CLOUD_SQL_CONNECTION_NAME": "$INSTANCE_CONNECTION_NAME",
7+
"INSTANCE_UNIX_SOCKET": "$UNIX_SOCKET_DIR/$INSTANCE_CONNECTION_NAME",
8+
"DB_NAME": "kokoro_ci",
9+
"DB_USER": "kokoro_ci"
10+
},
11+
"secrets": {
12+
"DB_PASS": "nodejs-docs-samples-tests/nodejs-docs-samples-sql-password"
13+
}
14+
}

cloud-sql/postgres/knex/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
},
1515
"scripts": {
1616
"start": "node server/server.js",
17+
"proxy": "$GITHUB_WORKSPACE/.github/workflows/utils/sql-proxy.sh",
1718
"start-proxy": "! pgrep cloud_sql_proxy > /dev/null && cloud_sql_proxy -dir=/cloudsql -instances=$INSTANCE_CONNECTION_NAME &",
18-
"test": "c8 mocha -p -j 2 test/*.test.js --timeout=60000 --exit"
19+
"test": "npm run proxy -- c8 mocha -p -j 2 test/*.test.js --timeout=60000 --exit"
1920
},
2021
"dependencies": {
2122
"@google-cloud/cloud-sql-connector": "^1.0.0",

0 commit comments

Comments
 (0)