-
Notifications
You must be signed in to change notification settings - Fork 0
feat: enhance MySQL support and improve script logging #20
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,50 @@ | ||
| #!/usr/bin/env sh | ||
|
|
||
| if ! [ -x "$(command -v cloud_sql_proxy)" ]; then | ||
| echo "Error: cannot find the cloud_sql_proxy executable, please install it or add to your path." >&2 | ||
| set -eu | ||
|
|
||
| # shellcheck disable=SC3040 | ||
| if (set -o pipefail 2>/dev/null); then | ||
| set -o pipefail | ||
| fi | ||
|
|
||
| log() { | ||
| printf '[sql-proxy] %s\n' "${1}" | ||
| } | ||
|
|
||
| CLOUDSQL_PROXY_BIN="" | ||
| if command -v cloud_sql_proxy >/dev/null 2>&1; then | ||
| CLOUDSQL_PROXY_BIN="cloud_sql_proxy" | ||
| else | ||
| log "Error: cannot find the Cloud SQL Auth Proxy executable cloud_sql_proxy. Please install it or add it to your PATH." >&2 | ||
| exit 1 | ||
| elif ! [ -x "$(command -v nc)" ]; then | ||
| echo "Error: Netcat is not installed." >&2 | ||
| fi | ||
|
|
||
| if ! command -v nc >/dev/null 2>&1; then | ||
| log "Error: Netcat is not installed." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| SERVICE="cloud_sql_proxy" | ||
| CONNECTION_NAME="${CLOUDSDK_CORE_PROJECT}:${GCLOUD_PROJECT_REGION}:${CLOUDSQL_INSTANCE_NAME}" | ||
|
|
||
| if ! pgrep -x "$SERVICE" >/dev/null | ||
| then | ||
| exec cloud_sql_proxy -instances="${CLOUDSDK_CORE_PROJECT}:${GCLOUD_PROJECT_REGION}:${CLOUDSQL_INSTANCE_NAME}"="tcp:0.0.0.0:${CLOUDSQL_PROXY_PORT}" /dev/null 2>&1 & | ||
| if ! pgrep -x "$CLOUDSQL_PROXY_BIN" >/dev/null; then | ||
| log "Starting Cloud SQL Auth Proxy (${CLOUDSQL_PROXY_BIN}) for ${CONNECTION_NAME} on localhost:${CLOUDSQL_PROXY_PORT}." | ||
| "${CLOUDSQL_PROXY_BIN}" "${CONNECTION_NAME}" --port "${CLOUDSQL_PROXY_PORT}" >/dev/null 2>&1 & | ||
| sleep 1s | ||
| else | ||
| log "Cloud SQL Auth Proxy already running; skipping start." | ||
| fi | ||
|
|
||
| for j in $(seq 1 10); do | ||
| READY=$(sh -c 'nc -v ${CLOUDSQL_PROXY_HOST} ${CLOUDSQL_PROXY_PORT} </dev/null; echo $?;' 2>/dev/null) | ||
| if [ "$READY" -eq 0 ]; then | ||
| echo "Connection with with CloudSQL Auth Proxy established at ${CLOUDSQL_PROXY_HOST}." | ||
| log "Connection with Cloud SQL Auth Proxy established at ${CLOUDSQL_PROXY_HOST}:${CLOUDSQL_PROXY_PORT}." | ||
filippolmt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| break | ||
| fi | ||
| echo "Waiting for Cloud SQL Proxy to start... $j" | ||
| log "Waiting for Cloud SQL Proxy to start (attempt ${j}/10)..." | ||
| sleep 1s | ||
| done | ||
|
|
||
| if [ "$READY" -eq 1 ]; then | ||
| echo "ERROR: cannot connect to the CloudSQL Auth Proxy at ${CLOUDSQL_PROXY_HOST}, please check your settings." | ||
| if [ "$READY" -ne 0 ]; then | ||
| log "ERROR: cannot connect to the Cloud SQL Auth Proxy at ${CLOUDSQL_PROXY_HOST}:${CLOUDSQL_PROXY_PORT}, please check your settings." >&2 | ||
| exit 1 | ||
| fi | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.