Skip to content

Commit 3971cc2

Browse files
authored
feature: add a comment to the PR when there are any changes that would change what's cached on windows VHDs (#5994)
1 parent 60e2f92 commit 3971cc2

File tree

5 files changed

+257
-3
lines changed

5 files changed

+257
-3
lines changed

.github/workflows/validate-windows-ut.yml

+61
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ jobs:
88
steps:
99
- name: Check out repository code
1010
uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 1
1113
- name: Perform a Pester test from the parts/windows/*.tests.ps1 file
1214
shell: powershell
1315
run: |
@@ -21,3 +23,62 @@ jobs:
2123
run: |
2224
Install-Module -Name powershell-yaml -Force
2325
Invoke-Pester staging/cse/windows/*.tests.ps1 -Passthru
26+
27+
compare-components-output:
28+
name: Compare components.json for each windows VHD
29+
runs-on: windows-latest
30+
permissions:
31+
pull-requests: write
32+
steps:
33+
- name: Check out repository code
34+
uses: actions/checkout@v4
35+
with:
36+
ref: master
37+
path: master
38+
fetch-depth: 1
39+
40+
- name: Check out repository code
41+
uses: actions/checkout@v4
42+
with:
43+
path: pr
44+
fetch-depth: 1
45+
46+
- name: Produce vhd files - master
47+
shell: pwsh
48+
run: |
49+
cd pr
50+
mkdir vhd_files
51+
52+
pwsh -c vhdbuilder/scripts/windows/generate_cached_stuff_list.ps1 vhd_files vhdbuilder/packer/windows/components_json_helpers.ps1 ../master/vhdbuilder/packer/windows/windows_settings.json ../master/parts/common/components.json
53+
54+
git add vhd_files
55+
git config user.email "[email protected]"
56+
git config user.name "Your Name"
57+
git commit -m "versions of files from master"
58+
59+
pwsh -c vhdbuilder/scripts/windows/generate_cached_stuff_list.ps1 vhd_files vhdbuilder/packer/windows/components_json_helpers.ps1 vhdbuilder/packer/windows/windows_settings.json parts/common/components.json
60+
61+
mkdir -p ../.github/workflows
62+
$diffFile = "../.github/workflows/diff.md"
63+
64+
git diff --quiet
65+
if ( $LASTEXITCODE -eq "0" ) {
66+
Write-Output "No changes to cached containers or packages on Windows VHDs" > $diffFile
67+
} else {
68+
Write-Output "Changes cached containers or packages on windows VHDs" > $diffFile
69+
Write-Output "" >> $diffFile
70+
Write-Output '```diff' >> $diffFile
71+
git diff >> $diffFile
72+
Write-Output '```' >> $diffFile
73+
}
74+
75+
dir $diffFile
76+
Get-Content $diffFile
77+
78+
- name: Add comment to PR
79+
uses: NejcZdovc/comment-pr@v2
80+
with:
81+
file: "diff.md"
82+
identifier: "WINDOWS_VHD_CONTENT_DIFF"
83+
env:
84+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

parts/parts.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package parts provides the the embedded templates used in Linux and Windows systems.
1+
// Package parts provides the embedded templates used in Linux and Windows systems.
22
package parts
33

44
import "embed"

vhdbuilder/packer/windows/components_json_helpers.ps1

+25
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,29 @@ function GetDefenderUpdateInfoUrl {
279279
)
280280

281281
return $windowsSettingsContent.WindowsDefenderInfo.DefenderUpdateInfoUrl
282+
}
283+
284+
function GetAllCachedThings {
285+
Param(
286+
[Parameter(Mandatory = $true)][Object]
287+
$componentsJsonContent,
288+
[Parameter(Mandatory = $true)][Object]
289+
$windowsSettingsContent
290+
)
291+
292+
$items = GetComponentsFromComponentsJson $componentsJsonContent
293+
$packages = GetPackagesFromComponentsJson $componentsJsonContent
294+
$regKeys = GetRegKeysToApply $windowsSettingsContent
295+
296+
foreach ($packageName in $packages.keys) {
297+
foreach ($package in $packages[$packageName]) {
298+
$items += $packageName + ": " + $package
299+
}
300+
}
301+
302+
foreach ($regKey in $regKeys) {
303+
$items += $regKey.Path + "\" + $regKey.Name + "=" + $regKey.Value
304+
}
305+
306+
return ($items | Sort-Object)
282307
}

vhdbuilder/packer/windows/components_json_helpers.tests.ps1

+105-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,109 @@ Describe 'SafeReplaceString' {
3333

3434

3535

36+
Describe 'Tests of GetAllCachedThings ' {
37+
BeforeEach {
38+
$windowsSettingsTestString = '{
39+
"WindowsBaseVersions": {
40+
"2019": {
41+
"base_image_sku": "2019-Datacenter-Core-smalldisk",
42+
"windows_image_name": "windows-2019",
43+
"base_image_version": "17763.6893.250210",
44+
"patches_to_apply": [{"id": "patchid", "url": "patch_url"}]
45+
},
46+
"23H2-gen2": {
47+
"base_image_sku": "2019-Datacenter-Core-smalldisk",
48+
"windows_image_name": "windows-2019",
49+
"base_image_version": "17763.6893.250210",
50+
"patches_to_apply": [{"id": "patchid", "url": "patch_url"}]
51+
}
52+
},
53+
"WindowsRegistryKeys": [
54+
{
55+
"Comment": "Enables DNS resolution of SMB shares for containerD: # https://github.com/kubernetes-sigs/windows-gmsa/issues/30#issuecomment-802240945",
56+
"WindowsSkuMatch": "*",
57+
"Path": "HKLM:\\SYSTEM\\CurrentControlSet\\Services\\hns\\State",
58+
"Name": "EnableCompartmentNamespace",
59+
"Value": "1",
60+
"Type": "DWORD"
61+
}
62+
]
63+
}'
64+
$windowsSettings = echo $windowsSettingsTestString | ConvertFrom-Json
65+
66+
$componentsJsonTestString = '{
67+
"ContainerImages": [
68+
{
69+
"downloadURL": "mcr.microsoft.com/container/with/seperate/win/and/linux/versions:*",
70+
"amd64OnlyVersions": [],
71+
"multiArchVersionsV2": [],
72+
"windowsVersions": [
73+
{
74+
"renovateTag": "registry=https://mcr.microsoft.com, name=oss/kubernetes/pause",
75+
"latestVersion": "win-version"
76+
},{
77+
"renovateTag": "registry=https://mcr.microsoft.com, name=oss/kubernetes/pause",
78+
"latestVersion": "other-version"
79+
}
80+
]
81+
}],
82+
"Packages": [
83+
{
84+
"windowsDownloadLocation": "c:\\akse-cache\\",
85+
"downloadLocation": null,
86+
"downloadUris": {
87+
"windows": {
88+
"default": {
89+
"versionsV2": [
90+
{
91+
"renovateTag": "<DO_NOT_UPDATE>",
92+
"latestVersion": "0.0.50",
93+
"previousLatestVersion": "0.0.51"
94+
}
95+
],
96+
"downloadURL": "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v${version}.zip"
97+
}
98+
}
99+
}
100+
}
101+
]}'
102+
$componentsJson = echo $componentsJsonTestString | ConvertFrom-Json
103+
}
104+
105+
it 'has a component in it' {
106+
$windowsSku = "2019-containerd"
107+
108+
$allpackages = GetAllCachedThings $componentsJson $windowsSettings
109+
110+
$allpackages | Should -Contain "mcr.microsoft.com/container/with/seperate/win/and/linux/versions:win-version"
111+
}
112+
113+
it 'has a package in it' {
114+
$windowsSku = "2019-containerd"
115+
116+
$allpackages = GetAllCachedThings $componentsJson $windowsSettings
117+
118+
$allpackages | Should -Contain "c:\akse-cache\: https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v0.0.50.zip"
119+
}
120+
121+
it 'has a reg key in it' {
122+
$windowsSku = "2019-containerd"
123+
124+
$allpackages = GetAllCachedThings $componentsJson $windowsSettings
125+
126+
$allpackages | Should -Contain "HKLM:\SYSTEM\CurrentControlSet\Services\hns\State\EnableCompartmentNamespace=1"
127+
}
128+
129+
it 'is sorted' {
130+
$windowsSku = "2019-containerd"
131+
132+
$allpackages = GetAllCachedThings $componentsJson $windowsSettings
133+
134+
$allpackages | Should -Be ( $allpackages | Sort-Object )
135+
}
136+
}
137+
138+
36139
Describe 'GetWindowsDefenderInfo' {
37140
BeforeEach {
38141
$testString = '{
@@ -560,7 +663,7 @@ Describe 'Gets The Versions' {
560663
)
561664
$componentsJson.ContainerImages[0].downloadURL = "mcr.microsoft.com/oss/kubernetes/autoscaler/`${CPU_ARCH}/addon-resizer:*"
562665

563-
$CPU_ARCH="x86"
666+
$CPU_ARCH = "x86"
564667
$components = GetComponentsFromComponentsJson $componentsJson
565668

566669
$components | Should -HaveCount 1
@@ -575,7 +678,7 @@ Describe 'Gets The Versions' {
575678
)
576679
$componentsJson.ContainerImages[0].downloadURL = "mcr.microsoft.com/oss/kubernetes/autoscaler/`${varvarvar}/addon-resizer:*"
577680

578-
$varvarvar="x86"
681+
$varvarvar = "x86"
579682
$components = GetComponentsFromComponentsJson $componentsJson
580683

581684
$components | Should -HaveCount 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
param(
3+
[string]
4+
$outputDirParam,
5+
[string]
6+
$helpersFileParam,
7+
[string]
8+
$windowsSettingsFileParam,
9+
[string]
10+
$componentsJsonFileParam
11+
)
12+
13+
$HelpersFile = "vhdbuilder/packer/windows/components_json_helpers.ps1"
14+
$WindowsSettingsFile = "vhdbuilder/packer/windows/windows_settings.json"
15+
$ComponentsJsonFile = "parts/common/components.json"
16+
$outputDir = "temp"
17+
18+
if (![string]::IsNullOrEmpty($outputDirParam))
19+
{
20+
Write-Output "Setting output dir to to to $outputDirParam"
21+
$outputDir = $outputDirParam
22+
} else {
23+
Write-Output "using default output dir: $outputDir"
24+
}
25+
26+
if (![string]::IsNullOrEmpty($helpersFileParam))
27+
{
28+
Write-Output "Setting helpers file to $helpersFileParam"
29+
$HelpersFile = $helpersFileParam
30+
} else {
31+
Write-Output "using default helpers file: $HelpersFile"
32+
}
33+
34+
if (![string]::IsNullOrEmpty($windowsSettingsFileParam))
35+
{
36+
Write-Output "Setting windows settings file to $windowsSettingsFileParam"
37+
$WindowsSettingsFile = $windowsSettingsFileParam
38+
} else {
39+
Write-Output "using default windows settings: $WindowsSettingsFile"
40+
}
41+
42+
if (![string]::IsNullOrEmpty($componentsJsonFileParam))
43+
{
44+
Write-Output "Setting components json file to to $componentsJsonFileParam"
45+
$ComponentsJsonFile = $componentsJsonFileParam
46+
} else {
47+
Write-Output "using default components json: $ComponentsJsonFile"
48+
}
49+
50+
. "$HelpersFile"
51+
52+
$componentsJson = Get-Content $ComponentsJsonFile | Out-String | ConvertFrom-Json
53+
$windowsSettingsJson = Get-Content $WindowsSettingsFile | Out-String | ConvertFrom-Json
54+
$BaseVersions = GetWindowsBaseVersions $windowsSettingsJson
55+
56+
foreach ($WindowsSku in $BaseVersions)
57+
{
58+
$cachedThings = GetAllCachedThings $componentsJson $windowsSettingsJson
59+
60+
$fileName = "${outputDir}/${WindowsSku}.txt"
61+
Write-Output "Creating file $fileName"
62+
Write-Output $WindowsSku > $fileName
63+
64+
echo $cachedThings | ConvertTo-Json | Write-Output >> $fileName
65+
}

0 commit comments

Comments
 (0)