So, I am trying to use Azure DevOps release pipeline and Packer to build a gold image but I am coming up with a weird error where the script is not found. I am trying to use the auto generated template as I am not experience with Packer at all but it seemed very straight forward so I persisted.
I am building off a base Ubuntu 18.04-LTS image, my package is being picked up from the CI pipeline fine and is visible in the UI. My package contains the script and this is also visible from the UI. I have no arguments for the script as it contains very little at this stage.
The initial step runs fine as per below and when I put in an incorrect script name or path it fails as I would expect.
2020-09-21T13:42:28.5763293Z Resolving deploy package path.
2020-09-21T13:42:28.5872208Z Resolved deploy package path: /agent/_work/r1/a/_APP/_drop/MyApp.Web.
2020-09-21T13:42:28.5873284Z Resolving deploy script path.
2020-09-21T13:42:28.7426014Z Resolved deploy script path: deploy.sh.
The build runs through packer validation fine and a machine is setup. The task successfully connects via SSH and logs show that it uploads as per below. It then fails because it can't find the script.
2020-09-21T13:43:51.9642183Z ==> azure-arm: Connected to SSH!
2020-09-21T13:43:51.9642706Z
2020-09-21T13:43:51.9661411Z ==> azure-arm: Provisioning with shell script: /tmp/packer-shell391925162
2020-09-21T13:43:51.9678528Z
2020-09-21T13:43:54.3568719Z ==> azure-arm: Uploading /agent/_work/r1/a/_APP/_drop/MyApp.Web => /deployTemp/MyApp.Web
2020-09-21T13:50:54.8214369Z
2020-09-21T13:50:55.8696845Z ==> azure-arm: Provisioning with shell script: /tmp/packer-shell088825827
2020-09-21T13:50:55.8700537Z
2020-09-21T13:50:55.9197460Z azure-arm: MyApp.Web
2020-09-21T13:50:55.9198790Z
2020-09-21T13:50:55.9211167Z azure-arm: /tmp/script_5793.sh: 5: /tmp/script_5793.sh: /deployTemp/MyApp.Web/deploy.sh: not found
My initial thoughts are that the package was still in the process of copying across as the time stamp between the upload and trying to run the script is really quick and I know from other steps in the pipeline that copying the package generally takes a lot longer. I did try to run a user generated version of the script but keep getting blocked in other ways.
I have included the code from the deploy as it is only really an apt-get command which I was hoping to flesh out after once I had a successful test run but have yet to see any success.
Any help or suggestions would be greatly appreciated.
Step settings Settings as per below (written in GUI and copied to YAML)
steps:
- task: PackerBuild@1
displayName: 'Build immutable image'
inputs:
ConnectedServiceName: '<Service Account>'
managedImageName: AppNameGoldImageSept20
location: australiaeast
storageAccountName: astorageaccount
azureResourceGroup: '<ResourceGroup>'
baseImage: 'Canonical:UbuntuServer:18.04-LTS:linux'
packagePath: '$(System.DefaultWorkingDirectory)/_APP/_drop/MyApp.Web'
deployScriptPath: deploy.sh
additionalBuilderParameters: '{\"vm_size\":\"Standard_D3_v2\",\"virtual_network_name\":\"<VNetHere>\",\"virtual_network_subnet_name\":\"<Subnet Here>\",\"virtual_network_resource_group_name\":\"<VnetRg>\"}'