Skip to content

Commit 927231d

Browse files
use chat GPT to fix the problem?
1 parent e9fadc8 commit 927231d

File tree

1 file changed

+60
-36
lines changed

1 file changed

+60
-36
lines changed

action.yml

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,78 @@ inputs:
99
creds:
1010
description: "Contents of a Service Account JSON Key"
1111
required: true
12-
instance:
13-
description: "CloudSQL instance"
12+
instances:
13+
description: "CloudSQL instances (comma-separated)"
1414
required: true
15-
port:
16-
description: "Listen on port"
15+
ports:
16+
description: "Listen ports (comma-separated)"
1717
required: false
18-
default: 5432
18+
default: "5432"
1919
proxy_version:
2020
description: "CloudSQL Proxy Version"
2121
required: false
22-
default: 1.21.0
22+
default: "1.21.0"
2323

2424
runs:
2525
using: "composite"
2626
steps:
2727
- name: Start Google Cloud SQL Proxy
28+
id: proxy
2829
shell: bash
2930
run: |
30-
# write google application credentials to a temporary file to be used inside the container
31-
TMPDIR=$(mktemp -d)
32-
echo '${{ inputs.creds }}' > $TMPDIR/key.json
33-
34-
# start container
35-
CONTAINER=$(docker run -d --net host --restart on-failure \
36-
-v $TMPDIR:/tmp/gce-cloudsql-proxy \
37-
gcr.io/cloudsql-docker/gce-proxy:${{ inputs.proxy_version }} \
38-
/cloud_sql_proxy \
39-
-credential_file $TMPDIR/key.json \
40-
-dir /tmp \
41-
-instances=${{ inputs.instance }}=tcp:127.0.0.1:${{ inputs.port }})
42-
43-
# wait until connections are accepted
44-
sleep 3
45-
isready=0
46-
for i in {1..10}; do
47-
echo "Wait for connections to be ready ... $i/10"
48-
(${{ github.action_path }}/wait-for-it.sh --quiet --timeout=3 --host=127.0.0.1 --port=${{ inputs.port }} || exit $?) && true # escape bash's pipefail
49-
isready=$?
50-
if [[ $isready -eq 0 ]]; then
51-
break
52-
fi
53-
sleep 2
54-
done
31+
instances=(${{ inputs.instances }})
32+
ports=(${{ inputs.ports }})
33+
proxy_version="${{ inputs.proxy_version }}"
5534
56-
# print container logs
57-
docker logs $CONTAINER
35+
# Split comma-separated inputs into arrays
36+
IFS=',' read -ra instances <<< "$instances"
37+
IFS=',' read -ra ports <<< "$ports"
5838
59-
# exit with error code if we couldn't connect
60-
if [[ $isready -ne 0 ]]; then
61-
exit $isready
39+
# Check if the number of instances and ports match
40+
if [[ ${#instances[@]} -ne ${#ports[@]} ]]; then
41+
echo "Error: Number of instances and ports should match."
42+
exit 1
6243
fi
44+
45+
# Start Google Cloud SQL Proxy for each instance
46+
for i in "${!instances[@]}"; do
47+
instance="${instances[$i]}"
48+
port="${ports[$i]}"
49+
50+
# write google application credentials to a temporary file to be used inside the container
51+
mkdir -p /tmp/gce-cloudsql-proxy-$i
52+
echo '${{ inputs.creds }}' > /tmp/gce-cloudsql-proxy-$i/key.json
53+
54+
# start container
55+
docker run -d --net host --name gce-cloudsql-proxy-$i --restart on-failure \
56+
-v /tmp/gce-cloudsql-proxy-$i:/tmp/gce-cloudsql-proxy \
57+
gcr.io/cloudsql-docker/gce-proxy:$proxy_version \
58+
/cloud_sql_proxy \
59+
-credential_file /tmp/gce-cloudsql-proxy-$i/key.json \
60+
-dir /tmp \
61+
-instances=$instance=tcp:127.0.0.1:$port
62+
63+
# wait until connections are accepted
64+
sleep 3
65+
isready=0
66+
for j in {1..10}; do
67+
echo "Wait for connections to be ready for instance $instance on port $port ... $j/10"
68+
(${{ github.action_path }}/wait-for-it.sh --quiet --timeout=3 --host=127.0.0.1 --port=$port || exit $?) && true # escape bash's pipefail
69+
isready=$?
70+
if [[ $isready -eq 0 ]]; then
71+
break
72+
fi
73+
sleep 2
74+
done
75+
76+
# print container logs
77+
docker logs gce-cloudsql-proxy-$i
78+
79+
# exit with error code if we couldn't connect
80+
if [[ $isready -ne 0 ]]; then
81+
exit $isready
82+
fi
83+
done
84+
85+
# Set the output to be used by subsequent steps
86+
echo "::set-output name=proxy_ids::$(docker ps -aq --filter 'name=gce-cloudsql-proxy-'*)"

0 commit comments

Comments
 (0)