-
Notifications
You must be signed in to change notification settings - Fork 37
/
build.go
811 lines (705 loc) · 26.5 KB
/
build.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
// Copyright © 2017 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"github.com/clearlinux/mixer-tools/builder"
"github.com/clearlinux/mixer-tools/helpers"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
const bumpMarker = "format-bump"
// Sets the default number of RPM download retries
const retriesDefault = 3
type buildCmdFlags struct {
format string
newFormat string
increment bool
minVersion int
clean bool
noSigning bool
downloadRetries int
noPublish bool
template string
skipFullfiles bool
skipPacks bool
to int
from int
toRepoURLs *map[string]string
fromRepoURLs *map[string]string
skipFormatCheck bool
numFullfileWorkers int
numDeltaWorkers int
numBundleWorkers int
}
var buildFlags buildCmdFlags
func setWorkers(b *builder.Builder) {
var workers int
workers = buildFlags.numFullfileWorkers
if workers < 1 {
workers = runtime.NumCPU()
}
b.NumFullfileWorkers = workers
workers = buildFlags.numDeltaWorkers
if workers < 1 {
workers = runtime.NumCPU()
}
b.NumDeltaWorkers = workers
workers = buildFlags.numBundleWorkers
if workers < 1 {
workers = runtime.NumCPU()
}
b.NumBundleWorkers = workers
}
// buildCmd represents the base build command when called without any subcommands
var buildCmd = &cobra.Command{
Use: "build",
Short: "Build various pieces of OS content",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
// Since this function overwrites root's PersistentPreRun, call it manually
root := cmd
for root.Parent() != nil {
root = root.Parent()
}
if err := root.PersistentPreRunE(cmd, args); err != nil {
return err
}
b, err := builder.NewFromConfig(configFile)
if err != nil {
return err
}
if err := printFormatMismatch(b); err != nil {
return err
}
// Skip format bump check for format-bump commands
if hasMarker(cmd, bumpMarker) {
return nil
}
return checkFormatBump(b)
},
}
func buildBundles(builder *builder.Builder, signflag, cleanFlag bool, downloadRetries int) error {
if downloadRetries < 0 {
return errors.New("Please supply value >= 0 for --retries")
}
// Create the signing and validation key/cert
if _, err := os.Stat(builder.Config.Builder.Cert); os.IsNotExist(err) {
fmt.Println("Generating certificate for signature validation...")
privkey, err := helpers.CreateKeyPair()
if err != nil {
return errors.Wrap(err, "Error generating OpenSSL keypair")
}
template := helpers.CreateCertTemplate()
err = builder.BuildBundles(template, privkey, signflag, cleanFlag, downloadRetries)
if err != nil {
return errors.Wrap(err, "Error building bundles")
}
} else {
err := builder.BuildBundles(nil, nil, true, cleanFlag, downloadRetries)
if err != nil {
return errors.Wrap(err, "Error building bundles")
}
}
return nil
}
var buildBundlesCmd = &cobra.Command{
Use: "bundles",
Aliases: []string{"chroots"},
Short: "Build the bundles for your mix",
Long: `Build the bundles for your mix`,
Run: func(cmd *cobra.Command, args []string) {
b, err := builder.NewFromConfig(configFile)
if err != nil {
fail(err)
}
setWorkers(b)
err = buildBundles(b, buildFlags.noSigning, buildFlags.clean, buildFlags.downloadRetries)
if err != nil {
fail(err)
}
},
}
var buildUpstreamFormatCmd = &cobra.Command{
Use: "upstream-format",
Short: "Use to create the necessary builds to cross an upstream format",
Long: `Use to create the necessary builds to cross an upstream format`,
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
b, err := builder.NewFromConfig(configFile)
if err != nil {
fail(err)
}
// Don't print any more warnings about being behind formats when we loop
silent := true
bumpNeeded := true
for bumpNeeded {
cmdStr := fmt.Sprintf("mixer build format-bump old --new-format %s --retries %d --native", buildFlags.newFormat, buildFlags.downloadRetries)
cmdToRun := strings.Split(cmdStr, " ")
if err = helpers.RunCommand(cmdToRun[0], cmdToRun[1:]...); err != nil {
fail(err)
}
// Set the upstream version to the previous format's latest version
b.UpstreamVer = strconv.FormatUint(uint64(b.UpstreamVerUint32), 10)
vFile := filepath.Join(b.Config.Builder.VersionPath, b.UpstreamVerFile)
if err = ioutil.WriteFile(vFile, []byte(b.UpstreamVer), 0644); err != nil {
fail(err)
}
cmdStr = fmt.Sprintf("mixer build format-bump new --new-format %s --native", buildFlags.newFormat)
cmdToRun = strings.Split(cmdStr, " ")
if err = helpers.RunCommand(cmdToRun[0], cmdToRun[1:]...); err != nil {
fail(err)
}
// Set the upstream version back to what the user originally tried to build
if err = b.UnstageMixFromBump(); err != nil {
fail(err)
}
bumpNeeded, err = b.CheckBumpNeeded(silent)
if err != nil {
fail(err)
}
}
newFormatVer, err := strconv.Atoi(b.MixVer)
if err != nil {
failf("Couldn't get new format version")
}
newFormatVer += 10
if err = b.UpdateMixVer(newFormatVer); err != nil {
failf("Couldn't update Mix Version")
}
},
}
var buildFormatBumpCmd = &cobra.Command{
Use: "format-bump",
Short: "Used to create a downstream format bump",
Long: `Used to create a downstream format bump`,
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
if buildFlags.newFormat == "" {
fail(errors.New("Please supply the next format version with --new-format"))
}
cmdStr := fmt.Sprintf("mixer build format-bump old --new-format %s --retries %d --native", buildFlags.newFormat, buildFlags.downloadRetries)
cmdToRun := strings.Split(cmdStr, " ")
if output, err := helpers.RunCommandOutputEnv(cmdToRun[0], cmdToRun[1:], []string{}); err != nil {
failf("%s: %s", output, err)
}
cmdStr = fmt.Sprintf("mixer build format-bump new --new-format %s --native", buildFlags.newFormat)
cmdToRun = strings.Split(cmdStr, " ")
if output, err := helpers.RunCommandOutputEnv(cmdToRun[0], cmdToRun[1:], []string{}); err != nil {
failf("%s: %s", output, err)
}
},
}
// This is the last build in the original format. At this point add ONLY the
// content relevant to the format bump to the mash to be used. Relevant content
// should be the only change.
//
// mixer will create manifests and update content based on the format it is
// building for. The format is set in the mixer.state file.
var buildFormatOldCmd = &cobra.Command{
Use: "old",
Short: "Build the +10 version in the old format for the format bump",
Long: `Build the +10 version in the old format for the format bump`,
Run: func(cmd *cobra.Command, args []string) {
b, err := builder.NewFromConfig(configFile)
if err != nil {
fail(err)
}
setWorkers(b)
lastVer, err := b.GetLastBuildVersion()
if err != nil {
fail(err)
}
// The PREVIOUS_MIX_VERSION value in mixer.state replaced the LAST_VER file for
// setting the previous version in the manifest header field. The PREVIOUS_MIX_VERSION
// value is set to the LAST_VER during format bumps to maintain consistent behavior.
if err = b.UpdatePreviousMixVersion(lastVer); err != nil {
fail(err)
}
originalVer, err := strconv.Atoi(lastVer)
if err != nil {
fail(err)
}
oldFormatVer := originalVer + 10
newFormatVer := originalVer + 20
// Update mixer to build version +20, to build the bundles with +20 inside not +10
if err = b.UpdateMixVer(newFormatVer); err != nil {
failf("Couldn't update Mix Version")
}
// Change the format internally just for building bundles so the right
// /usr/share/defaults/swupd/format is inserted; preserve old format
oldFormat := b.State.Mix.Format
b.State.Mix.Format = buildFlags.newFormat
oldFormatInt, err := strconv.Atoi(oldFormat)
if err != nil {
fail(err)
}
newFormatInt, err := strconv.Atoi(b.State.Mix.Format)
if err != nil {
fail(err)
}
// Delete index manifest when passing format 28
if oldFormatInt <= 28 && newFormatInt > 28 {
bdir := filepath.Join(b.Config.Builder.ServerStateDir, "image", b.MixVer, "os-core-update-index")
if err := os.MkdirAll(bdir, 0755); err != nil {
fail(err)
}
}
// Build bundles normally. At this point the bundles to be deleted should still
// be part of the mixbundles list and the groups.ini
if err = buildBundles(b, buildFlags.noSigning, buildFlags.clean, buildFlags.downloadRetries); err != nil {
fail(err)
}
// Remove deleted bundles and replace with empty dirs for update to mark as deleted
if err = b.ModifyBundles(b.ReplaceInfoBundles); err != nil {
fail(err)
}
// Link the +20 bundles to the +10 so we are building the update with the same
// underlying content. The only things that might change are the manifests
// (potentially the pack and full-file formats as well, though this is very
// rare).
if err = b.UpdateMixVer(oldFormatVer); err != nil {
failf("Couldn't update Mix Version")
}
source := filepath.Join(b.Config.Builder.ServerStateDir, "image", strconv.Itoa(newFormatVer))
dest := filepath.Join(b.Config.Builder.ServerStateDir, "image", strconv.Itoa(oldFormatVer))
fmt.Println(" Copying +20 bundles to +10 bundles")
if err = helpers.RunCommandSilent("cp", "-al", source, dest); err != nil {
failf("Failed to copy +10 bundles to +20: %s\n", err)
}
// Set the format back to old for the actual build update
b.State.Mix.Format = oldFormat
// Build the update content for the +10 build
params := builder.UpdateParameters{
MinVersion: buildFlags.minVersion,
Format: b.State.Mix.Format,
Publish: !buildFlags.noPublish,
SkipSigning: buildFlags.noSigning,
SkipFullfiles: buildFlags.skipFullfiles,
SkipPacks: buildFlags.skipPacks,
}
if err = b.BuildUpdate(params); err != nil {
failf("Couldn't build update: %s", err)
}
// Write the +0 version to LAST_VER so that we reference in both +10 and +20 manifests as the 'previous:'
if err = ioutil.WriteFile(filepath.Join(b.Config.Builder.ServerStateDir, "image", "LAST_VER"), []byte(lastVer), 0644); err != nil {
failf("Couldn't update LAST_VER file: %s", err)
}
// PREVIOUS_MIX_VERSION is set to the LAST_VER for format bumps to maintain
// consistent format bump behavior.
if err = b.UpdatePreviousMixVersion(lastVer); err != nil {
fail(err)
}
},
}
// This is the first build in the new format. The content is the same as the +10
// but the manifests might be created differently if a new manifest template is
// defined for the new format.
var buildFormatNewCmd = &cobra.Command{
Use: "new",
Short: "Build the +20 version in the new format for the format bump",
Long: `Build the +20 version in the new format for the format bump`,
Run: func(cmd *cobra.Command, args []string) {
b, err := builder.NewFromConfig(configFile)
if err != nil {
fail(err)
}
// Set mixversion to +20 build now, we only need to build update since we
// already have the bundles created
ver, err := strconv.Atoi(b.MixVer)
if err != nil {
fail(err)
}
if err = b.UpdateMixVer(ver + 10); err != nil {
failf("Couldn't update Mix Version")
}
// Set format to format+1 for future builds
if err = b.UpdateFormatVersion(buildFlags.newFormat); err != nil {
fail(err)
}
setWorkers(b)
if err = b.ModifyBundles(b.RemoveBundlesGroupINI); err != nil {
fail(err)
}
minver, err := strconv.Atoi(b.MixVer)
if err != nil {
fail(err)
}
// Build the +20 update so we don't have to switch tooling in between
params := builder.UpdateParameters{
MinVersion: minver,
Format: buildFlags.newFormat,
Publish: !buildFlags.noPublish,
SkipSigning: buildFlags.noSigning,
SkipFullfiles: buildFlags.skipFullfiles,
SkipPacks: buildFlags.skipPacks,
}
err = b.BuildUpdate(params)
if err != nil {
failf("Couldn't build update: %s", err)
}
// The PREVIOUS_MIX_VERSION value in mixer.state replaced the LAST_VER file for
// setting the previous version in the manifest header field. The PREVIOUS_MIX_VERSION
// value is set to the LAST_VER during format bumps to maintain consistent behavior.
lastVer, err := b.GetLastBuildVersion()
if err != nil {
fail(err)
}
if err = b.UpdatePreviousMixVersion(lastVer); err != nil {
fail(err)
}
},
}
var buildUpdateCmd = &cobra.Command{
Use: "update",
Short: "Build the update content for your mix",
Long: `Build the update content for your mix`,
Run: func(cmd *cobra.Command, args []string) {
b, err := builder.NewFromConfig(configFile)
if err != nil {
fail(err)
}
setWorkers(b)
params := builder.UpdateParameters{
MinVersion: buildFlags.minVersion,
Format: buildFlags.format,
Publish: !buildFlags.noPublish,
SkipSigning: buildFlags.noSigning,
SkipFullfiles: buildFlags.skipFullfiles,
SkipPacks: buildFlags.skipPacks,
}
err = b.BuildUpdate(params)
if err != nil {
failf("Couldn't build update: %s", err)
}
if buildFlags.increment {
if err = b.UpdatePreviousMixVersion(b.MixVer); err != nil {
fail(err)
}
ver, err := strconv.Atoi(b.MixVer)
if err != nil {
fail(err)
}
if err = b.UpdateMixVer(ver + 10); err != nil {
failf("Couldn't update Mix Version")
}
}
},
}
var buildAllCmd = &cobra.Command{
Use: "all",
Short: "Build all content for mix with default options",
Long: `Build all content for mix with default options`,
Run: func(cmd *cobra.Command, args []string) {
b, err := builder.NewFromConfig(configFile)
if err != nil {
fail(err)
}
setWorkers(b)
rpms, err := helpers.ListVisibleFiles(b.Config.Mixer.LocalRPMDir)
if err == nil {
err = b.AddRPMList(rpms)
if err != nil {
failf("Couldn't add the RPMs: %s", err)
}
}
err = buildBundles(b, buildFlags.noSigning, buildFlags.clean, buildFlags.downloadRetries)
if err != nil {
failf("Couldn't build bundles: %s", err)
}
params := builder.UpdateParameters{
MinVersion: buildFlags.minVersion,
Format: buildFlags.format,
Publish: !buildFlags.noPublish,
SkipSigning: buildFlags.noSigning,
SkipFullfiles: buildFlags.skipFullfiles,
SkipPacks: buildFlags.skipPacks,
}
err = b.BuildUpdate(params)
if err != nil {
failf("Couldn't build update: %s", err)
}
if buildFlags.increment {
if err = b.UpdatePreviousMixVersion(b.MixVer); err != nil {
fail(err)
}
ver, err := strconv.Atoi(b.MixVer)
if err != nil {
fail(err)
}
if err = b.UpdateMixVer(ver + 10); err != nil {
failf("Couldn't update Mix Version")
}
}
},
}
var buildValidateCmd = &cobra.Command{
Use: "validate",
Short: "Validate manifests correctly generated between two versions",
Long: `Validate manifests correctly generated between two versions`,
Run: func(cmd *cobra.Command, args []string) {
b, err := builder.NewFromConfig(configFile)
if err != nil {
fail(err)
}
setWorkers(b)
err = b.CheckManifestCorrectness(buildFlags.from, buildFlags.to, buildFlags.downloadRetries, *buildFlags.fromRepoURLs, *buildFlags.toRepoURLs)
if err != nil {
fail(err)
}
},
}
var buildImageCmd = &cobra.Command{
Use: "image",
Short: "Build an image from the mix content",
Long: `Build an image from the mix content`,
Run: func(cmd *cobra.Command, args []string) {
b, err := builder.NewFromConfig(configFile)
if err != nil {
fail(err)
}
setWorkers(b)
err = b.BuildImage(buildFlags.format, buildFlags.template)
if err != nil {
failf("Couldn't build image: %s", err)
}
},
}
var buildDeltaPacksCmd = &cobra.Command{
Use: "delta-packs",
Short: "Build packs used to optimize update between versions",
Long: `Build packs used to optimize update between versions
When a swupd client updates a bundle, it looks for a pack file from
its current version to the new version. If not available, the client
will download the individual files necessary for the update. If a
bundle haven't changed between two versions, no pack need to be
generated.
To generate the packs to optimize update from VER to the current mix
version use
mixer build delta-packs --from VER
Alternatively, to generate packs for a set of NUM previous versions,
each one to the current mix version, instead of --from use
mixer build delta-packs --previous-versions NUM
To change the target version (by default the current version), use the
flag --to. The target version must be larger than the --from version.
`,
RunE: runBuildDeltaPacks,
}
var buildDeltaManifestsCmd = &cobra.Command{
Use: "delta-manifests",
Short: "Build delta manifests used to optimize update between versions",
Long: `Build delta manifests used to optimize update between versions
When a swupd client updates content, it uses manifest files to get file
metadata. If the current versions manifests already exists on the system
and the delta manifest files are available on the server, the client will
attempt to apply the delta manifests to create the new version manifests
rather than downloading the full manifest directly. If a bundle hasn't changed
between two versions, no delta manifest needs to be generated.
To generate the delta manifests to optimize update from VER to the current mix
version use
mixer build delta-manifests --from VER
Alternatively, to generate delta manifests for a set of NUM previous versions,
each one to the current mix version, instead of --from use
mixer build delta-manifests --previous-versions NUM
To change the target version (by default the current version), use the
flag --to. The target version must be larger than the --from version.
`,
RunE: runBuildDeltaManifests,
}
var buildDeltaPacksFlags struct {
previousVersions uint32
from uint32
to uint32
report bool
}
var buildDeltaManifestsFlags struct {
previousVersions uint32
from uint32
to uint32
}
func runBuildDeltaPacks(cmd *cobra.Command, args []string) error {
fromChanged := cmd.Flags().Changed("from")
prevChanged := cmd.Flags().Changed("previous-versions")
if fromChanged == prevChanged {
return errors.Errorf("either --from or --previous-versions must be set, but not both")
}
b, err := builder.NewFromConfig(configFile)
if err != nil {
fail(err)
}
setWorkers(b)
if fromChanged {
err = b.BuildDeltaPacks(buildDeltaPacksFlags.from, buildDeltaPacksFlags.to, buildDeltaPacksFlags.report)
} else {
err = b.BuildDeltaPacksPreviousVersions(buildDeltaPacksFlags.previousVersions, buildDeltaPacksFlags.to, buildDeltaPacksFlags.report)
}
if err != nil {
fail(err)
}
return nil
}
func runBuildDeltaManifests(cmd *cobra.Command, args []string) error {
fromChanged := cmd.Flags().Changed("from")
prevChanged := cmd.Flags().Changed("previous-versions")
if fromChanged == prevChanged {
return errors.Errorf("either --from or --previous-versions must be set, but not both")
}
b, err := builder.NewFromConfig(configFile)
if err != nil {
fail(err)
}
setWorkers(b)
if fromChanged {
err = b.BuildDeltaManifests(buildDeltaManifestsFlags.from, buildDeltaManifestsFlags.to)
} else {
err = b.BuildDeltaManifestsPreviousVersions(buildDeltaManifestsFlags.previousVersions, buildDeltaManifestsFlags.to)
}
if err != nil {
fail(err)
}
return nil
}
func setUpdateFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&buildFlags.format, "format", "", "Supply format to use")
cmd.Flags().BoolVar(&buildFlags.increment, "increment", false, "Automatically increment the mixversion post build")
cmd.Flags().IntVar(&buildFlags.minVersion, "min-version", 0, "Supply minversion to build update with")
cmd.Flags().BoolVar(&buildFlags.noSigning, "no-signing", false, "Do not generate a certificate and do not sign the Manifest.MoM")
cmd.Flags().BoolVar(&buildFlags.noPublish, "no-publish", false, "Do not update the latest version after update")
cmd.Flags().BoolVar(&buildFlags.skipFullfiles, "skip-fullfiles", false, "Do not generate fullfiles")
cmd.Flags().BoolVar(&buildFlags.skipPacks, "skip-packs", false, "Do not generate zero packs")
var unusedStringFlag string
cmd.Flags().StringVar(&unusedStringFlag, "prefix", "", "Supply prefix for where the swupd binaries live")
_ = cmd.Flags().MarkHidden("prefix")
_ = cmd.Flags().MarkDeprecated("prefix", "this flag is ignored by the update builder")
var unusedBoolFlag bool
cmd.Flags().BoolVar(&unusedBoolFlag, "keep-chroots", false, "Keep individual chroots created and not just consolidated 'full'")
_ = cmd.Flags().MarkHidden("keep-chroots")
_ = cmd.Flags().MarkDeprecated("keep-chroots", "this flag is ignored by the update builder")
}
var containerCmds = []*cobra.Command{
buildBundlesCmd,
buildUpdateCmd,
buildAllCmd,
buildValidateCmd,
buildDeltaPacksCmd,
buildDeltaManifestsCmd,
}
var nativeCmds = []*cobra.Command{
buildFormatBumpCmd,
buildUpstreamFormatCmd,
buildImageCmd,
}
var bumpCmds = []*cobra.Command{
buildFormatNewCmd,
buildFormatOldCmd,
}
func init() {
for _, cmd := range containerCmds {
addMarker(cmd, containerMarker)
buildCmd.AddCommand(cmd)
}
for _, cmd := range nativeCmds {
buildCmd.AddCommand(cmd)
}
for _, cmd := range bumpCmds {
addMarker(cmd, containerMarker)
addMarker(cmd, bumpMarker)
buildFormatBumpCmd.AddCommand(cmd)
}
addMarker(buildUpstreamFormatCmd, bumpMarker)
buildFormatBumpCmd.Flags().StringVar(&buildFlags.newFormat, "new-format", "", "Supply the next format version to build mixes in")
buildFormatOldCmd.Flags().StringVar(&buildFlags.newFormat, "new-format", "", "Supply the next format version to build mixes in")
buildFormatNewCmd.Flags().StringVar(&buildFlags.newFormat, "new-format", "", "Supply the next format version to build mixes in")
buildUpstreamFormatCmd.Flags().StringVar(&buildFlags.newFormat, "new-format", "", "Supply the next format version to build mixes in")
buildCmd.PersistentFlags().IntVar(&buildFlags.numFullfileWorkers, "fullfile-workers", 0, "Number of parallel workers when creating fullfiles, 0 means number of CPUs")
buildCmd.PersistentFlags().IntVar(&buildFlags.numDeltaWorkers, "delta-workers", 0, "Number of parallel workers when creating deltas, 0 means number of CPUs")
buildCmd.PersistentFlags().IntVar(&buildFlags.numBundleWorkers, "bundle-workers", 0, "Number of parallel workers when building bundles, 0 means number of CPUs")
buildCmd.PersistentFlags().IntVar(&buildFlags.downloadRetries, "retries", retriesDefault, "Number of retry attempts to download RPMs")
buildCmd.PersistentFlags().BoolVar(&buildFlags.skipFormatCheck, "skip-format-check", false, "Skip format bump check")
RootCmd.AddCommand(buildCmd)
buildAllCmd.Flags().BoolVar(&buildFlags.clean, "clean", false, "Wipe the /image and /www dirs if they exist")
buildBundlesCmd.Flags().BoolVar(&buildFlags.clean, "clean", false, "Wipe the /image and /www dirs if they exist")
buildBundlesCmd.Flags().BoolVar(&buildFlags.noSigning, "no-signing", false, "Do not generate a certificate to sign the Manifest.MoM")
unusedBoolFlag := false
buildBundlesCmd.Flags().BoolVar(&unusedBoolFlag, "new-chroots", false, "")
_ = buildBundlesCmd.Flags().MarkHidden("new-chroots")
_ = buildBundlesCmd.Flags().MarkDeprecated("new-chroots", "new functionality is now the standard behavior, this flag is obsolete and no longer used")
buildValidateCmd.Flags().IntVar(&buildFlags.to, "to", 0, "Compare manifests targeting a specific version")
buildValidateCmd.Flags().IntVar(&buildFlags.from, "from", 0, "Compare manifests from a specific version")
buildFlags.toRepoURLs = buildValidateCmd.Flags().StringToString("to-repo-url", nil, "Overrides the baseurl value for the provided repo in the DNF config file for the `to` version: <repo>=<URL>")
buildFlags.fromRepoURLs = buildValidateCmd.Flags().StringToString("from-repo-url", nil, "Overrides the baseurl value for the provided repo in the DNF config file for the `from` version: <repo>=<URL>")
buildImageCmd.Flags().StringVar(&buildFlags.format, "format", "", "Supply the format used for the Mix")
buildImageCmd.Flags().StringVar(&buildFlags.template, "template", "", "Path to template file to use")
buildDeltaPacksCmd.Flags().Uint32Var(&buildDeltaPacksFlags.from, "from", 0, "Generate packs from a specific version")
buildDeltaPacksCmd.Flags().Uint32Var(&buildDeltaPacksFlags.previousVersions, "previous-versions", 0, "Generate packs for multiple previous versions")
buildDeltaPacksCmd.Flags().Uint32Var(&buildDeltaPacksFlags.to, "to", 0, "Generate packs targeting a specific version")
buildDeltaPacksCmd.Flags().BoolVar(&buildDeltaPacksFlags.report, "report", false, "Report reason each file in to manifest was packed or not")
buildDeltaManifestsCmd.Flags().Uint32Var(&buildDeltaManifestsFlags.from, "from", 0, "Generate delta manifests from a specific version")
buildDeltaManifestsCmd.Flags().Uint32Var(&buildDeltaManifestsFlags.previousVersions, "previous-versions", 0, "Generate delta manifests for multiple previous versions")
buildDeltaManifestsCmd.Flags().Uint32Var(&buildDeltaManifestsFlags.to, "to", 0, "Generate delta manifests targeting a specific version")
setUpdateFlags(buildUpdateCmd)
setUpdateFlags(buildAllCmd)
setUpdateFlags(buildFormatNewCmd)
setUpdateFlags(buildFormatOldCmd)
externalDeps[buildBundlesCmd] = []string{
"rpm",
"dnf",
}
externalDeps[buildUpdateCmd] = []string{
"openssl",
"xz",
}
externalDeps[buildImageCmd] = []string{
"ister.py",
}
externalDeps[buildAllCmd] = append(
externalDeps[buildBundlesCmd],
append(externalDeps[buildUpdateCmd],
externalDeps[buildImageCmd]...)...)
}
func printFormatMismatch(b *builder.Builder) error {
// Skip check if offline
if builder.Offline {
return nil
}
hostFormat, upstreamFormat, err := b.GetHostAndUpstreamFormats()
if err != nil {
return err
}
if hostFormat == "" {
log.Println("Warning: Unable to determine host format. Running natively may fail.")
} else if hostFormat != upstreamFormat {
log.Println("Warning: The host format and mix upstream format do not match.",
"Mixer may be incompatible with this format; running natively may fail.")
}
return nil
}
func checkFormatBump(b *builder.Builder) error {
// Skip check if offline
if builder.Offline || buildFlags.skipFormatCheck {
return nil
}
if bumpNeeded, err := b.CheckBumpNeeded(false); err != nil {
return err
} else if bumpNeeded {
return errors.New("ERROR: Format bump required")
}
return nil
}