Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
f46b2a1
wip: proof of concept cloud-sql mysql
glasnt Mar 25, 2025
c54abd2
chmod
glasnt Mar 25, 2025
e1d0de8
add sleep to ensure proxy starts before use
glasnt Mar 25, 2025
3507ff7
use correct envvar
glasnt Mar 25, 2025
41ad376
extra bit
glasnt Mar 25, 2025
ae36e28
debugging
glasnt Mar 25, 2025
5ecb710
instance_host is deleted by the server-unix test
glasnt Mar 25, 2025
6326bd3
proxy all tests
glasnt Mar 25, 2025
c004e1a
accepting gemini-code-assist code
glasnt Mar 25, 2025
6a98c4d
oop
glasnt Mar 25, 2025
0bbd11b
Merge branch 'main' into sql-tests-2
glasnt Mar 26, 2025
d82ed40
wip: tcp or unix
glasnt Mar 26, 2025
43a8e53
syntax
glasnt Mar 27, 2025
81781de
cause she looks like a flower
glasnt Mar 27, 2025
4ff9afc
more shell logic
glasnt Mar 27, 2025
a47abdf
sh
glasnt Mar 27, 2025
b7dcf45
continued proof of concept
glasnt Mar 27, 2025
8699edf
call shutdown
glasnt Mar 27, 2025
23b9430
format value
glasnt Mar 28, 2025
23f3a2e
order?
glasnt Mar 28, 2025
986a700
Merge branch 'main' into sql-tests-2
glasnt Mar 28, 2025
0cf5917
debug: echo
glasnt Mar 28, 2025
184e6c4
hoisted by my own petard.
glasnt Mar 28, 2025
5b00c53
tmp file
glasnt Mar 28, 2025
0e60a3d
-p
glasnt Mar 28, 2025
d43ccb1
WIP: shared proxy setup
glasnt Mar 28, 2025
a82cdbf
chmod
glasnt Mar 28, 2025
2c8a076
maybe?
glasnt Mar 28, 2025
f0fbd65
??
glasnt Mar 28, 2025
e8594a6
bash
glasnt Mar 28, 2025
f13d4eb
debug
glasnt Mar 28, 2025
629fa09
debug
glasnt Mar 28, 2025
8bf31b9
maybe
glasnt Mar 28, 2025
a62e1bf
more bash
glasnt Mar 28, 2025
24bd715
simplify usage
glasnt Mar 28, 2025
f26c218
cleanup
glasnt Mar 28, 2025
82ff1dd
actually use the new setting
glasnt Mar 28, 2025
8d5befd
remove old setting
glasnt Mar 28, 2025
b83a1af
attempt formatting
glasnt Mar 28, 2025
1e5b92d
add mocha colour
glasnt Mar 28, 2025
a8f39d5
at least use something
glasnt Mar 28, 2025
41bc54a
code review comments
glasnt Mar 30, 2025
21ebc78
syntax
glasnt Mar 30, 2025
919bd8f
syntax
glasnt Mar 30, 2025
c425a7e
fix usage
glasnt Mar 31, 2025
a811f0f
Merge branch 'main' into sql-tests-2
glasnt Mar 31, 2025
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
1 change: 1 addition & 0 deletions .github/config/nodejs-dev.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"auth",
"batch",
"cloud-language",
"cloud-sql/mysql/mysql",
"cloud-tasks/snippets",
"cloud-tasks/tutorial-gcf/app",
"cloud-tasks/tutorial-gcf/function",
Expand Down
1 change: 0 additions & 1 deletion .github/config/nodejs-prod.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
// TODO: fix these
"ai-platform/snippets", // PERMISSION_DENIED: Permission denied: Consumer 'projects/undefined' has been suspended.
"automl", // (untested) FAILED_PRECONDITION: Google Cloud AutoML Natural Language was retired on March 15, 2024. Please migrate to Vertex AI instead
"cloud-sql/mysql/mysql", // (untested) Error: expected 200 "OK", got 500 "Internal Server Error"
"cloud-sql/mysql/mysql2", // (untested) Error: Cannot find module './connect-connector-with-iam-authn.js'
"cloud-sql/postgres/knex", // (untested) CloudSQLConnectorError: Malformed instance connection name provided: expected format of "PROJECT:REGION:INSTANCE", got undefined
"cloud-sql/sqlserver/mssql", // (untested) TypeError: The "config.server" property is required and must be of type string.
Expand Down
95 changes: 95 additions & 0 deletions .github/workflows/utils/sql-proxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash -ex

# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Shared Cloud SQL Proxy setup
# Presumes the following variables in ci-setup.json:
# * CLOUD_SQL_CONNECTION_NAME - the project:region:instance of a Cloud SQL instance.
# * UNIX_SOCKET_DIR - a local directory to set the proxy to (default tmp/cloudsql)
#
# Note: in GitHub Actions environments, `/cloudsql` is not valid.
# Ensure any INSTANCE_UNIX_SOCKET value is ~= $UNIX_SOCKET_DIR/$CLOUD_SQL_CONNECTION_NAME

usage() {
cat << EOF
# Usage:
# CLOUD_SQL_CONNECTION_NAME=project:region:instance sql-proxy.sh [..]
#
# Defaults to TCP socket proxy. Set `SOCKET=unix` for Unix sockets.
#
# Usage in package.json:
#
# "proxy": "$GITHUB_WORKSPACE/.github/workflows/utils/sql-proxy.sh",
# "system-test": "npm run proxy -- c8 mocha test/... ",
# "system-test-unix": "SOCKET=unix npm run proxy -- c8 mocha test/... ",
EOF
}


PROXY_VERSION="v2.15.1"
SOCKET=${SOCKET:-tcp}

echop(){ # Print Echo
echo "👾 $1"
}

exit_message() { # Error Echo
echo "❌ $1"
usage
exit 1
}

if [[ -z "$CLOUD_SQL_CONNECTION_NAME" ]]; then
exit_message "Must provide CLOUD_SQL_CONNECTION_NAME"
fi

if [[ $SOCKET == "unix" ]]; then
UNIX_SOCKET_DIR=${UNIX_SOCKET_DIR:-"tmp/cloudsql"}

if [[ $UNIX_SOCKET_DIR == "/cloudsql" ]]; then
exit_message "Cannot use /cloudsql in a GitHub Actions context"
fi

mkdir -p $UNIX_SOCKET_DIR && chmod 777 $UNIX_SOCKET_DIR
socket="--unix-socket $UNIX_SOCKET_DIR"
fi
echop "Setting up cloud-sql-proxy for $SOCKET socket connections"

# Download the Cloud SQL Auth Proxy (only once)
if [[ ! -f cloud-sql-proxy ]]; then
curl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/${PROXY_VERSION}/cloud-sql-proxy.linux.amd64
if [[ $? -ne 0 ]]; then
echo "Failed to download cloud-sql-proxy"
exit 1
fi
chmod +x cloud-sql-proxy
else
echo "cloud-sql-proxy already downloaded"
fi

# Setup proxy
./cloud-sql-proxy $socket $CLOUD_SQL_CONNECTION_NAME &
sleep 5
echop "Proxy ready for use"

# Run whatever command was passed to this script
$@ || STATUS=$?

# Cleanup
echop "Shutting down proxy process"
pkill -f "cloud-sql-proxy" || echo "cloud-sql-proxy process not found. Was it already stopped?"

# Fail if the tests failed
exit $STATUS
14 changes: 14 additions & 0 deletions cloud-sql/mysql/mysql/ci-setup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"env": {
"INSTANCE_HOST": "127.0.0.1",
"INSTANCE_CONNECTION_NAME": "nodejs-docs-samples-tests:us-central1:mysql-ci",
"UNIX_SOCKET_DIR": "tmp/cloudsql",
"CLOUD_SQL_CONNECTION_NAME": "$INSTANCE_CONNECTION_NAME",
"INSTANCE_UNIX_SOCKET": "$UNIX_SOCKET_DIR/$INSTANCE_CONNECTION_NAME",
"DB_NAME": "kokoro_ci",
"DB_USER": "kokoro_ci"
},
"secrets": {
"DB_PASS": "nodejs-docs-samples-tests/nodejs-docs-samples-sql-password"
}
}
5 changes: 3 additions & 2 deletions cloud-sql/mysql/mysql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
},
"scripts": {
"start": "node server/server.js",
"system-test": "c8 mocha -p -j 2 test/server.test.js --timeout=60000 --exit",
"system-test-unix": "c8 mocha -p -j 2 test/server-unix.test.js --timeout=60000 --exit",
"proxy": "$GITHUB_WORKSPACE/.github/workflows/utils/sql-proxy.sh",
"system-test": "npm run proxy -- c8 mocha -p -j 2 test/server.test.js --colors --timeout=60000 --exit",
"system-test-unix": "SOCKET=unix npm run proxy -- c8 mocha -p -j 2 test/server-unix.test.js --colors --timeout=60000 --exit",
"test": "npm run system-test && npm run system-test-unix"
},
"dependencies": {
Expand Down
Loading