actions / runner-images

GitHub Actions runner images
MIT License
9.17k stars 2.84k forks source link

Unable to create runner using Image Name #9681

Closed slaterx closed 1 month ago

slaterx commented 1 month ago

Description

Hi Team,

I am trying to create new action runner based on latest code that creates managed image instead of VHD. Documentation states to use Managed Image Name (such as Runner-Image-Ubuntu2204), but doing as such lead to error:

ERROR: Invalid image "Runner-Image-Ubuntu2204". Use a valid image URN, custom image name, custom image id, VHD blob URI, or pick an image from ['CentOS85Gen2', 'Debian11', 'FlatcarLinuxFreeGen2', 'OpenSuseLeap154Gen2', 'RHELRaw8LVMGen2', 'SuseSles15SP3', 'Ubuntu2204', 'Win2022Datacenter', 'Win2022AzureEditionCore', 'Win2019Datacenter', 'Win2016Datacenter', 'Win2012R2Datacenter', 'Win2012Datacenter', 'Win2008R2SP1'].

If this is by design, then maybe we should consider update the documentation to use the actual custom image ID that is generated after packer completes the build?

Platforms affected

Runner images affected

Image version and build link

actions-runner-linux-x64-2.315.0

Is it regression?

no

Expected behavior

helpers/CreateAzureVMFromPackerTemplate.ps1 completes VM creation

Actual behavior

helpers/CreateAzureVMFromPackerTemplate.ps1 fails to create VM with error:


ERROR: Invalid image "Runner-Image-Ubuntu2204". Use a valid image URN, custom image name, custom image id, VHD blob URI, or pick an image from ['CentOS85Gen2', 'Debian11', 'FlatcarLinuxFreeGen2', 'OpenSuseLeap154Gen2', 'RHELRaw8LVMGen2', 'SuseSles15SP3', 'Ubuntu2204', 'Win2022Datacenter', 'Win2022AzureEditionCore', 'Win2019Datacenter', 'Win2016Datacenter', 'Win2012R2Datacenter', 'Win2012Datacenter', 'Win2008R2SP1'].

Repro steps

Install-Module -Name Az -Repository PSGallery -Force Update-AzConfig -DefaultSubscriptionForLogin * Import-Module .\helpers\CreateAzureVMFromPackerTemplate.ps1 CreateAzureVMFromPackerTemplate -SubscriptionId -ResourceGroupName -ManagedImageName "Runner-Image-Ubuntu2204" -VirtualMachineName githubvm -AdminUsername ** -AdminPassword ** -AzureLocation *

holgerjs commented 1 month ago

You can actually use the managed image name but only if you are deploying the VM into the same resource group as the image... otherwise the managed image id is required. I agree the documentation should reflect this. In fairness, it is also not clear from the az vm createdocumentation: https://learn.microsoft.com/en-us/cli/azure/vm?view=azure-cli-latest#az-vm-create

slaterx commented 1 month ago

I agree that vm creation docs requires more love and care, it is not clear how this matters.

In our case, we build the image in one disposable resource group and maintain the runners in a groomed resource group, so it doesn't make sense to build the image there. I'll have to hack CreateAzureVMFromPackerTemplate to fit my case, but would be great to have the code considering images inside and outside the resource group.

Are we allowed to propose PRs?

holgerjs commented 1 month ago

Yes, to my understanding of https://github.com/actions/runner-images/blob/main/CONTRIBUTING.md anyone can contribute and create pull requests. ^^

I would say this is by desing though since the script is only executing...

    az vm create `
        --resource-group $ResourceGroupName `
        --name $VirtualMachineName `
        --image $ManagedImageName `
        --size $vmSize `
        --admin-username $AdminUsername `
        --admin-password $AdminPassword `
        --nics $networkId `
        --subscription $subscriptionId `
        --location $AzureLocation

...and the --image parameter accepts both, the Managed Image Id as well as the name (if the image resides in the resource group that is passed in --resource-group)... Imho, changing the parameter $ManagedImageName to $ManagedImage and updating the function description would probably do it already, but I guess depends on your use case. :-)

mikhailkoliada commented 1 month ago

As dusted in the docs you should first generate the managed image and only then use the script to run packer on it, in your specific case managed image you specify does not exist in the RG you specified that is why you see this error, it is expected.