@@ -53,10 +53,13 @@ func main() {
5353}
5454
5555func run (cmd * cobra.Command , argv []string ) error {
56+ // 20250714: They changed it to images/ubuntu/templates/build.ubuntu-24_04.pkr.hcl
5657 filepath := "images/ubuntu/templates/"
57- sourceFile := fmt .Sprintf ("%s%s-%s.pkr.hcl" , filepath , args .os , args .osVersion )
58+ sourceFile := fmt .Sprintf ("%sbuild.%s-%s.pkr.hcl" , filepath , args .os , strings .ReplaceAll (args .osVersion , "." , "_" ))
59+ varsFile := "variable.ubuntu.pkr.hcl"
5860 imageFile := "build/image.raw"
5961 filename := ""
62+ varsFilename := ""
6063 imageName := fmt .Sprintf ("%s-%s-%s-gha-image" , args .os , args .osVersion , args .arch )
6164
6265 githubClient := github .NewClient (nil )
@@ -85,29 +88,42 @@ func run(cmd *cobra.Command, argv []string) error {
8588 if err != nil {
8689 log .Fatalf ("Failed to extract packer file: %s\n " , err )
8790 }
91+ varsFilename , err = extractPackerFileFromURL (downloadURL , varsFile )
92+ if err != nil {
93+ log .Fatalf ("Failed to extract packer file: %s\n " , err )
94+ }
8895 selectedRelease = release
8996 break
9097 }
9198 }
9299
93- file , err := os .ReadFile (filename )
100+ pkrContent , err := os .ReadFile (filename )
94101 if err != nil {
95102 log .Fatalf ("Failed to open file: %s\n " , err )
96103 }
97104
105+ // Read vars file
106+ varsContent , err := os .ReadFile (varsFilename )
107+ if err != nil {
108+ log .Fatalf ("Failed to open vars file: %s\n " , err )
109+ }
110+
98111 for key , value := range replacements {
99112 log .Printf ("Replacing %s with %s\n " , key , value )
100- file = bytes .ReplaceAll (file , []byte (key ), []byte (value ))
113+ pkrContent = bytes .ReplaceAll (pkrContent , []byte (key ), []byte (value ))
101114 }
102115
116+ mergedContent := append (varsContent , []byte ("\n " )... )
117+ mergedContent = append (mergedContent , pkrContent ... )
118+
103119 newFile := fmt .Sprintf ("%s-replaced.pkr.hcl" , filename )
104120
105121 out , err := os .Create (newFile )
106122 if err != nil {
107123 log .Fatalf ("Failed to create file: %s\n " , err )
108124 }
109125 defer out .Close ()
110- _ , err = out .Write (file )
126+ _ , err = out .Write (mergedContent )
111127 if err != nil {
112128 log .Fatalf ("Failed to write file: %s\n " , err )
113129 }
@@ -165,7 +181,7 @@ func run(cmd *cobra.Command, argv []string) error {
165181 replaceArmPackageLinks (baseDir , "/images/ubuntu/toolsets/toolset-2404.json" , "\" Ruby\" ,\n \" platform_version\" : \" 24.04\" " , "\" Ruby\" ,\n \" platform_version\" : \" 24.04-arm64\" " )
166182 }
167183
168- command := exec .Command ("packer" , "build" , "-var" , "architecture=" + args .arch , "--only" , "qemu.img" , newFile )
184+ command := exec .Command ("packer" , "build" , "-var" , "architecture=" + args .arch , newFile )
169185
170186 command .Stdout = os .Stdout
171187 if err := command .Run (); err != nil {
@@ -526,26 +542,11 @@ func init() {
526542 return []string {"json" , "prom" }, cobra .ShellCompDirectiveDefault
527543 })
528544
529- replacements [`dynamic "azure_tag" {
530- for_each = var.azure_tags
531- content {
532- name = azure_tag.key
533- value = azure_tag.value
534- }
535- }
536- }` ] = fmt .Sprintf (`dynamic "azure_tag" {
537- for_each = var.azure_tags
538- content {
539- name = azure_tag.key
540- value = azure_tag.value
541- }
542- }
543- }
544-
545- variable architecture {
546- type = string
547- default = "amd64"
548- description = "Target architecture (amd64 or arm64)"
545+ replacements [`build {
546+ sources = ["source.azure-arm.image"]` ] = fmt .Sprintf (`variable architecture {
547+ type = string
548+ default = "amd64"
549+ description = "Target architecture (amd64 or arm64)"
549550}
550551
551552source "qemu" "img" {
@@ -575,7 +576,15 @@ source "qemu" "img" {
575576 ssh_password = "ubuntu"
576577 ssh_timeout = "60m"
577578 headless = true
578- }` , args .isoURL , args .isoChecksum )
579+ }
580+
581+ build {
582+ sources = ["source.qemu.img"]
583+
584+ provisioner "shell" {
585+ execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'"
586+ inline = ["touch /etc/waagent.conf"]
587+ }` , args .isoURL , args .isoChecksum )
579588
580589 if args .arch == "arm64" {
581590 replacements [`provisioner "shell" {
0 commit comments