-
Notifications
You must be signed in to change notification settings - Fork 43
/
action.yml
62 lines (55 loc) · 1.82 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
54
55
56
57
58
59
60
61
62
name: "Google Cloud SQL Proxy"
description: "Start Google CloudSQL Proxy"
branding:
icon: "database"
color: "red"
inputs:
creds:
description: "Contents of a Service Account JSON Key"
required: true
instance:
description: "CloudSQL instance"
required: true
port:
description: "Listen on port"
required: false
default: 5432
proxy_version:
description: "CloudSQL Proxy Version"
required: false
default: 1.21.0
runs:
using: "composite"
steps:
- name: Start Google Cloud SQL Proxy
shell: bash
run: |
# write google application credentials to a temporary file to be used inside the container
mkdir -p /tmp/gce-cloudsql-proxy
echo '${{ inputs.creds }}' > /tmp/gce-cloudsql-proxy/key.json
# start container
docker run -d --net host --name gce-cloudsql-proxy --restart on-failure \
-v /tmp/gce-cloudsql-proxy:/tmp/gce-cloudsql-proxy \
gcr.io/cloudsql-docker/gce-proxy:${{ inputs.proxy_version }} \
/cloud_sql_proxy \
-credential_file /tmp/gce-cloudsql-proxy/key.json \
-dir /tmp \
-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
# print container logs
docker logs gce-cloudsql-proxy
# exit with error code if we couldn't connect
if [[ $isready -ne 0 ]]; then
exit $isready
fi