forked from wagnerpereira/gce-cloudsql-proxy-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
53 lines (47 loc) · 1.54 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
name: 'Google Cloud SQL Proxy with workload identity'
description: 'Start Google CloudSQL Proxy using Google Workload Identity Federation short-lived credentials'
branding:
icon: 'database'
color: 'red'
inputs:
creds:
description: 'Contents of a short-lived GOOGLE_APPLICATION_CREDENTIALS environment variable'
required: false
instance:
description: 'CloudSQL instance'
required: true
port:
description: 'Listen on port'
required: false
default: 5432
proxy_version:
description: 'CloudSQL Proxy Version'
required: false
default: v1.29.0
runs:
using: 'composite'
steps:
- name: Start Google Cloud SQL Proxy
shell: bash
run: |
# Download Linux binary
wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy
chmod +x cloud_sql_proxy
# Start Cloud SQL Proxy
./cloud_sql_proxy -instances=${{ inputs.instance }}=tcp:127.0.0.1:${{ inputs.port }} &
# wait until connections are accepted
sleep 3
isready=0
for i in {1..10}; do
echo "Wait for connections to be ready ... $i/10"
(${{ github.action_path }}/wait-for-it.sh --quiet --timeout=3 --host=127.0.0.1 --port=${{ inputs.port }} || exit $?) && true # escape bash's pipefail
isready=$?
if [[ $isready -eq 0 ]]; then
break
fi
sleep 2
done
# exit with error code if we couldn't connect
if [[ $isready -ne 0 ]]; then
exit $isready
fi