Skip to content

Commit

Permalink
feat: Install zstd on Windows runner images (#572)
Browse files Browse the repository at this point in the history
It is required for [actions/cache](https://github.com/actions/cache?tab=readme-ov-file#pre-requisites) and possibly other GitHub actions.

Resolves #571
  • Loading branch information
kichik committed May 16, 2024
1 parent f08da20 commit b805d28
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
18 changes: 17 additions & 1 deletion src/image-builders/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,23 @@ export abstract class RunnerImageComponent {
runnerCommands = [`$RUNNER_VERSION = '${runnerVersion.version}'`];
}

runnerCommands.push('mkdir C:\\hostedtoolcache\\windows');
runnerCommands = runnerCommands.concat([
// create directories
'mkdir C:\\hostedtoolcache\\windows',
'mkdir C:\\tools',
// download zstd and extract to C:\tools
'cmd /c curl -w "%{redirect_url}" -fsS https://github.com/facebook/zstd/releases/latest > $Env:TEMP\\latest-zstd',
'$LatestUrl = Get-Content $Env:TEMP\\latest-zstd',
'$ZSTD_VERSION = ($LatestUrl -Split \'/\')[-1].substring(1)',
'Invoke-WebRequest -UseBasicParsing -Uri "https://github.com/facebook/zstd/releases/download/v$ZSTD_VERSION/zstd-v$ZSTD_VERSION-win64.zip" -OutFile zstd.zip',
'Expand-Archive zstd.zip -DestinationPath C:\\tools',
'Move-Item -Path C:\\tools\\zstd-v$ZSTD_VERSION-win64\\zstd.exe C:\\tools',
'Remove-Item -LiteralPath "C:\\tools\\zstd-v$ZSTD_VERSION-win64" -Force -Recurse',
'del zstd.zip',
// add C:\tools to PATH
'$persistedPaths = [Environment]::GetEnvironmentVariable(\'Path\', [EnvironmentVariableTarget]::Machine)',
'[Environment]::SetEnvironmentVariable("PATH", $persistedPaths + ";C:\\tools", [EnvironmentVariableTarget]::Machine)',
]);

return runnerCommands.concat([
'Invoke-WebRequest -UseBasicParsing -Uri "https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-win-x64-${RUNNER_VERSION}.zip" -OutFile actions.zip',
Expand Down
4 changes: 2 additions & 2 deletions test/default.integ.snapshot/github-runners-test.assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@
}
}
},
"c7adc373a2e617c07b79256b0990e1a6ed3b10843f562ffcc8a783769346dce1": {
"03f4ef92c163cdb444cc29e5cc2d9d55caf06a401f5be2bd8485f5d58b415a53": {
"source": {
"path": "github-runners-test.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "c7adc373a2e617c07b79256b0990e1a6ed3b10843f562ffcc8a783769346dce1.json",
"objectKey": "03f4ef92c163cdb444cc29e5cc2d9d55caf06a401f5be2bd8485f5d58b415a53.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
26 changes: 24 additions & 2 deletions test/default.integ.snapshot/github-runners-test.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -2340,6 +2340,17 @@
"$LatestUrl = Get-Content $Env:TEMP\\latest-gha",
"$RUNNER_VERSION = ($LatestUrl -Split '/')[-1].substring(1)",
"mkdir C:\\hostedtoolcache\\windows",
"mkdir C:\\tools",
"cmd /c curl -w \"%{redirect_url}\" -fsS https://github.com/facebook/zstd/releases/latest > $Env:TEMP\\latest-zstd",
"$LatestUrl = Get-Content $Env:TEMP\\latest-zstd",
"$ZSTD_VERSION = ($LatestUrl -Split '/')[-1].substring(1)",
"Invoke-WebRequest -UseBasicParsing -Uri \"https://github.com/facebook/zstd/releases/download/v$ZSTD_VERSION/zstd-v$ZSTD_VERSION-win64.zip\" -OutFile zstd.zip",
"Expand-Archive zstd.zip -DestinationPath C:\\tools",
"Move-Item -Path C:\\tools\\zstd-v$ZSTD_VERSION-win64\\zstd.exe C:\\tools",
"Remove-Item -LiteralPath \"C:\\tools\\zstd-v$ZSTD_VERSION-win64\" -Force -Recurse",
"del zstd.zip",
"$persistedPaths = [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::Machine)",
"[Environment]::SetEnvironmentVariable(\"PATH\", $persistedPaths + \";C:\\tools\", [EnvironmentVariableTarget]::Machine)",
"Invoke-WebRequest -UseBasicParsing -Uri \"https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-win-x64-${RUNNER_VERSION}.zip\" -OutFile actions.zip",
"Expand-Archive actions.zip -DestinationPath C:\\actions",
"del actions.zip",
Expand All @@ -2360,7 +2371,7 @@
"WindowsImageBuilderComponent5GithubRunnerComponent34C12ED4": {
"Type": "AWS::ImageBuilder::Component",
"Properties": {
"Data": "{\"name\":\"Component 5 GithubRunner\",\"schemaVersion\":\"1.0\",\"phases\":[{\"name\":\"build\",\"steps\":[{\"name\":\"Download\",\"action\":\"S3Download\",\"inputs\":[]},{\"name\":\"Run\",\"action\":\"ExecutePowerShell\",\"inputs\":{\"commands\":[\"$ErrorActionPreference = 'Stop'\",\"$ProgressPreference = 'SilentlyContinue'\",\"Set-PSDebug -Trace 1\",\"cmd /c curl -w \\\"%{redirect_url}\\\" -fsS https://github.com/actions/runner/releases/latest > $Env:TEMP\\\\latest-gha\",\"$LatestUrl = Get-Content $Env:TEMP\\\\latest-gha\",\"$RUNNER_VERSION = ($LatestUrl -Split '/')[-1].substring(1)\",\"mkdir C:\\\\hostedtoolcache\\\\windows\",\"Invoke-WebRequest -UseBasicParsing -Uri \\\"https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-win-x64-${RUNNER_VERSION}.zip\\\" -OutFile actions.zip\",\"Expand-Archive actions.zip -DestinationPath C:\\\\actions\",\"del actions.zip\",\"echo latest | Out-File -Encoding ASCII -NoNewline C:\\\\actions\\\\RUNNER_VERSION\"]}}]}]}",
"Data": "{\"name\":\"Component 5 GithubRunner\",\"schemaVersion\":\"1.0\",\"phases\":[{\"name\":\"build\",\"steps\":[{\"name\":\"Download\",\"action\":\"S3Download\",\"inputs\":[]},{\"name\":\"Run\",\"action\":\"ExecutePowerShell\",\"inputs\":{\"commands\":[\"$ErrorActionPreference = 'Stop'\",\"$ProgressPreference = 'SilentlyContinue'\",\"Set-PSDebug -Trace 1\",\"cmd /c curl -w \\\"%{redirect_url}\\\" -fsS https://github.com/actions/runner/releases/latest > $Env:TEMP\\\\latest-gha\",\"$LatestUrl = Get-Content $Env:TEMP\\\\latest-gha\",\"$RUNNER_VERSION = ($LatestUrl -Split '/')[-1].substring(1)\",\"mkdir C:\\\\hostedtoolcache\\\\windows\",\"mkdir C:\\\\tools\",\"cmd /c curl -w \\\"%{redirect_url}\\\" -fsS https://github.com/facebook/zstd/releases/latest > $Env:TEMP\\\\latest-zstd\",\"$LatestUrl = Get-Content $Env:TEMP\\\\latest-zstd\",\"$ZSTD_VERSION = ($LatestUrl -Split '/')[-1].substring(1)\",\"Invoke-WebRequest -UseBasicParsing -Uri \\\"https://github.com/facebook/zstd/releases/download/v$ZSTD_VERSION/zstd-v$ZSTD_VERSION-win64.zip\\\" -OutFile zstd.zip\",\"Expand-Archive zstd.zip -DestinationPath C:\\\\tools\",\"Move-Item -Path C:\\\\tools\\\\zstd-v$ZSTD_VERSION-win64\\\\zstd.exe C:\\\\tools\",\"Remove-Item -LiteralPath \\\"C:\\\\tools\\\\zstd-v$ZSTD_VERSION-win64\\\" -Force -Recurse\",\"del zstd.zip\",\"$persistedPaths = [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::Machine)\",\"[Environment]::SetEnvironmentVariable(\\\"PATH\\\", $persistedPaths + \\\";C:\\\\tools\\\", [EnvironmentVariableTarget]::Machine)\",\"Invoke-WebRequest -UseBasicParsing -Uri \\\"https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-win-x64-${RUNNER_VERSION}.zip\\\" -OutFile actions.zip\",\"Expand-Archive actions.zip -DestinationPath C:\\\\actions\",\"del actions.zip\",\"echo latest | Out-File -Encoding ASCII -NoNewline C:\\\\actions\\\\RUNNER_VERSION\"]}}]}]}",
"Description": "Component 5 GithubRunner",
"Name": "github-runners-test-WindowsImageBuilder-Component5GithubRunner-7AC775C5",
"Platform": "Windows",
Expand Down Expand Up @@ -7568,6 +7579,17 @@
"$LatestUrl = Get-Content $Env:TEMP\\latest-gha",
"$RUNNER_VERSION = ($LatestUrl -Split '/')[-1].substring(1)",
"mkdir C:\\hostedtoolcache\\windows",
"mkdir C:\\tools",
"cmd /c curl -w \"%{redirect_url}\" -fsS https://github.com/facebook/zstd/releases/latest > $Env:TEMP\\latest-zstd",
"$LatestUrl = Get-Content $Env:TEMP\\latest-zstd",
"$ZSTD_VERSION = ($LatestUrl -Split '/')[-1].substring(1)",
"Invoke-WebRequest -UseBasicParsing -Uri \"https://github.com/facebook/zstd/releases/download/v$ZSTD_VERSION/zstd-v$ZSTD_VERSION-win64.zip\" -OutFile zstd.zip",
"Expand-Archive zstd.zip -DestinationPath C:\\tools",
"Move-Item -Path C:\\tools\\zstd-v$ZSTD_VERSION-win64\\zstd.exe C:\\tools",
"Remove-Item -LiteralPath \"C:\\tools\\zstd-v$ZSTD_VERSION-win64\" -Force -Recurse",
"del zstd.zip",
"$persistedPaths = [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::Machine)",
"[Environment]::SetEnvironmentVariable(\"PATH\", $persistedPaths + \";C:\\tools\", [EnvironmentVariableTarget]::Machine)",
"Invoke-WebRequest -UseBasicParsing -Uri \"https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-win-x64-${RUNNER_VERSION}.zip\" -OutFile actions.zip",
"Expand-Archive actions.zip -DestinationPath C:\\actions",
"del actions.zip",
Expand All @@ -7588,7 +7610,7 @@
"WindowsEC2BuilderComponent6GithubRunnerComponent6342E200": {
"Type": "AWS::ImageBuilder::Component",
"Properties": {
"Data": "{\"name\":\"Component 6 GithubRunner\",\"schemaVersion\":\"1.0\",\"phases\":[{\"name\":\"build\",\"steps\":[{\"name\":\"Download\",\"action\":\"S3Download\",\"inputs\":[]},{\"name\":\"Run\",\"action\":\"ExecutePowerShell\",\"inputs\":{\"commands\":[\"$ErrorActionPreference = 'Stop'\",\"$ProgressPreference = 'SilentlyContinue'\",\"Set-PSDebug -Trace 1\",\"cmd /c curl -w \\\"%{redirect_url}\\\" -fsS https://github.com/actions/runner/releases/latest > $Env:TEMP\\\\latest-gha\",\"$LatestUrl = Get-Content $Env:TEMP\\\\latest-gha\",\"$RUNNER_VERSION = ($LatestUrl -Split '/')[-1].substring(1)\",\"mkdir C:\\\\hostedtoolcache\\\\windows\",\"Invoke-WebRequest -UseBasicParsing -Uri \\\"https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-win-x64-${RUNNER_VERSION}.zip\\\" -OutFile actions.zip\",\"Expand-Archive actions.zip -DestinationPath C:\\\\actions\",\"del actions.zip\",\"echo latest | Out-File -Encoding ASCII -NoNewline C:\\\\actions\\\\RUNNER_VERSION\"]}}]}]}",
"Data": "{\"name\":\"Component 6 GithubRunner\",\"schemaVersion\":\"1.0\",\"phases\":[{\"name\":\"build\",\"steps\":[{\"name\":\"Download\",\"action\":\"S3Download\",\"inputs\":[]},{\"name\":\"Run\",\"action\":\"ExecutePowerShell\",\"inputs\":{\"commands\":[\"$ErrorActionPreference = 'Stop'\",\"$ProgressPreference = 'SilentlyContinue'\",\"Set-PSDebug -Trace 1\",\"cmd /c curl -w \\\"%{redirect_url}\\\" -fsS https://github.com/actions/runner/releases/latest > $Env:TEMP\\\\latest-gha\",\"$LatestUrl = Get-Content $Env:TEMP\\\\latest-gha\",\"$RUNNER_VERSION = ($LatestUrl -Split '/')[-1].substring(1)\",\"mkdir C:\\\\hostedtoolcache\\\\windows\",\"mkdir C:\\\\tools\",\"cmd /c curl -w \\\"%{redirect_url}\\\" -fsS https://github.com/facebook/zstd/releases/latest > $Env:TEMP\\\\latest-zstd\",\"$LatestUrl = Get-Content $Env:TEMP\\\\latest-zstd\",\"$ZSTD_VERSION = ($LatestUrl -Split '/')[-1].substring(1)\",\"Invoke-WebRequest -UseBasicParsing -Uri \\\"https://github.com/facebook/zstd/releases/download/v$ZSTD_VERSION/zstd-v$ZSTD_VERSION-win64.zip\\\" -OutFile zstd.zip\",\"Expand-Archive zstd.zip -DestinationPath C:\\\\tools\",\"Move-Item -Path C:\\\\tools\\\\zstd-v$ZSTD_VERSION-win64\\\\zstd.exe C:\\\\tools\",\"Remove-Item -LiteralPath \\\"C:\\\\tools\\\\zstd-v$ZSTD_VERSION-win64\\\" -Force -Recurse\",\"del zstd.zip\",\"$persistedPaths = [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::Machine)\",\"[Environment]::SetEnvironmentVariable(\\\"PATH\\\", $persistedPaths + \\\";C:\\\\tools\\\", [EnvironmentVariableTarget]::Machine)\",\"Invoke-WebRequest -UseBasicParsing -Uri \\\"https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-win-x64-${RUNNER_VERSION}.zip\\\" -OutFile actions.zip\",\"Expand-Archive actions.zip -DestinationPath C:\\\\actions\",\"del actions.zip\",\"echo latest | Out-File -Encoding ASCII -NoNewline C:\\\\actions\\\\RUNNER_VERSION\"]}}]}]}",
"Description": "Component 6 GithubRunner",
"Name": "github-runners-test-WindowsEC2Builder-Component6GithubRunner-0FBD0A17",
"Platform": "Windows",
Expand Down

0 comments on commit b805d28

Please sign in to comment.