forked from mattes/gce-cloudsql-proxy-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
70 lines (62 loc) · 2.17 KB
/
action.yml
File metadata and controls
70 lines (62 loc) · 2.17 KB
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
63
64
65
66
67
68
69
70
# Forked version of @mattes's gce-cloudsql-proxy-action (https://github.com/mattes/gce-cloudsql-proxy-action)
# to support Cloud SQL Auth proxy v2 & add a few small
name: "CloudSQL Proxy for Github Actions"
description: "Use the CloudSQL Proxy with your Github Actions"
branding:
icon: "database"
color: "purple"
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: 2.20.0
startup_attempts:
description: "Number of attempts to wait for the proxy to start"
required: false
default: 10
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/cloudsql-proxy
echo '${{ inputs.creds }}' > /tmp/cloudsql-proxy/key.json
# start container
docker run -d --net host --name cloudsql-proxy --restart on-failure \
-v /tmp/cloudsql-proxy:/tmp/cloudsql-proxy \
gcr.io/cloud-sql-connectors/cloud-sql-proxy:${{ inputs.proxy_version }} \
--credentials-file /tmp/cloudsql-proxy/key.json \
--address 127.0.0.1 \
--port ${{ inputs.port }} \
${{ inputs.instance }}
# wait until connections are accepted
sleep 3
isReady=0
maxAttempts=${{ inputs.startup_attempts }}
for i in $(seq 1 $maxAttempts); do
echo "Wait for connections to be ready ... $i/$maxAttempts"
(${{ 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 cloudsql-proxy
# exit with error code if we couldn't connect
if [[ $isReady -ne 0 ]]; then
exit $isReady
fi