Skip to content

Commit 24bd715

Browse files
committed
simplify usage
1 parent a62e1bf commit 24bd715

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

.github/workflows/utils/sql-proxy.sh

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,35 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
# Proof of concept: setting up proxy
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+
#
21+
# Usage:
22+
# sql-proxy.sh [..] - sets up a TCP proxy
23+
# sql-proxy.sh -s [..] - sets up a Unix socket proxy
24+
#
25+
# Any [..] commands are run directly (e.g. `c8 mocha ...`)
1826

1927
PROXY_VERSION="v2.15.1"
2028

21-
while getopts c: flag
29+
# If no `-s` flag is set, use tcp connection style.
30+
SETUP_STYLE="tcp"
31+
while getopts s: flag
2232
do
2333
case "${flag}" in
24-
c) SETUP_STYLE=${1:-tcp};;
34+
s) SETUP_STYLE="socket";;
2535
esac
2636
done
2737

2838
if [[ ! $SETUP_STYLE == "tcp" ]]; then
29-
echo "setup for sockets"
3039
mkdir -p $UNIX_SOCKET_DIR && chmod 777 $UNIX_SOCKET_DIR
3140
socket="--unix-socket $UNIX_SOCKET_DIR"
3241
fi
33-
3442
echo "Setting up cloud-sql-proxy for $SETUP_STYLE connections"
3543

44+
# Download the Cloud SQL Auth Proxy (only once)
3645
if [[ ! -f cloud-sql-proxy ]]; then
37-
3846
curl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/${PROXY_VERSION}/cloud-sql-proxy.linux.amd64
3947
if [[ $? -ne 0 ]]; then
4048
echo "Failed to download cloud-sql-proxy"
@@ -45,17 +53,17 @@ else
4553
echo "cloud-sql-proxy already downloaded"
4654
fi
4755

56+
# Setup proxy
4857
./cloud-sql-proxy $socket $CLOUD_SQL_CONNECTION_NAME &
4958
sleep 10
5059

5160
echo "Proxy ready for use"
5261

53-
# Run test
62+
# Run whatever command was passed to this script
5463
$@ || STATUS=$?
5564

56-
65+
# Cleanup
5766
echo "Shutting down proxy process"
58-
5967
pkill -f "cloud-sql-proxy" || echo "cloud-sql-proxy process not found. Was it already stopped?"
6068

6169
# Fail if the tests failed

cloud-sql/mysql/mysql/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"start": "node server/server.js",
1616
"proxy": "bash $GITHUB_WORKSPACE/.github/workflows/utils/sql-proxy.sh",
1717
"system-test": "npm run proxy -- c8 mocha -p -j 2 test/server.test.js --timeout=60000 --exit",
18-
"system-test-unix": "npm run proxy -c socket -- c8 mocha -p -j 2 test/server-unix.test.js --timeout=60000 --exit",
18+
"system-test-unix": "npm run proxy -s -- c8 mocha -p -j 2 test/server-unix.test.js --timeout=60000 --exit",
1919
"test": "npm run system-test && npm run system-test-unix"
2020
},
2121
"dependencies": {

0 commit comments

Comments
 (0)