Skip to content

Commit 7ffd128

Browse files
committed
Add flag to not compress generic builds
1 parent 64d1c62 commit 7ffd128

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

cmd/build.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ func addBuildFlags(cmd *cobra.Command) {
168168
cmd.Flags().String("dump-plan", "", "Writes the build plan as JSON to a file. Use \"-\" to write the build plan to stderr.")
169169
cmd.Flags().Bool("werft", false, "Produce werft CI compatible output")
170170
cmd.Flags().Bool("dont-test", false, "Disable all package-level tests (defaults to false)")
171+
cmd.Flags().Bool("dont-compress", false, "Disable compression of build artifacts (defaults to false)")
171172
cmd.Flags().Bool("jailed-execution", false, "Run all build commands using runc (defaults to false)")
172173
cmd.Flags().UintP("max-concurrent-tasks", "j", uint(runtime.NumCPU()), "Limit the number of max concurrent build tasks - set to 0 to disable the limit")
173174
cmd.Flags().String("coverage-output-path", "", "Output path where test coverage file will be copied after running tests")
@@ -288,6 +289,11 @@ func getBuildOpts(cmd *cobra.Command) ([]leeway.BuildOption, *leeway.FilesystemC
288289
log.Fatal(err)
289290
}
290291

292+
dontCompress, err := cmd.Flags().GetBool("dont-compress")
293+
if err != nil {
294+
log.Fatal(err)
295+
}
296+
291297
return []leeway.BuildOption{
292298
leeway.WithLocalCache(localCache),
293299
leeway.WithRemoteCache(remoteCache),
@@ -299,6 +305,7 @@ func getBuildOpts(cmd *cobra.Command) ([]leeway.BuildOption, *leeway.FilesystemC
299305
leeway.WithCoverageOutputPath(coverageOutputPath),
300306
leeway.WithDockerBuildOptions(&dockerBuildOptions),
301307
leeway.WithJailedExecution(jailedExecution),
308+
leeway.WithCompressionDisabled(dontCompress),
302309
}, localCache
303310
}
304311

pkg/leeway/build.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ type buildOptions struct {
259259
Reporter Reporter
260260
DryRun bool
261261
BuildPlan io.Writer
262+
DontCompress bool
262263
DontTest bool
263264
MaxConcurrentTasks int64
264265
CoverageOutputPath string
@@ -358,6 +359,13 @@ func WithJailedExecution(jailedExecution bool) BuildOption {
358359
}
359360
}
360361

362+
func WithCompressionDisabled(dontCompress bool) BuildOption {
363+
return func(opts *buildOptions) error {
364+
opts.DontCompress = dontCompress
365+
return nil
366+
}
367+
}
368+
361369
func withBuildContext(ctx *buildContext) BuildOption {
362370
return func(opts *buildOptions) error {
363371
opts.context = ctx
@@ -1619,8 +1627,15 @@ func extractImageNameFromCache(pkgName, cacheBundleFN string) (imgname string, e
16191627
return "", nil
16201628
}
16211629

1622-
// buildGeneric implements the build process for generic packages.
1623-
// If you change anything in this process that's not backwards compatible, make sure you increment BuildGenericProccessVersion.
1630+
// Helper function to get compression arg based on DontCompress setting
1631+
func getCompressionArg(ctx *buildContext) string {
1632+
if ctx.DontCompress {
1633+
return ""
1634+
}
1635+
return fmt.Sprintf("--use-compress-program=%v", compressor)
1636+
}
1637+
1638+
// Update buildGeneric to use compression arg helper
16241639
func (p *Package) buildGeneric(buildctx *buildContext, wd, result string) (res *packageBuild, err error) {
16251640
cfg, ok := p.Config.(GenericPkgConfig)
16261641
if !ok {
@@ -1631,18 +1646,26 @@ func (p *Package) buildGeneric(buildctx *buildContext, wd, result string) (res *
16311646
if len(cfg.Commands) == 0 && len(cfg.Test) == 0 {
16321647
log.WithField("package", p.FullName()).Debug("package has no commands nor test - creating empty tar")
16331648

1649+
compressArg := getCompressionArg(buildctx)
1650+
tarArgs := []string{"cf", result}
1651+
if compressArg != "" {
1652+
tarArgs = append(tarArgs, compressArg)
1653+
}
1654+
16341655
// if provenance is enabled, we have to make sure we capture the bundle
16351656
if p.C.W.Provenance.Enabled {
1657+
tarArgs = append(tarArgs, "./"+provenanceBundleFilename)
16361658
return &packageBuild{
16371659
Commands: map[PackageBuildPhase][][]string{
1638-
PackageBuildPhasePackage: [][]string{{"tar", "cf", result, fmt.Sprintf("--use-compress-program=%v", compressor), "./" + provenanceBundleFilename}},
1660+
PackageBuildPhasePackage: {append([]string{"tar"}, tarArgs...)},
16391661
},
16401662
}, nil
16411663
}
16421664

1665+
tarArgs = append(tarArgs, "--files-from", "/dev/null")
16431666
return &packageBuild{
16441667
Commands: map[PackageBuildPhase][][]string{
1645-
PackageBuildPhasePackage: [][]string{{"tar", "cf", result, fmt.Sprintf("--use-compress-program=%v", compressor), "--files-from", "/dev/null"}},
1668+
PackageBuildPhasePackage: {append([]string{"tar"}, tarArgs...)},
16461669
},
16471670
}, nil
16481671
}
@@ -1667,10 +1690,17 @@ func (p *Package) buildGeneric(buildctx *buildContext, wd, result string) (res *
16671690
commands = append(commands, cfg.Test...)
16681691
}
16691692

1693+
compressArg := getCompressionArg(buildctx)
1694+
tarArgs := []string{"cf", result}
1695+
if compressArg != "" {
1696+
tarArgs = append(tarArgs, compressArg)
1697+
}
1698+
tarArgs = append(tarArgs, ".")
1699+
16701700
return &packageBuild{
16711701
Commands: map[PackageBuildPhase][][]string{
16721702
PackageBuildPhaseBuild: commands,
1673-
PackageBuildPhasePackage: {{"tar", "cf", result, fmt.Sprintf("--use-compress-program=%v", compressor), "."}},
1703+
PackageBuildPhasePackage: {append([]string{"tar"}, tarArgs...)},
16741704
},
16751705
}, nil
16761706
}

0 commit comments

Comments
 (0)