Skip to content

Commit f2f9eab

Browse files
authored
Supported running cleanup job on GCP (#719)
ref https://linear.app/ghost/issue/PROD-685 Connecting to CloudSQL isn't done in the usual way, we need to use the unix socket which is mounted automatically for Cloud Run Jobs at /cloudsql/<instance-name>
1 parent cbf2d76 commit f2f9eab

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
#!/bin/sh
22
set -e
33

4-
mysql \
5-
--host="$MYSQL_HOST" \
6-
--port="$MYSQL_PORT" \
7-
--user="$MYSQL_USER" \
8-
--password="$MYSQL_PASSWORD" \
9-
--database="$MYSQL_DATABASE" \
10-
-e "DELETE FROM key_value WHERE expires IS NOT NULL AND expires < UTC_TIMESTAMP();"
4+
PORT=${MYSQL_PORT:-3306}
5+
6+
if [ -n "$MYSQL_SOCKET_PATH" ]; then
7+
echo "Using Unix socket for $MYSQL_SOCKET_PATH"
8+
SOCKET="--socket=$MYSQL_SOCKET_PATH"
9+
HOSTPORT=""
10+
else
11+
echo "Using TCP host $MYSQL_HOST:$PORT"
12+
SOCKET=""
13+
HOSTPORT="--host=$MYSQL_HOST --port=$PORT"
14+
fi
15+
16+
mysql $SOCKET $HOSTPORT -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" -e \
17+
"DELETE FROM key_value WHERE expires IS NOT NULL AND expires < UTC_TIMESTAMP();"

0 commit comments

Comments
 (0)