This guide documents the process of setting up a Windows workspace using Coder and building the Coder repository on it.
- Access to a Coder deployment (e.g., dev.coder.com)
coder
CLI installed and authenticated
# Generate a random suffix for workspace name to avoid conflicts
RANDOM_SUFFIX=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 8 | head -n 1)
WORKSPACE_NAME="win-coder-${RANDOM_SUFFIX}"
# Create the workspace using the windows-with-good-rdp template
coder create --parameter display_enabled=false \
--parameter gpu_enabled=false \
--parameter zone="us-central1-a" \
--template windows-with-good-rdp \
--org=coder \
${WORKSPACE_NAME}
When prompted, confirm the creation by typing yes
.
# Ensure SSH directory exists
mkdir -p ~/.ssh && chmod 700 ~/.ssh
# Configure SSH for Coder
coder config-ssh -y
# Test connection to the workspace
ssh coder.${WORKSPACE_NAME} echo "Connection successful"
Here are the PowerShell commands to run on the Windows workspace:
# Create a working directory
New-Item -Path "C:\build-test" -ItemType Directory -Force
Set-Location -Path "C:\build-test"
# Install Git
Write-Host "Installing Git..."
Invoke-WebRequest -Uri "https://github.com/git-for-windows/git/releases/download/v2.42.0.windows.2/Git-2.42.0.2-64-bit.exe" -OutFile "git-installer.exe"
Start-Process -FilePath "git-installer.exe" -ArgumentList "/VERYSILENT /NORESTART" -Wait
# Clone the Coder repository
$gitPath = "C:\Program Files\Git\bin\git.exe"
Write-Host "Using Git from: $gitPath"
& $gitPath clone https://github.com/coder/coder.git
Set-Location -Path "coder"
# Install Go (portable version)
Write-Host "Installing Go (portable version)..."
Invoke-WebRequest -Uri "https://go.dev/dl/go1.21.0.windows-amd64.zip" -OutFile "C:\build-test\go.zip"
# Create directory for extraction
New-Item -Path "C:\build-test\go3" -ItemType Directory -Force
# Extract Go using .NET
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\build-test\go.zip", "C:\build-test\go3")
# Set environment variables
$env:Path += ";C:\build-test\go3\go\bin"
$env:GOPATH = "C:\build-test\gopath"
[Environment]::SetEnvironmentVariable("Path", $env:Path, "User")
[Environment]::SetEnvironmentVariable("GOPATH", $env:GOPATH, "User")
# Verify Go installation
Write-Host "Verifying Go installation..."
& "C:\build-test\go3\go\bin\go.exe" version
# Build the Coder project
Write-Host "Building Coder project..."
Set-Location -Path "C:\build-test\coder"
& "C:\build-test\go3\go\bin\go.exe" build -o coder.exe ./cmd/coder
# Verify the build
if (Test-Path "coder.exe") {
Write-Host "Build successful\! Coder binary created at: $(Get-Location)\coder.exe"
& .\coder.exe version
} else {
Write-Host "Build failed. The binary was not created."
}
# Check what's in the build directory
ssh coder.${WORKSPACE_NAME} powershell -Command "Get-ChildItem -Path 'C:\build-test\coder' -File | Where-Object { \$_.Extension -eq '.exe' } | Select-Object Name, Length, LastWriteTime"
# Verify the executable works
ssh coder.${WORKSPACE_NAME} powershell -Command "& 'C:\build-test\coder\coder.exe' version"
-
Windows RDP Access: The Windows workspace created with the template includes RDP access with these credentials:
- Username:
Administrator
- Password:
coderRDP\!
- Username:
-
Build Time: The Coder build process can take between 5-15 minutes depending on the workspace resources and network connectivity.
-
SSH Connection Issues: If SSH connection stalls, try adding a timeout or forcing a new connection:
timeout 30 ssh coder.${WORKSPACE_NAME} echo "Connection test"
-
Alternative Method for Script Execution: If sending a script via standard input doesn't work, you can create a Base64-encoded version:
SCRIPT_B64=$(base64 -w 0 setup_coder_build.ps1) ssh coder.${WORKSPACE_NAME} powershell -Command "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('$SCRIPT_B64')) | powershell -Command -"
-
Environment Persistence: Once set up, the environment will persist in the workspace as long as the workspace exists. The Go installation, Git, and the cloned repository will remain intact.