|
14 | 14 | # See the License for the specific language governing permissions and |
15 | 15 | # limitations under the License. |
16 | 16 |
|
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 ...`) |
18 | 26 |
|
19 | 27 | PROXY_VERSION="v2.15.1" |
20 | 28 |
|
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 |
22 | 32 | do |
23 | 33 | case "${flag}" in |
24 | | - c) SETUP_STYLE=${1:-tcp};; |
| 34 | + s) SETUP_STYLE="socket";; |
25 | 35 | esac |
26 | 36 | done |
27 | 37 |
|
28 | 38 | if [[ ! $SETUP_STYLE == "tcp" ]]; then |
29 | | - echo "setup for sockets" |
30 | 39 | mkdir -p $UNIX_SOCKET_DIR && chmod 777 $UNIX_SOCKET_DIR |
31 | 40 | socket="--unix-socket $UNIX_SOCKET_DIR" |
32 | 41 | fi |
33 | | - |
34 | 42 | echo "Setting up cloud-sql-proxy for $SETUP_STYLE connections" |
35 | 43 |
|
| 44 | +# Download the Cloud SQL Auth Proxy (only once) |
36 | 45 | if [[ ! -f cloud-sql-proxy ]]; then |
37 | | - |
38 | 46 | curl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/${PROXY_VERSION}/cloud-sql-proxy.linux.amd64 |
39 | 47 | if [[ $? -ne 0 ]]; then |
40 | 48 | echo "Failed to download cloud-sql-proxy" |
|
45 | 53 | echo "cloud-sql-proxy already downloaded" |
46 | 54 | fi |
47 | 55 |
|
| 56 | +# Setup proxy |
48 | 57 | ./cloud-sql-proxy $socket $CLOUD_SQL_CONNECTION_NAME & |
49 | 58 | sleep 10 |
50 | 59 |
|
51 | 60 | echo "Proxy ready for use" |
52 | 61 |
|
53 | | -# Run test |
| 62 | +# Run whatever command was passed to this script |
54 | 63 | $@ || STATUS=$? |
55 | 64 |
|
56 | | - |
| 65 | +# Cleanup |
57 | 66 | echo "Shutting down proxy process" |
58 | | - |
59 | 67 | pkill -f "cloud-sql-proxy" || echo "cloud-sql-proxy process not found. Was it already stopped?" |
60 | 68 |
|
61 | 69 | # Fail if the tests failed |
|
0 commit comments