This repository was archived by the owner on Mar 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathzb-system-tests-cloudbuild.yaml
More file actions
101 lines (90 loc) · 3.86 KB
/
zb-system-tests-cloudbuild.yaml
File metadata and controls
101 lines (90 loc) · 3.86 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
substitutions:
_REGION: "us-central1"
_ZONE: "us-central1-a"
_SHORT_BUILD_ID: ${BUILD_ID:0:8}
_VM_NAME: "py-sdk-sys-test-${_SHORT_BUILD_ID}"
_ULIMIT: "10000" # 10k, for gRPC bidi streams
steps:
# Step 0: Generate a persistent SSH key for this build run.
# This prevents gcloud from adding a new key to the OS Login profile on every ssh/scp command.
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "generate-ssh-key"
entrypoint: "bash"
args:
- "-c"
- |
mkdir -p /workspace/.ssh
# Generate the SSH key
ssh-keygen -t rsa -f /workspace/.ssh/google_compute_engine -N '' -C gcb
# Save the public key content to a file for the cleanup step
cat /workspace/.ssh/google_compute_engine.pub > /workspace/gcb_ssh_key.pub
waitFor: ["-"]
# Step 1 Create a GCE VM to run the tests.
# The VM is created in the same zone as the buckets to test rapid storage features.
# It's given the 'cloud-platform' scope to allow it to access GCS and other services.
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "create-vm"
entrypoint: "gcloud"
args:
- "compute"
- "instances"
- "create"
- "${_VM_NAME}"
- "--project=${PROJECT_ID}"
- "--zone=${_ZONE}"
- "--machine-type=e2-medium"
- "--image-family=debian-13"
- "--image-project=debian-cloud"
- "--service-account=${_ZONAL_VM_SERVICE_ACCOUNT}"
- "--scopes=https://www.googleapis.com/auth/devstorage.full_control,https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/devstorage.read_write"
- "--metadata=enable-oslogin=TRUE"
waitFor: ["-"]
# Step 2: Run the integration tests inside the newly created VM and cleanup.
# This step uses 'gcloud compute ssh' to execute a remote script.
# The VM is deleted after tests are run, regardless of success.
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "run-tests-and-delete-vm"
entrypoint: "bash"
args:
- "-c"
- |
set -e
# Wait for the VM to be fully initialized and SSH to be ready.
for i in {1..10}; do
if gcloud compute ssh ${_VM_NAME} --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine --command="echo VM is ready"; then
break
fi
echo "Waiting for VM to become available... (attempt $i/10)"
sleep 15
done
# copy the script to the VM
gcloud compute scp cloudbuild/run_zonal_tests.sh ${_VM_NAME}:~ --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine
# Execute the script on the VM via SSH.
# Capture the exit code to ensure cleanup happens before the build fails.
set +e
gcloud compute ssh ${_VM_NAME} --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine --command="ulimit -n {_ULIMIT}; COMMIT_SHA=${COMMIT_SHA} _ZONAL_BUCKET=${_ZONAL_BUCKET} CROSS_REGION_BUCKET=${_CROSS_REGION_BUCKET} _PR_NUMBER=${_PR_NUMBER} bash run_zonal_tests.sh"
EXIT_CODE=$?
set -e
echo "--- Deleting GCE VM ---"
gcloud compute instances delete "${_VM_NAME}" --zone=${_ZONE} --quiet
# Exit with the original exit code from the test script.
exit $$EXIT_CODE
waitFor:
- "create-vm"
- "generate-ssh-key"
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "cleanup-ssh-key"
entrypoint: "bash"
args:
- "-c"
- |
echo "--- Removing SSH key from OS Login profile to prevent accumulation ---"
gcloud compute os-login ssh-keys remove \
--key-file=/workspace/gcb_ssh_key.pub || true
waitFor:
- "run-tests-and-delete-vm"
timeout: "3600s" # 60 minutes
options:
logging: CLOUD_LOGGING_ONLY
pool:
name: "projects/${PROJECT_ID}/locations/us-central1/workerPools/cloud-build-worker-pool"