Skip to content

Commit e7cb46d

Browse files
committed
Add Depot GHA runner detection with private IP support
- Detect Depot runners by checking for agentd binary - Request private IPs when running on Depot infrastructure - Add debug logging with DEPOT_DEBUG_DETECTION env var - Add comprehensive test workflow for all platforms
1 parent 96c7261 commit e7cb46d

File tree

7 files changed

+869
-422
lines changed

7 files changed

+869
-422
lines changed
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
name: Test Depot Detection
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ test-depot-detection ]
7+
8+
jobs:
9+
# Test on Depot runners
10+
test-depot-ubuntu:
11+
runs-on: depot-ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- uses: actions/setup-go@v5
16+
with:
17+
go-version: '1.21'
18+
19+
- name: Test on Depot Ubuntu
20+
run: |
21+
echo "=== DEPOT UBUNTU RUNNER TEST ==="
22+
echo "Hostname: $(hostname)"
23+
24+
# Build CLI
25+
go build -o depot-test ./cmd/depot
26+
27+
# Run with debug
28+
export DEPOT_DEBUG_DETECTION=1
29+
echo -e "\n--- Running depot version ---"
30+
./depot-test version || true
31+
32+
# Check for agentd manually
33+
echo -e "\n--- Manual agentd check ---"
34+
ls -la /usr/local/bin/agentd || echo "agentd not found"
35+
36+
test-depot-windows:
37+
runs-on: depot-windows-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- uses: actions/setup-go@v5
42+
with:
43+
go-version: '1.21'
44+
45+
- name: Test on Depot Windows
46+
shell: bash
47+
run: |
48+
echo "=== DEPOT WINDOWS RUNNER TEST ==="
49+
echo "Hostname: $(hostname)"
50+
51+
# Build CLI
52+
go build -o depot-test.exe ./cmd/depot
53+
54+
# Run with debug
55+
export DEPOT_DEBUG_DETECTION=1
56+
echo -e "\n--- Running depot version ---"
57+
./depot-test.exe version || true
58+
59+
- name: Check for agentd (PowerShell)
60+
shell: powershell
61+
run: |
62+
Write-Host "`n--- Manual agentd check ---"
63+
$paths = @(
64+
"C:\Program Files\Depot\agentd.exe",
65+
"C:\ProgramData\Depot\agentd.exe",
66+
"C:\usr\local\bin\agentd.exe"
67+
)
68+
foreach ($path in $paths) {
69+
if (Test-Path $path) {
70+
Write-Host "Found: $path"
71+
} else {
72+
Write-Host "Not found: $path"
73+
}
74+
}
75+
76+
test-depot-macos:
77+
runs-on: depot-macos-latest
78+
steps:
79+
- uses: actions/checkout@v4
80+
81+
- uses: actions/setup-go@v5
82+
with:
83+
go-version: '1.21'
84+
85+
- name: Test on Depot macOS
86+
run: |
87+
echo "=== DEPOT MACOS RUNNER TEST ==="
88+
echo "Hostname: $(hostname)"
89+
90+
# Build CLI
91+
go build -o depot-test ./cmd/depot
92+
93+
# Run with debug
94+
export DEPOT_DEBUG_DETECTION=1
95+
echo -e "\n--- Running depot version ---"
96+
./depot-test version || true
97+
98+
# Check for agentd manually
99+
echo -e "\n--- Manual agentd check ---"
100+
ls -la /usr/local/bin/agentd || echo "agentd not found"
101+
102+
# Test on GitHub runners
103+
test-github-ubuntu:
104+
runs-on: ubuntu-latest
105+
steps:
106+
- uses: actions/checkout@v4
107+
108+
- uses: actions/setup-go@v5
109+
with:
110+
go-version: '1.21'
111+
112+
- name: Test on GitHub Ubuntu
113+
run: |
114+
echo "=== GITHUB UBUNTU RUNNER TEST ==="
115+
echo "Hostname: $(hostname)"
116+
117+
# Build CLI
118+
go build -o depot-test ./cmd/depot
119+
120+
# Run with debug
121+
export DEPOT_DEBUG_DETECTION=1
122+
echo -e "\n--- Running depot version ---"
123+
./depot-test version || true
124+
125+
# Check for agentd manually
126+
echo -e "\n--- Manual agentd check ---"
127+
ls -la /usr/local/bin/agentd || echo "agentd not found"
128+
129+
test-github-windows:
130+
runs-on: windows-latest
131+
steps:
132+
- uses: actions/checkout@v4
133+
134+
- uses: actions/setup-go@v5
135+
with:
136+
go-version: '1.21'
137+
138+
- name: Test on GitHub Windows
139+
shell: bash
140+
run: |
141+
echo "=== GITHUB WINDOWS RUNNER TEST ==="
142+
echo "Hostname: $(hostname)"
143+
144+
# Build CLI
145+
go build -o depot-test.exe ./cmd/depot
146+
147+
# Run with debug
148+
export DEPOT_DEBUG_DETECTION=1
149+
echo -e "\n--- Running depot version ---"
150+
./depot-test.exe version || true
151+
152+
- name: Check for agentd (PowerShell)
153+
shell: powershell
154+
run: |
155+
Write-Host "`n--- Manual agentd check ---"
156+
$paths = @(
157+
"C:\Program Files\Depot\agentd.exe",
158+
"C:\ProgramData\Depot\agentd.exe",
159+
"C:\usr\local\bin\agentd.exe"
160+
)
161+
foreach ($path in $paths) {
162+
if (Test-Path $path) {
163+
Write-Host "Found: $path"
164+
} else {
165+
Write-Host "Not found: $path"
166+
}
167+
}
168+
169+
test-github-macos:
170+
runs-on: macos-latest
171+
steps:
172+
- uses: actions/checkout@v4
173+
174+
- uses: actions/setup-go@v5
175+
with:
176+
go-version: '1.21'
177+
178+
- name: Test on GitHub macOS
179+
run: |
180+
echo "=== GITHUB MACOS RUNNER TEST ==="
181+
echo "Hostname: $(hostname)"
182+
183+
# Build CLI
184+
go build -o depot-test ./cmd/depot
185+
186+
# Run with debug
187+
export DEPOT_DEBUG_DETECTION=1
188+
echo -e "\n--- Running depot version ---"
189+
./depot-test version || true
190+
191+
# Check for agentd manually
192+
echo -e "\n--- Manual agentd check ---"
193+
ls -la /usr/local/bin/agentd || echo "agentd not found"
194+
195+
# Summary job
196+
test-summary:
197+
needs: [test-depot-ubuntu, test-depot-windows, test-depot-macos, test-github-ubuntu, test-github-windows, test-github-macos]
198+
runs-on: ubuntu-latest
199+
if: always()
200+
steps:
201+
- name: Summary
202+
run: |
203+
echo "=== TEST SUMMARY ==="
204+
echo "All tests completed. Check individual job outputs for results."
205+
echo ""
206+
echo "Expected results:"
207+
echo "- Depot runners: Should detect agentd and show 'Depot runner DETECTED'"
208+
echo "- GitHub runners: Should NOT detect agentd and show 'NOT a Depot runner'"

cmd/test-detection/main.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"runtime"
7+
8+
"github.com/depot/cli/pkg/helpers"
9+
)
10+
11+
func main() {
12+
fmt.Println("=== Depot GHA Detection Test ===")
13+
fmt.Printf("Platform: %s/%s\n", runtime.GOOS, runtime.GOARCH)
14+
15+
hostname, err := os.Hostname()
16+
if err != nil {
17+
fmt.Printf("Hostname: <error: %v>\n", err)
18+
} else {
19+
fmt.Printf("Hostname: %s\n", hostname)
20+
}
21+
22+
// Enable debug mode
23+
os.Setenv("DEPOT_DEBUG_DETECTION", "1")
24+
25+
fmt.Println("\nRunning detection...")
26+
isDepot := helpers.IsDepotGitHubActionsRunner()
27+
28+
fmt.Printf("\nResult: ")
29+
if isDepot {
30+
fmt.Println("✓ DEPOT RUNNER DETECTED")
31+
} else {
32+
fmt.Println("✗ NOT a Depot runner")
33+
}
34+
35+
// Also check specific paths manually for verification
36+
fmt.Println("\nManual path checks:")
37+
38+
var paths []string
39+
switch runtime.GOOS {
40+
case "windows":
41+
paths = []string{
42+
"C:\\Program Files\\Depot\\agentd.exe",
43+
"C:\\ProgramData\\Depot\\agentd.exe",
44+
"C:\\usr\\local\\bin\\agentd.exe",
45+
}
46+
case "darwin":
47+
paths = []string{
48+
"/usr/local/bin/agentd",
49+
}
50+
default:
51+
paths = []string{
52+
"/usr/local/bin/agentd",
53+
}
54+
}
55+
56+
for _, path := range paths {
57+
if _, err := os.Stat(path); err == nil {
58+
fmt.Printf(" ✓ Found: %s\n", path)
59+
} else {
60+
fmt.Printf(" ✗ Not found: %s\n", path)
61+
}
62+
}
63+
}

flake.nix

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
description = "Development shell for app";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils }:
10+
flake-utils.lib.eachDefaultSystem (system:
11+
let pkgs = import nixpkgs { inherit system; };
12+
in {
13+
devShell = pkgs.mkShell {
14+
name = "api-devshell";
15+
16+
packages = with pkgs; [
17+
go
18+
gopls
19+
buf
20+
golangci-lint
21+
];
22+
23+
shellHook = ''
24+
'';
25+
};
26+
});
27+
}

pkg/helpers/gha.go

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package helpers
22

3-
import "os"
3+
import (
4+
"fmt"
5+
"os"
6+
"runtime"
7+
)
48

59
// If the CLI is running inside a Depot GitHub Actions runner, restore the original
610
// GitHub Actions cache URL so that the remote BuildKit doesn't attempt to use the internal cache.
@@ -17,3 +21,55 @@ func FixGitHubActionsCacheEnv() {
1721
os.Setenv("ACTIONS_RESULTS_URL", original)
1822
}
1923
}
24+
25+
// IsDepotGitHubActionsRunner detects Depot runners by checking for agentd binary in OS-specific locations.
26+
func IsDepotGitHubActionsRunner() bool {
27+
var agentdPaths []string
28+
29+
// Debug: Print detection start
30+
if os.Getenv("DEPOT_DEBUG_DETECTION") != "" {
31+
fmt.Fprintf(os.Stderr, "[DEPOT DEBUG] Starting Depot GHA runner detection on %s/%s\n", runtime.GOOS, runtime.GOARCH)
32+
}
33+
34+
switch runtime.GOOS {
35+
case "windows":
36+
agentdPaths = []string{
37+
"C:\\Program Files\\Depot\\agentd.exe",
38+
"C:\\ProgramData\\Depot\\agentd.exe",
39+
"C:\\usr\\local\\bin\\agentd.exe",
40+
}
41+
case "darwin":
42+
agentdPaths = []string{
43+
"/usr/local/bin/agentd",
44+
}
45+
case "linux":
46+
agentdPaths = []string{
47+
"/usr/local/bin/agentd",
48+
}
49+
default:
50+
agentdPaths = []string{
51+
"/usr/local/bin/agentd",
52+
}
53+
}
54+
55+
for _, path := range agentdPaths {
56+
if os.Getenv("DEPOT_DEBUG_DETECTION") != "" {
57+
fmt.Fprintf(os.Stderr, "[DEPOT DEBUG] Checking for agentd at: %s\n", path)
58+
}
59+
60+
if _, err := os.Stat(path); err == nil {
61+
if os.Getenv("DEPOT_DEBUG_DETECTION") != "" {
62+
fmt.Fprintf(os.Stderr, "[DEPOT DEBUG] Found agentd at %s - Depot runner DETECTED\n", path)
63+
}
64+
return true
65+
} else if os.Getenv("DEPOT_DEBUG_DETECTION") != "" {
66+
fmt.Fprintf(os.Stderr, "[DEPOT DEBUG] agentd not found at %s: %v\n", path, err)
67+
}
68+
}
69+
70+
if os.Getenv("DEPOT_DEBUG_DETECTION") != "" {
71+
fmt.Fprintf(os.Stderr, "[DEPOT DEBUG] No agentd found - NOT a Depot runner\n")
72+
}
73+
74+
return false
75+
}

0 commit comments

Comments
 (0)