From 86a94b5494327ade76911b1eda3fd6afa034510e Mon Sep 17 00:00:00 2001 From: Evilazaro Alves Date: Wed, 27 Mar 2024 12:14:52 -0500 Subject: [PATCH] Updating the scripts to leverage DevBox Taks for customization --- .../computeGallery/BackEnd-InstallWSL.ps1 | 85 -------------- ...kEndEngineerImgTemplateFullCustomized.json | 30 ----- .../computeGallery/cloneRepos.ps1 | 62 ---------- .../frontEndEngineerImgTemplate.json | 106 ------------------ .../devBox/devCentertemplate.json | 17 +-- Deploy/Bash/deploy.sh | 1 - .../install-docker/install-docker.ps1 | 92 +++++++-------- Tasks/install-docker/task.yaml | 7 ++ Tasks/update-dependencies/task.yaml | 7 ++ .../update-dependencies.ps1 | 0 10 files changed, 53 insertions(+), 354 deletions(-) delete mode 100644 Deploy/ARMTemplates/computeGallery/BackEnd-InstallWSL.ps1 delete mode 100644 Deploy/ARMTemplates/computeGallery/cloneRepos.ps1 delete mode 100644 Deploy/ARMTemplates/computeGallery/frontEndEngineerImgTemplate.json rename Deploy/ARMTemplates/computeGallery/BackEnd-Customizations.ps1 => Tasks/install-docker/install-docker.ps1 (64%) create mode 100644 Tasks/install-docker/task.yaml create mode 100644 Tasks/update-dependencies/task.yaml rename Deploy/ARMTemplates/computeGallery/updateDependencies.ps1 => Tasks/update-dependencies/update-dependencies.ps1 (100%) diff --git a/Deploy/ARMTemplates/computeGallery/BackEnd-InstallWSL.ps1 b/Deploy/ARMTemplates/computeGallery/BackEnd-InstallWSL.ps1 deleted file mode 100644 index 3d7e906..0000000 --- a/Deploy/ARMTemplates/computeGallery/BackEnd-InstallWSL.ps1 +++ /dev/null @@ -1,85 +0,0 @@ -Set-ExecutionPolicy Bypass -Scope Process -Force - -function WriteTimestampedMessage { - param ( - [string]$message - ) - - $currentTime = Get-Date - Write-Host "$message at $($currentTime.ToLongTimeString())" -} - -function EnsureDirectory { - param ( - [string]$path - ) - - if (-not (Test-Path $path)) { - New-Item -Path $path -ItemType Directory | Out-Null - } -} - -function DownloadScript { - param ( - [string]$uri, - [string]$destinationPath - ) - - Invoke-WebRequest -Uri $uri -OutFile $destinationPath -} - -# Main Script Execution - -WriteTimestampedMessage "Starting WSL Ubuntu installation" - -$automaticInstall = $true -$wslRootPath = "c:\WSL2" -$wslTempPath = Join-Path $wslRootPath "temp" -$wslStagingPath = Join-Path $wslTempPath "staging" -$wslScriptsPath = Join-Path $wslRootPath "scripts" - -Write-Host "Creating Directories" -EnsureDirectory $wslRootPath -EnsureDirectory $wslTempPath -EnsureDirectory $wslStagingPath -EnsureDirectory $wslScriptsPath -Write-Host "Directories Created" - -$wslInstalled = (Get-Command wsl.exe -ErrorAction SilentlyContinue) -ne $null - -if ($wslInstalled) { - Write-Host "WSL is Installed" -} else { - Write-Error "WSL not detected! WSL is needed to install." - exit 1 -} - -Write-Host "Downloading Scripts" -DownloadScript "https://raw.githubusercontent.com/Evilazaro/MicrosoftDevBox/main/Deploy/ARMTemplates/computeGallery/createUser.sh" (Join-Path $wslScriptsPath "createUser.sh") -DownloadScript "https://raw.githubusercontent.com/Evilazaro/MicrosoftDevBox/main/Deploy/ARMTemplates/computeGallery/installUtils.sh" (Join-Path $wslScriptsPath "installUtils.sh") -Write-Host "Scripts downloaded to $wslScriptsPath" - -if ($automaticInstall) { - $wslName = 'Ubuntu' - $wslInstallationPath = "C:\Users\Default\AppData\Local\WSL2\$wslName" - $wslUsername = "vmadmin" - - WriteTimestampedMessage "Installing Ubuntu" - wsl --install -d Ubuntu -u root -y - WriteTimestampedMessage "Ubuntu installed successfully" - - # Commented out sections can be uncommented if needed. - # WriteTimestampedMessage "Creating Ubuntu User" - # wsl -d $wslName -u root bash -ic "/mnt/c/WSL2/scripts/createUser.sh $wslUsername ubuntu" - # WriteTimestampedMessage "Ubuntu User Created" - # WriteTimestampedMessage "Updating Ubuntu User" - # wsl -d $wslName -u root bash -ic "/mnt/c/temp/configureUbuntuFrontEnd.sh" - # wsl -d $wslName -u root bash -ic "DEBIAN_FRONTEND=noninteractive /mnt/c/temp/updateUbuntu.sh" - # WriteTimestampedMessage "Ubuntu Updated" - # Write-Host "Restarting WSL Distro" - # wsl -t $wslName - # Write-Host "WSL Distro Restarted" - WriteTimestampedMessage "Finishing WSL Ubuntu installation" -} else { - Add-AppxPackage $packageArgs.fileFullPath -} diff --git a/Deploy/ARMTemplates/computeGallery/backEndEngineerImgTemplateFullCustomized.json b/Deploy/ARMTemplates/computeGallery/backEndEngineerImgTemplateFullCustomized.json index 66f6184..c97ab30 100644 --- a/Deploy/ARMTemplates/computeGallery/backEndEngineerImgTemplateFullCustomized.json +++ b/Deploy/ARMTemplates/computeGallery/backEndEngineerImgTemplateFullCustomized.json @@ -56,36 +56,6 @@ "filters": [ "exclude:$_.Title -like '*Preview*'" ] - }, - { - "type": "PowerShell", - "name": "Updating Dependencies", - "inline": [ - "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/Evilazaro/MicrosoftDevBox/main/Deploy/ARMTemplates/computeGallery/updateDependencies.ps1'));" - ] - }, - { - "type": "PowerShell", - "name": "Cloning GitHub Repos", - "inline": [ - "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/Evilazaro/MicrosoftDevBox/main/Deploy/ARMTemplates/computeGallery/cloneRepos.ps1'));" - ] - }, - { - "type": "PowerShell", - "name": "Installing Dependencies and Customizations", - "inline": [ - "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/Evilazaro/MicrosoftDevBox/main/Deploy/ARMTemplates/computeGallery/BackEnd-Customizations.ps1'));" - ] - }, - { - "type": "PowerShell", - "name": "Adding current user to docker-users group", - "inline": [ - "Set-ExecutionPolicy Bypass -Scope Process -Force;", - "Write-Host 'Adding current user to docker-users group';", - "Add-LocalGroupMember -Group 'docker-users' -Member 'Everyone';" - ] } ], "distribute": [ diff --git a/Deploy/ARMTemplates/computeGallery/cloneRepos.ps1 b/Deploy/ARMTemplates/computeGallery/cloneRepos.ps1 deleted file mode 100644 index 71f6b1a..0000000 --- a/Deploy/ARMTemplates/computeGallery/cloneRepos.ps1 +++ /dev/null @@ -1,62 +0,0 @@ -# Checks and sets the execution policy if needed -function initializeEnvironment { - # Get current execution policy - $currentPolicy = Get-ExecutionPolicy -Scope Process - - # Set execution policy if it's more restrictive than 'Bypass' - if ($currentPolicy -ne 'Bypass') { - Set-ExecutionPolicy Bypass -Scope Process -Force - } -} - -# Clones repositories based on given array of repository info -function cloneRepositories { - param ( - [Parameter(Mandatory = $true)] - [Array]$reposToClone - ) - - mkdir c:\projects - icacls c:\projects /grant "Everyone:(OI)(CI)F" /T - git config --global --add safe.directory C:/projects/ - - foreach ($repo in $reposToClone) { - Write-Output "Cloning $($repo.description)" - - try { - git clone $repo.url $repo.destination - git config --global --add safe.directory $repo.destination - } catch { - throw "Failed to clone $($repo.description) from $($repo.url) to $($repo.destination)" - } - } -} - -# Main script execution -function main { - initializeEnvironment - - # Define repositories to clone - $repositories = @( - @{ - url = 'https://github.com/Evilazaro/eShopOnContainers.git' - destination = 'c:\projects\eShop' - description = 'eShop running on containers' - }, - @{ - url = 'https://github.com/Evilazaro/eShopAPI.git' - destination = 'c:\projects\eShopAPI' - description = 'eShop API' - }, - @{ - url = 'https://github.com/dotnet-architecture/eShopOnBlazor.git' - destination = 'c:\projects\eShopOnBlazor' - description = 'eShop on Blazor WebAssembly' - } - ) - - cloneRepositories -reposToClone $repositories -} - -# Call the main function to run the script -main diff --git a/Deploy/ARMTemplates/computeGallery/frontEndEngineerImgTemplate.json b/Deploy/ARMTemplates/computeGallery/frontEndEngineerImgTemplate.json deleted file mode 100644 index 4ab5004..0000000 --- a/Deploy/ARMTemplates/computeGallery/frontEndEngineerImgTemplate.json +++ /dev/null @@ -1,106 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "imgName": { - "defaultValue": "", - "type": "String" - }, - "imageGalleryId": { - "defaultValue": "", - "type": "String" - }, - "userAssignedId": { - "defaultValue": "", - "type": "String" - }, - "location": { - "defaultValue": "", - "type": "String" - } - }, - "variables": {}, - "resources": [ - { - "type": "Microsoft.VirtualMachineImages/imageTemplates", - "apiVersion": "2022-07-01", - "name": "[parameters('imgName')]", - "location": "[parameters('location')]", - "tags": { - "Environment": "Prod", - "Role": "Front-End-Engineer", - "Team": "Engineering", - "businessUnit": "e-Commerce", - "division": "petv2-Platform", - "offer": "petv2-DevWorkstation-Service", - "solution": "ContosoProjects" - }, - "identity": { - "type": "UserAssigned", - "userAssignedIdentities": { - "[parameters('userAssignedId')]": {} - } - }, - "properties": { - "source": { - "offer": "windowsplustools", - "publisher": "microsoftvisualstudio", - "sku": "base-win11-gen2", - "type": "PlatformImage", - "version": "latest" - }, - "customize": [ - { - "type": "WindowsUpdate", - "searchCriteria": "IsInstalled=0", - "filters": [ - "exclude:$_.Title -like '*Preview*'" - ] - }, - { - "type": "PowerShell", - "name": "Installing VS Code", - "inline": [ - "Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'));choco install vscode -y;" - ] - }, - { - "type": "PowerShell", - "name": "Cloning GitHub Repos", - "inline": [ - "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/Evilazaro/MicrosoftDevBox/main/Deploy/ARMTemplates/computeGallery/cloneRepos.ps1'));" - ] - } - ], - "distribute": [ - { - "artifactTags": { - "Environment": "Prod", - "Role": "Front-End-Engineer", - "Team": "Engineering", - "businessUnit": "e-Commerce", - "division": "petv2-Platform", - "offer": "petv2-DevWorkstation-Service", - "solution": "ContosoProjects" - }, - "excludeFromLatest": false, - "galleryImageId": "[concat(parameters('imageGalleryId'), concat('/images/', parameters('imgName')))]", - "replicationRegions": [ - "[parameters('location')]" - ], - "runOutputName": "[parameters('imgName')]", - "type": "SharedImage" - } - ], - "buildTimeoutInMinutes": 0, - "vmProfile": { - "vmSize": "Standard_DS2_v2", - "osDiskSizeGB": 128, - "userAssignedIdentities": [ - "[parameters('userAssignedId')]" - ] - } - } - } - ] -} \ No newline at end of file diff --git a/Deploy/ARMTemplates/devBox/devCentertemplate.json b/Deploy/ARMTemplates/devBox/devCentertemplate.json index 1c2c09c..d0a65aa 100644 --- a/Deploy/ARMTemplates/devBox/devCentertemplate.json +++ b/Deploy/ARMTemplates/devBox/devCentertemplate.json @@ -55,27 +55,12 @@ ], "properties": { "gitHub": { - "uri": "https://github.com/microsoft/devcenter-catalog.git", + "uri": "https://github.com/Evilazaro/MicrosoftDevBox.git", "branch": "main", "path": "Tasks" } } }, - { - "type": "Microsoft.DevCenter/devcenters/catalogs", - "apiVersion": "2023-10-01-preview", - "name": "[concat(parameters('devCenterName'), '/quickstart-environment-definitions')]", - "dependsOn": [ - "[resourceId('Microsoft.DevCenter/devcenters', parameters('devCenterName'))]" - ], - "properties": { - "gitHub": { - "uri": "https://github.com/microsoft/devcenter-catalog.git", - "branch": "main", - "path": "Environment-Definitions" - } - } - }, { "type": "Microsoft.DevCenter/devcenters/attachednetworks", "apiVersion": "2023-04-01", diff --git a/Deploy/Bash/deploy.sh b/Deploy/Bash/deploy.sh index e660ceb..5a22d9d 100644 --- a/Deploy/Bash/deploy.sh +++ b/Deploy/Bash/deploy.sh @@ -195,7 +195,6 @@ function buildImage declare -A image_params image_params["Engineer-Clean-Img"]="Engineer-Clean petv2-Fabric ./DownloadedTempTemplates/engineerCleanTemplate-Output.json https://raw.githubusercontent.com/Evilazaro/MicrosoftDevBox/$branch/Deploy/ARMTemplates/computeGallery/engineerCleanTemplate.json Contoso" - image_params["FrontEnd-Img"]="VSCode-FrontEnd-Docker petv2-Fabric ./DownloadedTempTemplates/FrontEnd-Docker-Output.json https://raw.githubusercontent.com/Evilazaro/MicrosoftDevBox/$branch/Deploy/ARMTemplates/computeGallery/frontEndEngineerImgTemplate.json Contoso" image_params["BackEnd-Docker-Img"]="VS22-BackEnd-Docker petv2-Fabric ./DownloadedTempTemplates/BackEnd-Docker-Output.json https://raw.githubusercontent.com/Evilazaro/MicrosoftDevBox/$branch/Deploy/ARMTemplates/computeGallery/backEndEngineerImgTemplateFullCustomized.json Contoso" for imageName in "${!image_params[@]}"; do diff --git a/Deploy/ARMTemplates/computeGallery/BackEnd-Customizations.ps1 b/Tasks/install-docker/install-docker.ps1 similarity index 64% rename from Deploy/ARMTemplates/computeGallery/BackEnd-Customizations.ps1 rename to Tasks/install-docker/install-docker.ps1 index 1a77f0e..f8c8152 100644 --- a/Deploy/ARMTemplates/computeGallery/BackEnd-Customizations.ps1 +++ b/Tasks/install-docker/install-docker.ps1 @@ -1,54 +1,38 @@ -# Set the execution policy -Set-ExecutionPolicy Bypass -Scope Process -Force - -function installDockerDesktop { - param ( - [string]$dockerDownloadUrl = 'https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe', - [string]$dockerTempFolderPath = 'c:\DockerTemp', - [string]$installerFileName = 'dockerInstall.exe' - ) - - Write-Output "Installing Docker Desktop" - - try { - if (-not (Test-Path $dockerTempFolderPath)) { - New-Item -ItemType Directory -Path $dockerTempFolderPath - } - - $installerFullPath = Join-Path $dockerTempFolderPath $installerFileName - - $webClient = New-Object System.Net.WebClient - $webClient.DownloadFile($dockerDownloadUrl, $installerFullPath) - - & $installerFullPath install --wait --quiet --accept-license - - Write-Output "Docker Desktop installed successfully" - } catch { - throw "Failed to install Docker Desktop: $_" - } -} - -function intallVSCode { - - Write-Output "Installing Visual Studio Code" - try { - - Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) - - choco install vscode -y - - Write-Output "Visual Studio Code installed successfully" - } catch { - throw "Failed to install Visual Studio Code: $_" - } -} - -# Execute Functions -try { - intallVSCode - installDockerDesktop - Write-Output "Script completed successfully" -} catch { - Write-Error $_.Exception.Message - throw $_.Exception -} +# Set the execution policy +Set-ExecutionPolicy Bypass -Scope Process -Force + +function installDockerDesktop { + param ( + [string]$dockerDownloadUrl = 'https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe', + [string]$dockerTempFolderPath = 'c:\DockerTemp', + [string]$installerFileName = 'dockerInstall.exe' + ) + + Write-Output "Installing Docker Desktop" + + try { + if (-not (Test-Path $dockerTempFolderPath)) { + New-Item -ItemType Directory -Path $dockerTempFolderPath + } + + $installerFullPath = Join-Path $dockerTempFolderPath $installerFileName + + $webClient = New-Object System.Net.WebClient + $webClient.DownloadFile($dockerDownloadUrl, $installerFullPath) + + & $installerFullPath install --wait --quiet --accept-license + + Write-Output "Docker Desktop installed successfully" + } catch { + throw "Failed to install Docker Desktop: $_" + } +} + +# Execute Functions +try { + installDockerDesktop + Write-Output "Script completed successfully" +} catch { + Write-Error $_.Exception.Message + throw $_.Exception +} diff --git a/Tasks/install-docker/task.yaml b/Tasks/install-docker/task.yaml new file mode 100644 index 0000000..73e1772 --- /dev/null +++ b/Tasks/install-docker/task.yaml @@ -0,0 +1,7 @@ +# This is a Visual Studio extension installation task for Dev Box. + +$schema: 1.0 +name: install-docker +description: Installs Docker Desktop for the Back End Engineers +author: Microsoft Corporation +command: ".\\install-docker.ps1" \ No newline at end of file diff --git a/Tasks/update-dependencies/task.yaml b/Tasks/update-dependencies/task.yaml new file mode 100644 index 0000000..f7731af --- /dev/null +++ b/Tasks/update-dependencies/task.yaml @@ -0,0 +1,7 @@ +# This is a Visual Studio extension installation task for Dev Box. + +$schema: 1.0 +name: update-dependencies +description: Updates the dependencies for the DevBox +author: Microsoft Corporation +command: ".\\update-dependencies.ps1" \ No newline at end of file diff --git a/Deploy/ARMTemplates/computeGallery/updateDependencies.ps1 b/Tasks/update-dependencies/update-dependencies.ps1 similarity index 100% rename from Deploy/ARMTemplates/computeGallery/updateDependencies.ps1 rename to Tasks/update-dependencies/update-dependencies.ps1