Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image24 #543

Merged
merged 6 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 100 additions & 84 deletions .github/workflows/BuildMissingImages.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
name: Build missing images (after new windows updates)

on:
schedule:
- cron: '0 5 * * *'
workflow_dispatch:
inputs:
GenericTag:
description: Generic Tag (leave empty to use value in generic/tag.txt)
required: false
default: ''
Machines:
description: Number of machines to create
Agents:
description: Number of agents to create (0 = use existing)
required: false
default: '2'
PushToProd:
Expand All @@ -24,7 +22,6 @@ env:
ARMbranch: "master"
ARMtemplate: "buildagent"


permissions:
contents: read

Expand All @@ -48,7 +45,7 @@ jobs:
run: |
$erroractionpreference = "STOP"
try {
$unsupportedWindowsVersions = @("10.0.18363.*","10.0.18362.*")
$unsupportedWindowsVersions = @("10.0.14300.*","10.0.16299.*","10.0.18363.*","10.0.18362.*","10.0.17134.*") # "10.0.14393.*","10.0.19041.*","10.0.19042.*"
Set-Location "generic"
$genericTag = ''
if ($env:GITHUB_EVENT_NAME -eq "workflow_dispatch") {
Expand Down Expand Up @@ -123,76 +120,77 @@ jobs:
uses: azure/powershell@v1
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
machines: ${{ github.event.inputs.Machines }}
agents: ${{ github.event.inputs.Agents }}
with:
azPSVersion: "latest"
inlineScript: |
$resGroup = $env:resGroup
$resLocation = $env:resLocation
$repo = $env:GITHUB_REPOSITORY
$machines = [int]$env:machines
Write-Host "Resource Group is $resGroup"
$resourceGroup = Get-AzResourceGroup -name $resGroup -ErrorAction Ignore
if ($resourceGroup) {
Write-Host "Removing Resource Group $resGroup"
Remove-AzResourceGroup -Name $resGroup -Force | Out-Host
Write-Host "Done"
if ($env:agents -eq "0") {
Write-Host "Using existing agents"
}
$runners = (gh api /repos/$repo/actions/runners | ConvertFrom-Json).runners
$runners | Where-Object { $_.status -eq "offline" } | ForEach-Object {
Write-host "Unregistering runner $($_.name)"
$id = $_.id
gh api -X DELETE /repos/$repo/actions/runners/$id
Write-Host "Done"
}
Write-Host "Creating resource group $resGroup in $resLocation"
$resourceGroup = New-AzResourceGroup -Name $resGroup -Location $resLocation -Force
Write-Host "Done"
1..$machines | ForEach-Object {
# Deployment
$no = $_

# ARM template
$templateUri = "https://raw.githubusercontent.com/microsoft/nav-arm-templates/$($env:ARMbranch)/$($env:ARMtemplate).json"

$registrationToken = (gh api -X POST /repos/$repo/actions/runners/registration-token | ConvertFrom-Json).token
$headers = @{
"Accept" = "application/json"
"Authorization" = "token $env:GH_TOKEN"
else {
$resGroup = $env:resGroup
$resLocation = $env:resLocation
$repo = $env:GITHUB_REPOSITORY
$agents = [int]$env:agents
Write-Host "Resource Group is $resGroup"
$resourceGroup = Get-AzResourceGroup -name $resGroup -ErrorAction Ignore
if ($resourceGroup) {
Write-Host "Removing Resource Group $resGroup"
Remove-AzResourceGroup -Name $resGroup -Force | Out-Host
Write-Host "Done"
}

$uri = "https://api.github.com/repos/actions/runner/releases"
$result = Invoke-WebRequest -UseBasicParsing -Headers $headers -Uri $uri
$releases = $result.Content | ConvertFrom-Json
$asset = $releases[0].assets | Where-Object { $_.name -like "actions-runner-win-x64-*.*.?.zip" }

$Parameters = @{
"VmName" = "$resgroup$no"
"Remotedesktopaccess" = "-"
"OperatingSystem" = "Windows Server 2022"
"VmSize" = "Standard_D4as_v5"
"OSDiskSize" = 128
"StorageAccountType" = "Premium_LRS"
"AdminPassword" = [SecureString](ConvertTo-SecureString -String $env:GH_TOKEN -AsPlainText -Force)
"Count" = 1
"Token" = $registrationToken
"Organization" = "https://github.com/$repo"
"LabelsOrPool" = "buildgeneric"
"AgentUrl" = $asset.browser_download_url
"InstallHyperV" = "Yes"
"RunInsideDocker" = "No"
"FinalSetupScriptUrl" = "additional-installforbuildagent.ps1"
$runners = (gh api /repos/$repo/actions/runners | ConvertFrom-Json).runners
$runners | Where-Object { $_.status -eq "offline" } | ForEach-Object {
Write-host "Unregistering runner $($_.name)"
$id = $_.id
gh api -X DELETE /repos/$repo/actions/runners/$id
Write-Host "Done"
}

$err = $resourceGroup | Test-AzResourceGroupDeployment -TemplateUri $templateUri -TemplateParameterObject $Parameters
if ($err) {
$err
throw "stop"
Write-Host "Creating resource group $resGroup in $resLocation"
$resourceGroup = New-AzResourceGroup -Name $resGroup -Location $resLocation -Force
Write-Host "Done"
1..$agents | ForEach-Object {
# Deployment
$no = $_
# ARM template
$templateUri = "https://raw.githubusercontent.com/microsoft/nav-arm-templates/$($env:ARMbranch)/$($env:ARMtemplate).json"
$registrationToken = (gh api -X POST /repos/$repo/actions/runners/registration-token | ConvertFrom-Json).token
$headers = @{
"Accept" = "application/json"
"Authorization" = "token $env:GH_TOKEN"
}
$uri = "https://api.github.com/repos/actions/runner/releases"
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$result = Invoke-WebRequest -UseBasicParsing -Headers $headers -Uri $uri
$releases = $result.Content | ConvertFrom-Json
$asset = $releases[0].assets | Where-Object { $_.name -like "actions-runner-win-x64-*.*.?.zip" }
$Parameters = @{
"VmName" = "$resgroup$no"
"Remotedesktopaccess" = "-"
"OperatingSystem" = "Windows Server 2022"
"VmSize" = "Standard_D4as_v5"
"OSDiskSize" = 128
"StorageAccountType" = "Premium_LRS"
"AdminPassword" = [SecureString](ConvertTo-SecureString -String $env:GH_TOKEN -AsPlainText -Force)
"Count" = 1
"Token" = $registrationToken
"Organization" = "https://github.com/$repo"
"LabelsOrPool" = "buildgeneric"
"AgentUrl" = $asset.browser_download_url
"InstallHyperV" = "Yes"
"RunInsideDocker" = "No"
"FinalSetupScriptUrl" = "additional-installforbuildagent.ps1"
}
$err = $resourceGroup | Test-AzResourceGroupDeployment -TemplateUri $templateUri -TemplateParameterObject $Parameters
if ($err) {
$err
throw "stop"
}
Write-Host "Creating Azure VM $($parameters.VmName)"
$resourceGroup | New-AzResourceGroupDeployment -TemplateUri $templateUri -TemplateParameterObject $Parameters -Name $Parameters.vmName -ErrorAction Ignore -AsJob
Start-Sleep -Seconds 60
Write-Host "VM creation started"
}
Write-Host "Creating Azure VM $($parameters.VmName)"
$resourceGroup | New-AzResourceGroupDeployment -TemplateUri $templateUri -TemplateParameterObject $Parameters -Name $Parameters.vmName -ErrorAction Ignore -AsJob
Start-Sleep -Seconds 60
Write-Host "VM creation started"
}

Generic:
Expand Down Expand Up @@ -278,6 +276,12 @@ jobs:
docker tag $image $_
docker push $_
}
$newtags | ForEach-Object {
docker rmi $_
}
docker rmi $image
docker rmi $baseimage
docker system prune --force
}
catch {
Write-Host "::Error::Error building images. Error was $($_.Exception.Message)"
Expand Down Expand Up @@ -367,6 +371,12 @@ jobs:
docker tag $image $_
docker push $_
}
$newtags | ForEach-Object {
docker rmi $_
}
docker rmi $image
docker rmi $baseimage
docker system prune --force
}
catch {
Write-Host "::Error::Error building images. Error was $($_.Exception.Message)"
Expand All @@ -388,23 +398,29 @@ jobs:
uses: azure/powershell@v1
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
agents: ${{ github.event.inputs.Agents }}
with:
azPSVersion: "latest"
inlineScript: |
$resGroup = $env:resGroup
$resLocation = $env:resLocation
$repo = $env:GITHUB_REPOSITORY
Write-Host "Resource Group is $resGroup"
$resourceGroup = Get-AzResourceGroup -name $resGroup -ErrorAction Ignore
if ($resourceGroup) {
Write-Host "Removing Resource Group $resGroup"
Remove-AzResourceGroup -Name $resGroup -Force | Out-Host
Write-Host "Done"
if ($env:agents -eq "0") {
Write-Host "Used existing agents"
}
$runners = (gh api /repos/$repo/actions/runners | ConvertFrom-Json).runners
$runners | Where-Object { $_.status -eq "offline" } | ForEach-Object {
Write-host "Unregistering runner $($_.name)"
$id = $_.id
gh api -X DELETE /repos/$repo/actions/runners/$id
Write-Host "Done"
else {
$resGroup = $env:resGroup
$resLocation = $env:resLocation
$repo = $env:GITHUB_REPOSITORY
Write-Host "Resource Group is $resGroup"
$resourceGroup = Get-AzResourceGroup -name $resGroup -ErrorAction Ignore
if ($resourceGroup) {
Write-Host "Removing Resource Group $resGroup"
Remove-AzResourceGroup -Name $resGroup -Force | Out-Host
Write-Host "Done"
}
$runners = (gh api /repos/$repo/actions/runners | ConvertFrom-Json).runners
$runners | Where-Object { $_.status -eq "offline" } | ForEach-Object {
Write-host "Unregistering runner $($_.name)"
$id = $_.id
gh api -X DELETE /repos/$repo/actions/runners/$id
Write-Host "Done"
}
}
6 changes: 4 additions & 2 deletions generic/DOCKERFILE
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPref
# Install the prerequisites first to be able reuse the cache when changing only the scripts.
# Temporary workaround for Windows DNS client weirdness (need to check if the issue is still present or not).

RUN Add-WindowsFeature Web-Server,web-AppInit,web-Asp-Net45,web-Windows-Auth,web-Dyn-Compression,web-WebSockets; \
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 ; \
Add-WindowsFeature Web-Server,web-AppInit,web-Asp-Net45,web-Windows-Auth,web-Dyn-Compression,web-WebSockets; \
Stop-Service 'W3SVC' ; \
Set-Service 'W3SVC' -startuptype manual ; \
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters' -Name ServerPriorityTimeLimit -Value 0 -Type DWord; \
Expand All @@ -32,7 +33,8 @@ RUN Add-WindowsFeature Web-Server,web-AppInit,web-Asp-Net45,web-Windows-Auth,web

COPY Run /Run/

RUN Invoke-WebRequest -Uri 'https://bcdocker.blob.core.windows.net/public/nav-docker-install.zip' -OutFile 'nav-docker-install.zip' ; \
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 ; \
Invoke-WebRequest -Uri 'https://bcdocker.blob.core.windows.net/public/nav-docker-install.zip' -OutFile 'nav-docker-install.zip' ; \
[Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.Filesystem') | Out-Null ; \
[System.IO.Compression.ZipFile]::ExtractToDirectory('.\nav-docker-install.zip', 'c:\run') ; \
Remove-Item -Force 'nav-docker-install.zip' ; \
Expand Down
3 changes: 2 additions & 1 deletion generic/DOCKERFILE-filesonly
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPref

COPY Run /Run/

RUN Invoke-WebRequest -Uri 'https://bcdocker.blob.core.windows.net/public/nav-docker-install.zip' -OutFile 'nav-docker-install.zip' ; \
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 ; \
Invoke-WebRequest -Uri 'https://bcdocker.blob.core.windows.net/public/nav-docker-install.zip' -OutFile 'nav-docker-install.zip' ; \
[Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.Filesystem') | Out-Null ; \
[System.IO.Compression.ZipFile]::ExtractToDirectory('.\nav-docker-install.zip', 'c:\run') ; \
Remove-Item -Force 'nav-docker-install.zip' ; \
Expand Down
Loading