-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathsetup-dev.ps1
More file actions
381 lines (333 loc) · 13 KB
/
Copy pathsetup-dev.ps1
File metadata and controls
381 lines (333 loc) · 13 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#!/usr/bin/env pwsh
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: MIT
#Requires -Version 7.0
<#
.SYNOPSIS
Development environment setup for physical-ai-toolchain.
.DESCRIPTION
Verifies required tools, installs uv, sets up Python virtual environment,
clones Isaac Lab, and checks for hve-core.
.PARAMETER DisableVenv
Skip virtual environment creation; install packages directly.
.EXAMPLE
./setup-dev.ps1
.EXAMPLE
./setup-dev.ps1 -DisableVenv
#>
[CmdletBinding()]
param(
[switch]$DisableVenv
)
$ErrorActionPreference = 'Stop'
. (Join-Path $PSScriptRoot 'scripts/lib/Get-VerifiedDownload.ps1')
#region Helper Functions
function Write-Info {
param([string]$Message)
if ($env:NO_COLOR) {
Write-Host "[INFO] $Message"
}
else {
Write-Host "[INFO] $Message" -ForegroundColor Blue
}
}
function Write-Warn {
param([string]$Message)
if ($env:NO_COLOR) {
Write-Warning "[WARN] $Message"
}
else {
Write-Host "[WARN] $Message" -ForegroundColor Yellow
}
}
function Write-Section {
param([string]$Title)
Write-Host ''
Write-Host '============================'
Write-Host $Title
Write-Host '============================'
}
function Assert-Tools {
param([string[]]$Tools)
$missing = @()
foreach ($tool in $Tools) {
if (-not (Get-Command $tool -ErrorAction SilentlyContinue)) {
$missing += $tool
}
}
if ($missing.Count -gt 0) {
Write-Error "Missing required tools: $($missing -join ', ')"
}
}
function Install-Uv {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$Version,
[Parameter(Mandatory)]
[string]$ExpectedHash,
[Parameter(Mandatory)]
[bool]$IsWindowsPlatform
)
Write-Info "Installing uv package manager v$Version..."
if ($IsWindowsPlatform -and [string]::IsNullOrWhiteSpace($env:USERPROFILE)) {
throw 'USERPROFILE is required to locate the Windows uv installation'
}
$installerDirectory = Join-Path ([System.IO.Path]::GetTempPath()) ([guid]::NewGuid().ToString('N'))
$installerExitCode = -1
try {
New-Item -ItemType Directory -Path $installerDirectory | Out-Null
if (-not $IsWindowsPlatform) {
chmod 700 $installerDirectory
if ($LASTEXITCODE -ne 0) {
throw 'Failed to restrict uv installer directory permissions'
}
}
$download = Invoke-VerifiedDownload `
-Url "https://astral.sh/uv/$Version/install.ps1" `
-DestinationDirectory $installerDirectory `
-FileName 'uv-install.ps1' `
-ExpectedHash $ExpectedHash
$global:LASTEXITCODE = 0
& $download.Path
$installerExitCode = $LASTEXITCODE
}
finally {
Remove-Item -LiteralPath $installerDirectory -Recurse -Force -ErrorAction SilentlyContinue
}
if ($IsWindowsPlatform) {
$env:PATH = "$env:USERPROFILE\.local\bin;$env:USERPROFILE\.cargo\bin;$env:PATH"
}
else {
$env:PATH = "$HOME/.local/bin:$HOME/.cargo/bin:$env:PATH"
}
$uvCommand = Get-Command uv -ErrorAction SilentlyContinue
$reportedVersion = if ($uvCommand) { (uv --version) -join ' ' } else { '' }
if (
$installerExitCode -ne 0 -or
-not $uvCommand -or
$reportedVersion -notmatch ('\b' + [regex]::Escape($Version) + '\b')
) {
throw "Failed to install uv v$Version"
}
}
#endregion
$ScriptDir = $PSScriptRoot
$VenvDir = Join-Path $ScriptDir '.venv'
# Devcontainer recommendation
Write-Host ''
Write-Host ([System.Char]::ConvertFromUtf32(0x1F4A1) + ' RECOMMENDED: Use the Dev Container for the best experience.')
Write-Host ''
Write-Host 'The devcontainer includes all tools pre-configured:'
Write-Host ' - Azure CLI, Terraform, kubectl, helm, jq'
Write-Host ' - Python with all dependencies'
Write-Host ' - VS Code extensions for Terraform and Python'
Write-Host ''
Write-Host 'To use:'
Write-Host ' VS Code -> Reopen in Container (F1 -> Dev Containers: Reopen)'
Write-Host ' Codespaces -> Open in Codespace from GitHub'
Write-Host ''
Write-Host 'If this script fails, the devcontainer is your fallback.'
Write-Host ''
Write-Section 'Git Symlink Resolution'
# Git symlinks are stored as text files on Windows when core.symlinks=false.
# Replace broken symlinks with junctions (directories) or hard links (files).
$symlinkEntries = git ls-files -s 2>$null | Select-String '120000' | ForEach-Object {
($_ -split '\s+', 4)[3]
}
$repairedCount = 0
foreach ($entry in $symlinkEntries) {
$fullPath = Join-Path $ScriptDir $entry
if (-not (Test-Path $fullPath)) { continue }
$item = Get-Item $fullPath -Force
# Already a junction/symlink — nothing to fix
if ($item.LinkType) { continue }
# Only fix plain text files (broken symlink placeholders)
if ($item.PSIsContainer) { continue }
$target = (Get-Content $fullPath -Raw).Trim()
$resolvedTarget = Resolve-Path (Join-Path (Split-Path $fullPath) $target) -ErrorAction SilentlyContinue
if (-not $resolvedTarget) {
Write-Warn "Symlink target not found: $entry -> $target"
continue
}
Remove-Item $fullPath -Force
$targetItem = Get-Item $resolvedTarget.Path
if ($targetItem.PSIsContainer) {
New-Item -ItemType Junction -Path $fullPath -Target $resolvedTarget.Path | Out-Null
}
else {
New-Item -ItemType HardLink -Path $fullPath -Target $resolvedTarget.Path | Out-Null
}
$repairedCount++
}
if ($repairedCount -gt 0) {
Write-Info "Repaired $repairedCount broken git symlink(s) (junctions/hard links)"
}
else {
Write-Info 'All git symlinks are intact'
}
Write-Section 'Tool Verification'
Assert-Tools az, terraform, kubectl, helm, jq
Write-Info 'All required tools found'
Write-Section 'UV Package Manager Setup'
$UvVersion = '0.12.8'
# SHA-256 for https://astral.sh/uv/0.12.8/install.ps1.
$UvInstallerSha256 = 'c1c357b2945c4eb31f3380a6c0cb1c371f18b3c0d1856073f82d17cc52c892cb'
if (-not (Get-Command uv -ErrorAction SilentlyContinue)) {
Install-Uv `
-Version $UvVersion `
-ExpectedHash $UvInstallerSha256 `
-IsWindowsPlatform $IsWindows
}
Write-Info "Using uv: $(uv --version)"
# ===================================================================
# Terraform-Docs
# ===================================================================
Write-Section 'Terraform-Docs Setup'
$TerraformDocsVersion = '0.24.0'
if (Get-Command terraform-docs -ErrorAction SilentlyContinue) {
Write-Info "terraform-docs: $(terraform-docs --version)"
} else {
Write-Info "Installing terraform-docs v$TerraformDocsVersion..."
$arch = if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') { 'arm64' } else { 'amd64' }
$os = if ($IsLinux) { 'linux' } elseif ($IsMacOS) { 'darwin' } else { 'windows' }
$ext = if ($os -eq 'windows') { 'zip' } else { 'tar.gz' }
$url = "https://github.com/terraform-docs/terraform-docs/releases/download/v$TerraformDocsVersion/terraform-docs-v$TerraformDocsVersion-$os-$arch.$ext"
$dest = Join-Path $env:TEMP "terraform-docs.$ext"
Invoke-WebRequest -Uri $url -OutFile $dest
if ($os -eq 'windows') {
Expand-Archive -Path $dest -DestinationPath $env:TEMP -Force
Move-Item (Join-Path $env:TEMP 'terraform-docs.exe') (Join-Path $env:LOCALAPPDATA 'Microsoft\WindowsApps\terraform-docs.exe') -Force
} else {
tar -xzf $dest -C /tmp terraform-docs
sudo mv /tmp/terraform-docs /usr/local/bin/terraform-docs
sudo chmod +x /usr/local/bin/terraform-docs
}
Remove-Item $dest -ErrorAction SilentlyContinue
Write-Info "terraform-docs: v$TerraformDocsVersion (installed)"
}
# ===================================================================
# OSV-Scanner
# ===================================================================
Write-Section 'OSV-Scanner Setup'
$OsvScannerVersion = '2.3.8'
$osvInstalled = $null
if (Get-Command osv-scanner -ErrorAction SilentlyContinue) {
$osvInstalled = (osv-scanner --version 2>&1 | Select-String -Pattern '\d+\.\d+\.\d+' | Select-Object -First 1).Matches.Value
}
if ($osvInstalled -eq $OsvScannerVersion) {
Write-Info "osv-scanner: v$osvInstalled"
} else {
Write-Info "Installing osv-scanner v$OsvScannerVersion..."
$arch = if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') { 'arm64' } else { 'amd64' }
$os = if ($IsLinux) { 'linux' } elseif ($IsMacOS) { 'darwin' } else { 'windows' }
$ext = if ($os -eq 'windows') { '.exe' } else { '' }
# SHA-256 digests for OSV-Scanner v2.3.8 release assets; keep aligned with setup-dev.sh.
$OsvScannerDigests = @{
'linux_amd64' = 'bc98e15319ed0d515e3f9235287ba53cdc5535d576d24fd573978ecfe9ab92dc'
'linux_arm64' = '8158b18edd2d03b1a30d905ca91b032bc62262167be8f206c27114f08823e27c'
'darwin_amd64' = 'b8a80a9f14ca4c0cd0fc2d351b28f740da9e6a5b18385ac9f9d083360b5b504e'
'darwin_arm64' = 'a8cd6507b06239f463a7642430cfd2d154882f150f6e30cdc0653e28dfc34216'
'windows_amd64' = 'cb04e79dd9698a7bc821bbfdddec916a416d1409fda79c927c509d37d00c9716'
'windows_arm64' = '285d1fbcf2c69ab5ee38ae3a850ab46e83f32ef1cd5f3c4c9eb161cc493f6d52'
}
$digestKey = "${os}_${arch}"
$expectedSha = $OsvScannerDigests[$digestKey]
if (-not $expectedSha) {
Write-Error "Unsupported OS/arch for osv-scanner: $digestKey"
}
$assetName = "osv-scanner_${os}_${arch}${ext}"
$url = "https://github.com/google/osv-scanner/releases/download/v$OsvScannerVersion/$assetName"
$dest = Join-Path ([System.IO.Path]::GetTempPath()) "osv-scanner$ext"
Invoke-WebRequest -Uri $url -OutFile $dest
$actualSha = (Get-FileHash -Path $dest -Algorithm SHA256).Hash.ToLower()
if ($actualSha -ne $expectedSha) {
Remove-Item $dest -ErrorAction SilentlyContinue
Write-Error "osv-scanner SHA-256 mismatch for ${digestKey}: expected $expectedSha, got $actualSha"
}
if ($os -eq 'windows') {
Move-Item $dest (Join-Path $env:LOCALAPPDATA 'Microsoft\WindowsApps\osv-scanner.exe') -Force
} else {
sudo install -m 0755 $dest /usr/local/bin/osv-scanner
Remove-Item $dest -ErrorAction SilentlyContinue
}
Write-Info "osv-scanner: v$OsvScannerVersion (installed)"
}
Write-Section 'Python Environment Setup'
$PythonVersion = Get-Content (Join-Path $ScriptDir '.python-version') -Raw
$PythonVersion = $PythonVersion.Trim()
Write-Info "Target Python version: $PythonVersion"
if ($DisableVenv) {
Write-Info 'Virtual environment disabled, installing packages directly...'
}
else {
if (-not (Test-Path $VenvDir)) {
Write-Info "Creating virtual environment at $VenvDir with Python $PythonVersion..."
uv venv $VenvDir --python $PythonVersion
if ($LASTEXITCODE -ne 0) {
Write-Error "uv venv failed (exit code $LASTEXITCODE)"
}
}
else {
Write-Info "Virtual environment already exists at $VenvDir"
}
}
Write-Info 'Syncing dependencies from pyproject.toml...'
uv sync
if ($LASTEXITCODE -ne 0) {
Write-Error "uv sync failed (exit code $LASTEXITCODE)"
}
Write-Info 'Locking dependencies...'
uv lock
if ($LASTEXITCODE -ne 0) {
Write-Error "uv lock failed (exit code $LASTEXITCODE)"
}
Write-Section 'Isaac Lab Setup'
$IsaacLabDir = Join-Path $ScriptDir 'external' 'IsaacLab'
if (Test-Path $IsaacLabDir) {
Write-Info "Isaac Lab already cloned at $IsaacLabDir"
Write-Info "To update, run: cd $IsaacLabDir && git pull"
}
else {
Write-Info 'Cloning Isaac Lab for intellisense/Pylance support...'
New-Item -ItemType Directory -Path (Join-Path $ScriptDir 'external') -Force | Out-Null
git clone 'https://github.com/isaac-sim/IsaacLab.git' $IsaacLabDir
if ($LASTEXITCODE -ne 0) {
Write-Error "git clone failed (exit code $LASTEXITCODE)"
}
Write-Info 'Isaac Lab cloned successfully'
}
Write-Section 'hve-core Check'
$HveCoreDir = Join-Path $ScriptDir '..' 'hve-core'
if (-not (Test-Path $HveCoreDir)) {
Write-Warn "hve-core not found at $HveCoreDir"
Write-Warn 'Install for Copilot workflows: https://github.com/microsoft/hve-core/blob/main/docs/getting-started/install.md'
Write-Warn 'Or install the VS Code Extension: ise-hve-essentials.hve-core'
}
else {
Write-Info "hve-core found at $HveCoreDir"
}
Write-Section 'Setup Complete'
Write-Host ''
Write-Host 'Development environment setup complete!'
Write-Host ''
if (-not $DisableVenv) {
Write-Warn 'Run this command to activate the virtual environment:'
Write-Host ''
if ($IsWindows) {
Write-Host ' .venv\Scripts\Activate.ps1'
}
else {
Write-Host ' source .venv/bin/activate'
}
Write-Host ''
}
Write-Host 'Next steps:'
Write-Host ' 1. Run: . infrastructure/terraform/prerequisites/az-sub-init.ps1'
Write-Host ' 2. Configure: infrastructure/terraform/terraform.tfvars'
Write-Host ' 3. Deploy: cd infrastructure/terraform && terraform init && terraform apply'
Write-Host ''
Write-Host 'Documentation:'
Write-Host ' - README.md - Quick start guide'
Write-Host ' - infrastructure/README.md - Deployment overview'
Write-Host ''