Skip to content

Commit abf0e9c

Browse files
committed
chore: initial commit with sample cloudbuild file
1 parent fb8c21c commit abf0e9c

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

private.cloudbuild.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Ping Instance
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
schedule:
9+
- cron: "0 2 * * *"
10+
11+
permissions:
12+
contents: read
13+
id-token: write # required for secret manager
14+
15+
jobs:
16+
ping_instance:
17+
name: Ping Instance
18+
runs-on: ubuntu-latest
19+
env:
20+
PROJECT_ID: ${{ vars.GOOGLE_CLOUD_PROJECT }}
21+
IP_ADDRESS: ${{ vars.IP_ADDRESS }} # Required IP address
22+
DATABASE_PORT: 3306 # Or your database port
23+
24+
steps:
25+
- id: auth
26+
name: Authenticate to Google Cloud
27+
uses: google-github-actions/auth@71f986410dfbc7added4569d411d040a91dc6935 # v2.1.8
28+
with:
29+
workload_identity_provider: ${{ vars.PROVIDER_NAME }}
30+
service_account: ${{ vars.SERVICE_ACCOUNT }}
31+
access_token_lifetime: 600s
32+
33+
- id: secrets
34+
name: Get secrets
35+
uses: google-github-actions/get-secretmanager-secrets@a8440875e1c2892062aef9061228d4f1af8f919b # v2.2.3
36+
with:
37+
secrets: |-
38+
MYSQL_CONNECTION_NAME:${{ vars.GOOGLE_CLOUD_PROJECT }}/MYSQL_CONNECTION_NAME
39+
40+
- name: Download Cloud SQL Proxy
41+
run: |
42+
wget -O cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.13.0/cloud-sql-proxy.linux.amd64
43+
chmod +x cloud-sql-proxy
44+
45+
- name: Ping Instance
46+
run: |
47+
./cloud-sql-proxy "${{ steps.secrets.outputs.MYSQL_CONNECTION_NAME }}" --port "${{ env.DATABASE_PORT }}" &
48+
sleep 5
49+
nc -zv "${{ env.IP_ADDRESS }}" "${{ env.DATABASE_PORT }}"
50+
if [ $? -eq 0 ]; then
51+
echo "Successfully pinged the instance!"
52+
else
53+
echo "Failed to ping the instance."
54+
exit 1
55+
fi

0 commit comments

Comments
 (0)