I am using packer to generate images in Azure DevOps. This is the github source that I am using: https://github.com/actions/runner-images.
I am using Ubuntu-20.04 and am at the release ubuntu20/20240603. However, when I deploy the pipeline, I am repetedly getting the following error by Nodejs part:
this is the command that I am using to buil image:
this is my install-nodejs.sh script where Nodejs is installed:
sudo packer build --force -on-error=cleanup -var "client_id=$(VAR_CLIENT_ID)" -var "client_secret=$CLIENTSECRET" -var "template_dir=$template_dir" -var "sources_dir=$SOURCES_DIR" -var "sig_image_version=$(IMAGE_VERSION)" "$template_dir/packer/azure_devops_agent_basic/ubuntu2004.pkr.hcl"
# Source the helpers for use with the script
source $HELPER_SCRIPTS/install.sh
# Install default Node.js
default_version=$(get_toolset_value '.node.default')
curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n -o ~/n
bash ~/n $default_version
# Install node modules
node_modules=$(get_toolset_value '.node_modules[].name')
npm install -g $node_modules
echo "Creating the symlink for [now] command to vercel CLI"
ln -s /usr/local/bin/vercel /usr/local/bin/now
# fix global modules installation as regular user
# related issue https://github.com/actions/runner-images/issues/3727
sudo chmod -R 777 /usr/local/lib/node_modules
sudo chmod -R 777 /usr/local/bin
rm -rf ~/n
invoke_tests "Node" "Node.js"
This is my Node.Test.ps1 script:
Describe "Node.js" {
$binaries = @("node")
$module_commands = if ((Get-ToolsetContent).node_modules) {
(Get-ToolsetContent).node_modules | ForEach-Object { $_.command }
}
else {
@()
}
$testCases = $binaries + $module_commands | ForEach-Object { @{NodeCommand = $_ } }
It "<NodeCommand>" -TestCases $testCases {
"$NodeCommand --version" | Should -ReturnZeroExitCode
}
It "Node.js version should correspond to the version in the toolset" {
node --version | Should -BeLike "v$((Get-ToolsetContent).node.default).*"
}
}
My toolset.json script code block where modules are defined:
"node": {
"default": "18",
"node_modules": [
{
"name": "yarn",
"command": "yarn"
}
]
},
and this is Toolset.Tests.ps1 script for tests:
Describe "Toolset" {
$tools = (Get-ToolsetContent).toolcache
$toolsExecutables = @{
Python = @{
tools = @("python", "bin/pip")
command = "--version"
}
node = @{
tools = @("bin/node", "bin/npm")
command = "--version"
}
PyPy = @{
tools = @("bin/python", "bin/pip")
command = "--version"
}
go = @{
tools = @("bin/go")
command = "version"
}
Ruby = @{
tools = @("bin/ruby")
command = "--version"
}
CodeQL = @{
tools = @("codeql/codeql")
command = "version"
}
}
foreach ($tool in $tools) {
$toolName = $tool.Name
Context "$toolName" {
$toolExecs = $toolsExecutables[$toolName]
foreach ($version in $tool.versions) {
# Add wildcard if missing
if ($version.Split(".").Length -lt 3) {
$version += ".*"
}
$expectedVersionPath = Join-Path $env:AGENT_TOOLSDIRECTORY $toolName $version
It "$version version folder exists" -TestCases @{ ExpectedVersionPath = $expectedVersionPath } {
$ExpectedVersionPath | Should -Exist
}
$foundVersion = Get-Item $expectedVersionPath `
| Sort-Object -Property { [SemVer]$_.name } -Descending `
| Select-Object -First 1
$foundVersionPath = Join-Path $foundVersion $tool.arch
if ($toolExecs) {
foreach ($executable in $toolExecs["tools"]) {
$executablePath = Join-Path $foundVersionPath $executable
It "Validate $executable" -TestCases @{ExecutablePath = $executablePath } {
$ExecutablePath | Should -Exist
}
}
}
}
}
}
}
I had also edited the Node.Tests.ps1 script inorder for it to not show an error if iterating null and also added the yarn module even though I dont need it.
I know this is a very specific and complicated problem but I am not able to find any solution for this. Would be nice if someonw know how to solve it or give pointers :’)