@@ -53,10 +53,13 @@ func main() {
53
53
}
54
54
55
55
func run (cmd * cobra.Command , argv []string ) error {
56
+ // 20250714: They changed it to images/ubuntu/templates/build.ubuntu-24_04.pkr.hcl
56
57
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"
58
60
imageFile := "build/image.raw"
59
61
filename := ""
62
+ varsFilename := ""
60
63
imageName := fmt .Sprintf ("%s-%s-%s-gha-image" , args .os , args .osVersion , args .arch )
61
64
62
65
githubClient := github .NewClient (nil )
@@ -85,29 +88,42 @@ func run(cmd *cobra.Command, argv []string) error {
85
88
if err != nil {
86
89
log .Fatalf ("Failed to extract packer file: %s\n " , err )
87
90
}
91
+ varsFilename , err = extractPackerFileFromURL (downloadURL , varsFile )
92
+ if err != nil {
93
+ log .Fatalf ("Failed to extract packer file: %s\n " , err )
94
+ }
88
95
selectedRelease = release
89
96
break
90
97
}
91
98
}
92
99
93
- file , err := os .ReadFile (filename )
100
+ pkrContent , err := os .ReadFile (filename )
94
101
if err != nil {
95
102
log .Fatalf ("Failed to open file: %s\n " , err )
96
103
}
97
104
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
+
98
111
for key , value := range replacements {
99
112
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 ))
101
114
}
102
115
116
+ mergedContent := append (varsContent , []byte ("\n " )... )
117
+ mergedContent = append (mergedContent , pkrContent ... )
118
+
103
119
newFile := fmt .Sprintf ("%s-replaced.pkr.hcl" , filename )
104
120
105
121
out , err := os .Create (newFile )
106
122
if err != nil {
107
123
log .Fatalf ("Failed to create file: %s\n " , err )
108
124
}
109
125
defer out .Close ()
110
- _ , err = out .Write (file )
126
+ _ , err = out .Write (mergedContent )
111
127
if err != nil {
112
128
log .Fatalf ("Failed to write file: %s\n " , err )
113
129
}
@@ -165,7 +181,7 @@ func run(cmd *cobra.Command, argv []string) error {
165
181
replaceArmPackageLinks (baseDir , "/images/ubuntu/toolsets/toolset-2404.json" , "\" Ruby\" ,\n \" platform_version\" : \" 24.04\" " , "\" Ruby\" ,\n \" platform_version\" : \" 24.04-arm64\" " )
166
182
}
167
183
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 )
169
185
170
186
command .Stdout = os .Stdout
171
187
if err := command .Run (); err != nil {
@@ -526,26 +542,11 @@ func init() {
526
542
return []string {"json" , "prom" }, cobra .ShellCompDirectiveDefault
527
543
})
528
544
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)"
549
550
}
550
551
551
552
source "qemu" "img" {
@@ -575,7 +576,15 @@ source "qemu" "img" {
575
576
ssh_password = "ubuntu"
576
577
ssh_timeout = "60m"
577
578
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 )
579
588
580
589
if args .arch == "arm64" {
581
590
replacements [`provisioner "shell" {
0 commit comments