Skip to content

Commit af96ff7

Browse files
committed
fix: quickstart env variables
1 parent 8c7fb15 commit af96ff7

File tree

2 files changed

+192
-22
lines changed

2 files changed

+192
-22
lines changed

ci/kokoro/windows/builds/bazel.ps1

Lines changed: 88 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,32 +62,104 @@ if ($LastExitCode) {
6262
. ci/kokoro/windows/lib/integration.ps1
6363

6464
function Invoke-REST-Quickstart {
65-
bazelisk $common_flags run $build_flags `
66-
//google/cloud/storage/quickstart:quickstart -- `
67-
"${env:GOOGLE_CLOUD_CPP_STORAGE_TEST_BUCKET_NAME}"
68-
if ($LastExitCode) {
69-
Write-Host -ForegroundColor Red "bazel run (storage/quickstart) failed with exit code ${LastExitCode}."
70-
Exit ${LastExitCode}
65+
param($bazel_bin)
66+
try {
67+
$executable = Join-Path $bazel_bin "google/cloud/storage/quickstart/quickstart.exe"
68+
Write-Host "Running REST Quickstart, attempting to run: $executable"
69+
if (-not (Test-Path $executable)) {
70+
Write-Host -ForegroundColor Red "Executable not found at the specified path."
71+
Exit 1
72+
}
73+
& $executable "${env:GOOGLE_CLOUD_CPP_STORAGE_TEST_BUCKET_NAME}"
74+
if ($LastExitCode) {
75+
Write-Host -ForegroundColor Red "Execution of (storage/quickstart) failed with exit code ${LastExitCode}."
76+
Exit ${LastExitCode}
77+
}
78+
} catch {
79+
Write-Host -ForegroundColor Red "Caught exception while trying to run storage/quickstart: $_"
80+
Exit 1
7181
}
7282
}
7383

7484
function Invoke-gRPC-Quickstart {
75-
bazelisk $common_flags run $build_flags `
76-
//google/cloud/pubsub/quickstart:quickstart -- `
77-
"${env:GOOGLE_CLOUD_PROJECT}" "${env:GOOGLE_CLOUD_CPP_PUBSUB_TEST_QUICKSTART_TOPIC}"
78-
if ($LastExitCode) {
79-
Write-Host -ForegroundColor Red "bazel run (pubsub/quickstart) failed with exit code ${LastExitCode}."
80-
Exit ${LastExitCode}
85+
param($bazel_bin)
86+
try {
87+
$executable = Join-Path $bazel_bin "google/cloud/pubsub/quickstart/quickstart.exe"
88+
Write-Host "Running gRPC Quickstart, attempting to run: $executable"
89+
if (-not (Test-Path $executable)) {
90+
Write-Host -ForegroundColor Red "Executable not found at the specified path."
91+
Exit 1
92+
}
93+
& $executable "${env:GOOGLE_CLOUD_PROJECT}" "${env:GOOGLE_CLOUD_CPP_PUBSUB_TEST_QUICKSTART_TOPIC}"
94+
if ($LastExitCode) {
95+
Write-Host -ForegroundColor Red "Execution of (pubsub/quickstart) failed with exit code ${LastExitCode}."
96+
Exit ${LastExitCode}
97+
}
98+
} catch {
99+
Write-Host -ForegroundColor Red "Caught exception while trying to run pubsub/quickstart: $_"
100+
Exit 1
81101
}
82102
}
83103

84104
if (Test-Integration-Enabled) {
85105
Write-Host "`n$(Get-Date -Format o) Running minimal quickstart prorams"
106+
107+
# 1. Install the certificates
86108
Install-Roots-Pem
87-
${env:GRPC_DEFAULT_SSL_ROOTS_FILE_PATH}="${env:KOKORO_GFILE_DIR}/roots.pem"
88-
${env:GOOGLE_APPLICATION_CREDENTIALS}="${env:KOKORO_GFILE_DIR}/kokoro-run-key.json"
89-
Invoke-REST-Quickstart
90-
Invoke-gRPC-Quickstart
109+
110+
# 2. Normalize paths to use Forward Slashes (/)
111+
# This is the critical fix for C++ libcurl on Windows
112+
$RawRootsPath = Join-Path $env:KOKORO_GFILE_DIR "roots.pem"
113+
$RootsPath = $RawRootsPath -replace '\\', '/'
114+
115+
$RawKeyPath = Join-Path $env:KOKORO_GFILE_DIR "kokoro-run-key.json"
116+
$KeyPath = $RawKeyPath -replace '\\', '/'
117+
118+
# 3. Set the Environment Variables
119+
$env:GRPC_DEFAULT_SSL_ROOTS_FILE_PATH = $RootsPath
120+
$env:CURL_CA_BUNDLE = $RootsPath
121+
$env:GOOGLE_APPLICATION_CREDENTIALS = $KeyPath
122+
123+
# 4. Enable Deep Library Logging (The "Kitchen Sink")
124+
# 'http' traces headers/handshakes.
125+
# CURL_VERBOSE=1 forces libcurl to print to stderr.
126+
$env:GOOGLE_CLOUD_CPP_ENABLE_TRACING="http"
127+
$env:CURL_VERBOSE="1"
128+
129+
# --- DEBUGGING OUTPUT START ---
130+
Write-Host -ForegroundColor Cyan "`n--- DEBUG: Environment & File Check ---"
131+
132+
Write-Host "1. Path Normalization Check:"
133+
Write-Host " Original: $RawRootsPath"
134+
Write-Host " Forward : $RootsPath"
135+
136+
Write-Host "`n2. File Accessibility Check (using Forward Slash path):"
137+
if (Test-Path $RootsPath) {
138+
Write-Host -ForegroundColor Green " [OK] PowerShell can read '$RootsPath'"
139+
Get-Item $RootsPath | Select-Object FullName, Length, LastWriteTime | Format-Table -AutoSize | Out-Host
140+
} else {
141+
Write-Host -ForegroundColor Red " [FAIL] PowerShell CANNOT find '$RootsPath'"
142+
}
143+
144+
Write-Host "`n3. Active Environment Variables for Test Process:"
145+
Get-ChildItem Env: | Where-Object {
146+
$_.Name -match 'CURL_|GOOGLE_|GRPC_'
147+
} | Format-Table -AutoSize | Out-Host
148+
149+
Write-Host "--- DEBUG END ---`n"
150+
# --- DEBUGGING OUTPUT END ---
151+
152+
bazelisk $common_flags build $build_flags `
153+
//google/cloud/storage/quickstart:quickstart `
154+
//google/cloud/pubsub/quickstart:quickstart
155+
156+
$bazel_bin = (bazelisk $common_flags info $build_flags bazel-bin).Trim()
157+
# Fix bazel-bin path for PowerShell invocation just in case
158+
$bazel_bin = $bazel_bin.Replace('/', '\')
159+
Write-Host "bazel-bin directory: $bazel_bin"
160+
161+
Invoke-REST-Quickstart $bazel_bin
162+
Invoke-gRPC-Quickstart $bazel_bin
91163
}
92164

93165
# Shutdown the Bazel server to release any locks

ci/kokoro/windows/lib/integration.ps1

Lines changed: 104 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,127 @@
1414

1515
# Helper functions to run the minimal integration tests
1616

17-
$PROJECT_ROOT = (Get-Item -Path ".\" -Verbose).FullName
17+
$PROJECT_ROOT = (Get-Item -Path ".\").FullName
1818
$integration_tests_config="${PROJECT_ROOT}/ci/etc/integration-tests-config.ps1"
1919
. "${integration_tests_config}"
2020

2121
function Test-Integration-Enabled {
2222
if ((Test-Path env:KOKORO_GFILE_DIR) -and
2323
(Test-Path "${env:KOKORO_GFILE_DIR}/kokoro-run-key.json")) {
24-
return $True
24+
return $True
2525
}
2626
return $False
2727
}
2828

29+
function Debug-Network {
30+
param([string]$targetUrl)
31+
Write-Host -ForegroundColor Cyan "`n--- NETWORK DEBUG START ($targetUrl) ---"
32+
try {
33+
$uri = New-Object System.Uri($targetUrl)
34+
$hostName = $uri.DnsSafeHost
35+
36+
# 1. DNS Resolution
37+
Write-Host "1. Testing DNS resolution for $hostName..."
38+
$dns = Resolve-DnsName -Name $hostName -ErrorAction SilentlyContinue
39+
if ($dns) { $dns | Format-Table -AutoSize | Out-Host } else { Write-Host -ForegroundColor Red "DNS Resolution FAILED" }
40+
41+
# 2. Basic TCP Connectivity (checking port 443)
42+
Write-Host "`n2. Testing TCP connectivity to $hostName`:443..."
43+
try {
44+
$tcp = Test-NetConnection -ComputerName $hostName -Port 443 -WarningAction SilentlyContinue
45+
if ($tcp.TcpTestSucceeded) { Write-Host "TCP connection SUCCEEDED" } else { Write-Host -ForegroundColor Red "TCP connection FAILED" }
46+
Write-Host "Detailed Info: $($tcp | Out-String)"
47+
} catch {
48+
Write-Host -ForegroundColor Red "Test-NetConnection failed to run: $_"
49+
}
50+
51+
# 3. Proxy Detection
52+
Write-Host "`n3. Checking System Proxy for $targetUrl..."
53+
$proxy = [System.Net.WebRequest]::GetSystemWebProxy()
54+
$proxyUri = $proxy.GetProxy($uri)
55+
Write-Host "Effective Proxy: $proxyUri"
56+
Write-Host "Is Bypassed: $($proxy.IsBypassed($uri))"
57+
58+
} catch {
59+
Write-Host -ForegroundColor Red "An error occurred during network debug: $_"
60+
}
61+
Write-Host -ForegroundColor Cyan "--- NETWORK DEBUG END ---`n"
62+
}
63+
2964
function Install-Roots-Pem {
30-
Write-Host -ForegroundColor Yellow "`n$(Get-Date -Format o) " `
31-
"Downloading roots.pem [$_]"
65+
Debug-Network -targetUrl "https://curl.se/ca/cacert.pem"
66+
3267
ForEach($attempt in (1, 2, 3)) {
68+
Write-Host -ForegroundColor Yellow "`n$(Get-Date -Format o) " `
69+
"Downloading roots.pem [$attempt]"
3370
try {
3471
(New-Object System.Net.WebClient).Downloadfile(
35-
'https://pki.google.com/roots.pem',
72+
'https://curl.se/ca/cacert.pem',
3673
"${env:KOKORO_GFILE_DIR}/roots.pem")
74+
75+
# --- CHANGE 1: Inspect both Root and Intermediate (CA) stores ---
76+
# Many corporate proxies operate via an Intermediate CA.
77+
$storesToCheck = @("Root", "CA")
78+
79+
Write-Host "Appending Windows System Certificates to roots.pem..."
80+
81+
foreach ($storeName in $storesToCheck) {
82+
Write-Host -ForegroundColor Cyan "Processing Store: LocalMachine\$storeName"
83+
$certStore = New-Object System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $storeName, "LocalMachine"
84+
$certStore.Open('ReadOnly')
85+
86+
$certStore.Certificates | ForEach-Object {
87+
$cert = $_
88+
# --- CHANGE 2: Log the Subject Name ---
89+
# This lets us verify if the corporate proxy cert is actually present.
90+
Write-Host " Adding: $($cert.Subject)"
91+
92+
$pem = "`r`n-----BEGIN CERTIFICATE-----`r`n" +
93+
[Convert]::ToBase64String($cert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert), 'InsertLineBreaks') +
94+
"`r`n-----END CERTIFICATE-----`r`n"
95+
Add-Content -Path "${env:KOKORO_GFILE_DIR}/roots.pem" -Value $pem -Encoding Ascii
96+
}
97+
$certStore.Close()
98+
}
99+
100+
# --- DEBUG START ---
101+
$pemPath = "${env:KOKORO_GFILE_DIR}/roots.pem"
102+
Write-Host -ForegroundColor Cyan "`nDEBUG: Inspecting roots.pem..."
103+
104+
$corruption = Select-String -Path $pemPath -Pattern "-----END CERTIFICATE----------BEGIN CERTIFICATE-----"
105+
if ($corruption) {
106+
Write-Host -ForegroundColor Red "FAIL: Found corrupted certificate boundaries (missing newline)!"
107+
} else {
108+
Write-Host -ForegroundColor Green "PASS: No certificate boundary corruption detected."
109+
}
110+
111+
Write-Host -ForegroundColor Cyan "`nDEBUG: Testing SSL connection to GCS..."
112+
113+
# Fix: Relax ErrorActionPreference so curl -v stderr doesn't crash the script
114+
$OldEAP = $ErrorActionPreference
115+
$ErrorActionPreference = "Continue"
116+
117+
try {
118+
& curl.exe --version
119+
& curl.exe -v https://storage.googleapis.com --cacert $pemPath 2>&1 | Out-Host
120+
if ($LastExitCode -ne 0) {
121+
Write-Host -ForegroundColor Red "Curl exited with error code: $LastExitCode"
122+
} else {
123+
Write-Host -ForegroundColor Green "Curl connection test PASSED."
124+
}
125+
} catch {
126+
Write-Host -ForegroundColor Red "Debug curl command failed unexpectedly: $_"
127+
} finally {
128+
$ErrorActionPreference = $OldEAP
129+
}
130+
# --- DEBUG END ---
131+
37132
return
38133
} catch {
39-
Write-Host -ForegroundColor Yellow "`n$(Get-Date -Format o) download error"
134+
Write-Host -ForegroundColor Yellow "`n$(Get-Date -Format o) download/setup error: $_"
135+
if ($attempt -eq 3) {
136+
Debug-Network -targetUrl "https://storage.googleapis.com"
137+
}
40138
}
41139
Start-Sleep -Seconds (60 * $attempt)
42140
}

0 commit comments

Comments
 (0)