Addresses part of https://github.com/coder/internal/issues/532 (but doesn't fully close it out). This is a huge PR, but chunking it up seemed pointless, since we're largely copying over existing files. I'm going to try commenting on the main areas I think are worth paying attention to ## Changes made - Migrated over all Coder modules from coder/modules, and put them in their correct user namespaces. - Added README.md files to all newly-created user namespaces - Updated all image paths for every image used, to make sure they don't break (I switched the paths programmatically, and then manually verified every README to guarantee this). - Added README.md files for each contributor who previously made a module - Updated our `tsconfig.json` file to use modern libraries when run from the server, and made a custom `tsconfig.json` just for the `windows-rdp` module (which has more restrictive browser concerns) - Added CI step to run all the module tests we currently have ## Notes - There were a lot of Bash script files that weren't carried over in this PR, partly because I don't know Bash well enough to know (1) whether they're still needed, or (2) modify them to account for the new file structure. Those can be brought over later. - We had a `lint.ts` file that provided some light validation of some of the modules. After going through it, there were so many bugs and issues with the code that I legitimately think that it barely provided a safety net at all. I got rid of it entirely, with the intention of adding the functionality that was originally intended to the current validation logic (to be handled in a separate PR). - I changed how we set up the `.images` directory, because it felt like it would be chaos if a bunch of users try to throw all their images in one giant directory, with no guidelines on how to do it. I instead made it so that images should be scoped by namespace, which felt a lot more manageable. The `.icons` directory is still at the top level, because realistically, there are only going to be so many types of icons referenced, so it's fine for those to be shared. - I don't think the `maintainer_github` and `contributor_github` fields make sense anymore, but those can be stripped out once we've updated the Registry site build step to use the new Registry repo - My gut instinct is to use the user namespace to determine the main owner of the module, and then add a `contributors` string list to indicate which other users have contributed meaningfully to it. We can then add validation to make sure that every value in that list exists as another namespace in the repo ## What still needs to be migrated (in separate PRs) These are the main files of interest that still probably need to be copied over from the `/modules` repo: - `new.sh` - `terraform_validate.sh` - `update-version.sh` They're probably going to require enough changes that it's worth handling them in a separate PR.
171 lines
7.2 KiB
PowerShell
171 lines
7.2 KiB
PowerShell
# Terraform variables
|
|
$adminPassword = "${admin_password}"
|
|
$port = "${port}"
|
|
$webURLPath = "${web_url_path}"
|
|
|
|
function Set-LocalAdminUser {
|
|
Write-Output "[INFO] Starting Set-LocalAdminUser function"
|
|
$securePassword = ConvertTo-SecureString $adminPassword -AsPlainText -Force
|
|
Write-Output "[DEBUG] Secure password created"
|
|
Get-LocalUser -Name Administrator | Set-LocalUser -Password $securePassword
|
|
Write-Output "[INFO] Administrator password set"
|
|
Get-LocalUser -Name Administrator | Enable-LocalUser
|
|
Write-Output "[INFO] User Administrator enabled successfully"
|
|
Read-Host "[DEBUG] Press Enter to proceed to the next step"
|
|
}
|
|
|
|
function Get-VirtualDisplayDriverRequired {
|
|
Write-Output "[INFO] Starting Get-VirtualDisplayDriverRequired function"
|
|
$token = Invoke-RestMethod -Headers @{'X-aws-ec2-metadata-token-ttl-seconds' = '21600'} -Method PUT -Uri http://169.254.169.254/latest/api/token
|
|
Write-Output "[DEBUG] Token acquired: $token"
|
|
$instanceType = Invoke-RestMethod -Headers @{'X-aws-ec2-metadata-token' = $token} -Method GET -Uri http://169.254.169.254/latest/meta-data/instance-type
|
|
Write-Output "[DEBUG] Instance type: $instanceType"
|
|
$OSVersion = ((Get-ItemProperty -Path "Microsoft.PowerShell.Core\Registry::\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ProductName).ProductName) -replace "[^0-9]", ''
|
|
Write-Output "[DEBUG] OS version: $OSVersion"
|
|
|
|
# Force boolean result
|
|
$result = (($OSVersion -ne "2019") -and ($OSVersion -ne "2022") -and ($OSVersion -ne "2025")) -and (($instanceType[0] -ne 'g') -and ($instanceType[0] -ne 'p'))
|
|
Write-Output "[INFO] VirtualDisplayDriverRequired result: $result"
|
|
Read-Host "[DEBUG] Press Enter to proceed to the next step"
|
|
return [bool]$result
|
|
}
|
|
|
|
function Download-DCV {
|
|
param (
|
|
[bool]$VirtualDisplayDriverRequired
|
|
)
|
|
Write-Output "[INFO] Starting Download-DCV function"
|
|
|
|
$downloads = @(
|
|
@{
|
|
Name = "DCV Display Driver"
|
|
Required = $VirtualDisplayDriverRequired
|
|
Path = "C:\Windows\Temp\DCVDisplayDriver.msi"
|
|
Uri = "https://d1uj6qtbmh3dt5.cloudfront.net/nice-dcv-virtual-display-x64-Release.msi"
|
|
},
|
|
@{
|
|
Name = "DCV Server"
|
|
Required = $true
|
|
Path = "C:\Windows\Temp\DCVServer.msi"
|
|
Uri = "https://d1uj6qtbmh3dt5.cloudfront.net/nice-dcv-server-x64-Release.msi"
|
|
}
|
|
)
|
|
|
|
foreach ($download in $downloads) {
|
|
if ($download.Required -and -not (Test-Path $download.Path)) {
|
|
try {
|
|
Write-Output "[INFO] Downloading $($download.Name)"
|
|
|
|
# Display progress manually (no events)
|
|
$progressActivity = "Downloading $($download.Name)"
|
|
$progressStatus = "Starting download..."
|
|
Write-Progress -Activity $progressActivity -Status $progressStatus -PercentComplete 0
|
|
|
|
# Synchronously download the file
|
|
$webClient = New-Object System.Net.WebClient
|
|
$webClient.DownloadFile($download.Uri, $download.Path)
|
|
|
|
# Update progress
|
|
Write-Progress -Activity $progressActivity -Status "Completed" -PercentComplete 100
|
|
|
|
Write-Output "[INFO] $($download.Name) downloaded successfully."
|
|
} catch {
|
|
Write-Output "[ERROR] Failed to download $($download.Name): $_"
|
|
throw
|
|
}
|
|
} else {
|
|
Write-Output "[INFO] $($download.Name) already exists. Skipping download."
|
|
}
|
|
}
|
|
|
|
Write-Output "[INFO] All downloads completed"
|
|
Read-Host "[DEBUG] Press Enter to proceed to the next step"
|
|
}
|
|
|
|
function Install-DCV {
|
|
param (
|
|
[bool]$VirtualDisplayDriverRequired
|
|
)
|
|
Write-Output "[INFO] Starting Install-DCV function"
|
|
|
|
if (-not (Get-Service -Name "dcvserver" -ErrorAction SilentlyContinue)) {
|
|
if ($VirtualDisplayDriverRequired) {
|
|
Write-Output "[INFO] Installing DCV Display Driver"
|
|
Start-Process "C:\Windows\System32\msiexec.exe" -ArgumentList "/I C:\Windows\Temp\DCVDisplayDriver.msi /quiet /norestart" -Wait
|
|
} else {
|
|
Write-Output "[INFO] DCV Display Driver installation skipped (not required)."
|
|
}
|
|
Write-Output "[INFO] Installing DCV Server"
|
|
Start-Process "C:\Windows\System32\msiexec.exe" -ArgumentList "/I C:\Windows\Temp\DCVServer.msi ADDLOCAL=ALL /quiet /norestart /l*v C:\Windows\Temp\dcv_install_msi.log" -Wait
|
|
} else {
|
|
Write-Output "[INFO] DCV Server already installed, skipping installation."
|
|
}
|
|
|
|
# Wait for the service to appear with a timeout
|
|
$timeout = 10 # seconds
|
|
$elapsed = 0
|
|
while (-not (Get-Service -Name "dcvserver" -ErrorAction SilentlyContinue) -and ($elapsed -lt $timeout)) {
|
|
Start-Sleep -Seconds 1
|
|
$elapsed++
|
|
}
|
|
|
|
if ($elapsed -ge $timeout) {
|
|
Write-Output "[WARNING] Timeout waiting for dcvserver service. A restart is required to complete installation."
|
|
Restart-SystemForDCV
|
|
} else {
|
|
Write-Output "[INFO] dcvserver service detected successfully."
|
|
}
|
|
}
|
|
|
|
function Restart-SystemForDCV {
|
|
Write-Output "[INFO] The system will restart in 10 seconds to finalize DCV installation."
|
|
Start-Sleep -Seconds 10
|
|
|
|
# Initiate restart
|
|
Restart-Computer -Force
|
|
|
|
# Exit the script after initiating restart
|
|
Write-Output "[INFO] Please wait for the system to restart..."
|
|
|
|
Exit 1
|
|
}
|
|
|
|
|
|
function Configure-DCV {
|
|
Write-Output "[INFO] Starting Configure-DCV function"
|
|
$dcvPath = "Microsoft.PowerShell.Core\Registry::\HKEY_USERS\S-1-5-18\Software\GSettings\com\nicesoftware\dcv"
|
|
|
|
# Create the required paths
|
|
@("$dcvPath\connectivity", "$dcvPath\session-management", "$dcvPath\session-management\automatic-console-session", "$dcvPath\display") | ForEach-Object {
|
|
if (-not (Test-Path $_)) {
|
|
New-Item -Path $_ -Force | Out-Null
|
|
}
|
|
}
|
|
|
|
# Set registry keys
|
|
New-ItemProperty -Path "$dcvPath\session-management" -Name create-session -PropertyType DWORD -Value 1 -Force
|
|
New-ItemProperty -Path "$dcvPath\session-management\automatic-console-session" -Name owner -Value Administrator -Force
|
|
New-ItemProperty -Path "$dcvPath\connectivity" -Name quic-port -PropertyType DWORD -Value $port -Force
|
|
New-ItemProperty -Path "$dcvPath\connectivity" -Name web-port -PropertyType DWORD -Value $port -Force
|
|
New-ItemProperty -Path "$dcvPath\connectivity" -Name web-url-path -PropertyType String -Value $webURLPath -Force
|
|
|
|
# Attempt to restart service
|
|
if (Get-Service -Name "dcvserver" -ErrorAction SilentlyContinue) {
|
|
Restart-Service -Name "dcvserver"
|
|
} else {
|
|
Write-Output "[WARNING] dcvserver service not found. Ensure the system was restarted properly."
|
|
}
|
|
|
|
Write-Output "[INFO] DCV configuration completed"
|
|
Read-Host "[DEBUG] Press Enter to proceed to the next step"
|
|
}
|
|
|
|
# Main Script Execution
|
|
Write-Output "[INFO] Starting script"
|
|
$VirtualDisplayDriverRequired = [bool](Get-VirtualDisplayDriverRequired)
|
|
Set-LocalAdminUser
|
|
Download-DCV -VirtualDisplayDriverRequired $VirtualDisplayDriverRequired
|
|
Install-DCV -VirtualDisplayDriverRequired $VirtualDisplayDriverRequired
|
|
Configure-DCV
|
|
Write-Output "[INFO] Script completed"
|