YannickRe / azuredevops-buildagents

Generate self-hosted build agents for Azure DevOps, just like Microsoft does.
MIT License
151 stars 90 forks source link

Need to install PWSH and Packer #83

Closed musekmkr closed 5 months ago

musekmkr commented 7 months ago

I am not sure if I am missing something, but I needed to add a couple of steps to the yaml template to install PS Core and Packer on the Linux agents I'm using to create the build agents. I'm using Ubuntu Server 22.04 LTS, which clearly doesn't have this software installed by default. Just curious how everyone else is doing this?

- bash: |
    sudo apt-get update
    sudo apt-get install -y wget apt-transport-https software-properties-common
    source /etc/os-release
    wget -q https://packages.microsoft.com/config/ubuntu/$VERSION_ID/packages-microsoft-prod.deb
    sudo dpkg -i packages-microsoft-prod.deb
    rm packages-microsoft-prod.deb
    sudo apt-get update
    sudo apt-get install -y powershell
  displayName: "Install PowerShell Core"

- bash: |
    wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
    echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
    sudo apt update && sudo apt install packer
  displayName: "Install Packer"
musekmkr commented 7 months ago

I may have jumped the gun on this. Seems I just didn't quite follow the instructions from MS on creating a self-hosted agent. SO, I am also installing Git and the Az module and I am much closer now. Just getting these errors on build about an hour in.

    azure-arm.build_image:    [-] Validate bin/npm 11ms (8ms|3ms)
    azure-arm.build_image:     Expected path '/opt/hostedtoolcache/node/18.20.0/x64/bin/npm' to exist, but it did not exist.
    azure-arm.build_image:     at $ExecutablePath | Should -Exist, /imagegeneration/tests/Toolset.Tests.ps1:58
    azure-arm.build_image:     at <ScriptBlock>, /imagegeneration/tests/Toolset.Tests.ps1:58
    azure-arm.build_image:    [+] 20.*.* version folder exists 8ms (5ms|3ms)
    azure-arm.build_image:    [-] Validate bin/node 10ms (7ms|3ms)
    azure-arm.build_image:     Expected path '/opt/hostedtoolcache/node/20.12.0/x64/bin/node' to exist, but it did not exist.
    azure-arm.build_image:     at $ExecutablePath | Should -Exist, /imagegeneration/tests/Toolset.Tests.ps1:58
    azure-arm.build_image:     at <ScriptBlock>, /imagegeneration/tests/Toolset.Tests.ps1:58
YannickRe commented 6 months ago

It seems like you are trying to build these images on your current, already existing Build Agent. You might need to figure out what tools you need installed there, not sure this is documented somewhere. The easiest way is to build your first images using a Microsoft Hosted Agent, as it has all the tools necessary.

erik-de-bont commented 6 months ago

I have created a seperate scaleset to build the Agent Pool image.

I use the Ubuntu 22.04 image and under the "Operating System" option of the scaleset in the Azure Portal, I add the script below in the "User Data" field. This script will install the required tooling (Powershell, Packer etc..) when instances of the scale set are deployed to build Agent Pool images,

image

#cloud-config
# More info: https://learn.microsoft.com/en-us/azure/virtual-machines/linux/tutorial-automate-vm-deployment

bootcmd:
  - mkdir -p /etc/systemd/system/walinuxagent.service.d
  - echo "[Unit]\nAfter=cloud-final.service" > /etc/systemd/system/walinuxagent.service.d/override.conf
  - sed "s/After=multi-user.target//g" /lib/systemd/system/cloud-final.service > /etc/systemd/system/cloud-final.service
  - systemctl daemon-reload

disk_setup:
  ephemeral0:
    table_type: gpt
    layout: [66, [33,82]]
    overwrite: true

fs_setup:
  - device: ephemeral0.1
    filesystem: ext4

mounts:
  - ["ephemeral0.1", "/agent"]  

package_upgrade: true
packages:
   - apt-transport-https
   - zip
runcmd:
  # Install Azure-CLI (correct version)
  - curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
  # Download the Microsoft repository GPG keys
  - wget -q "https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb"
  # Register the Microsoft repository GPG keys
  - sudo dpkg -i packages-microsoft-prod.deb
  # Update the list of packages after we added packages.microsoft.com
  - sudo apt update
  # Install PowerShell
  - sudo apt install -y powershell 
  # Download and install packer
  - curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/hashicorp.gpg
  - sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
  - sudo apt update && sudo apt install packer -y

  # obsolete
  #  # Install dotnet-sdk-6
  # - sudo apt install -y dotnet-sdk-6.0
  # Download and install AZ Copy
  # - wget -O azcopy_v10.tar.gz https://aka.ms/downloadazcopy-v10-linux && tar -xf azcopy_v10.tar.gz 
  # - sudo cp ./azcopy_linux_amd64_*/azcopy /usr/bin/`
musekmkr commented 5 months ago

It seems like you are trying to build these images on your current, already existing Build Agent. You might need to figure out what tools you need installed there, not sure this is documented somewhere. The easiest way is to build your first images using a Microsoft Hosted Agent, as it has all the tools necessary.

I did end up doing this and installed the required software within the pipeline yaml. Fortunately, we were already paying for a couple of hosted agents, otherwise I would have been hit with the timeout and unable to build the initial images.

musekmkr commented 5 months ago

No need to keep this open any longer. Thank you for the help!