Skip to content

Commit 47e00cd

Browse files
committed
Also use pigz for tar
1 parent 02e7de0 commit 47e00cd

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

pkg/leeway/build.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ const (
9090
dockerMetadataFile = "metadata.yaml"
9191
)
9292

93+
var (
94+
compressor = "gzip"
95+
)
96+
97+
func init() {
98+
pigz, err := exec.LookPath("pigz")
99+
if err == nil {
100+
compressor = pigz
101+
}
102+
}
103+
93104
// buildProcessVersions contain the current version of the respective build processes.
94105
// Increment this value if you change any of the build procedures.
95106
var buildProcessVersions = map[PackageType]int{
@@ -1058,7 +1069,7 @@ func (p *Package) buildYarn(buildctx *buildContext, wd, result string) (bld *pac
10581069
{"sh", "-c", fmt.Sprintf("yarn generate-lock-entry --resolved file://./%s > _mirror/content_yarn.lock", dst)},
10591070
{"sh", "-c", "cat yarn.lock >> _mirror/content_yarn.lock"},
10601071
{"yarn", "pack", "--filename", dst},
1061-
{"tar", "cfz", result, "-C", "_mirror", "."},
1072+
{"tar", "cf", result, fmt.Sprintf("--use-compress-program=%v", compressor), "-C", "_mirror", "."},
10621073
}...)
10631074
resultDir = "_mirror"
10641075
} else if cfg.Packaging == YarnLibrary {
@@ -1082,11 +1093,11 @@ func (p *Package) buildYarn(buildctx *buildContext, wd, result string) (bld *pac
10821093
{"yarn", "pack", "--filename", pkg},
10831094
{"sh", "-c", fmt.Sprintf("cat yarn.lock %s > _pkg/yarn.lock", pkgYarnLock)},
10841095
{"yarn", "--cwd", "_pkg", "install", "--prod", "--frozen-lockfile"},
1085-
{"tar", "cfz", result, "-C", "_pkg", "."},
1096+
{"tar", "cf", result, fmt.Sprintf("--use-compress-program=%v", compressor), "-C", "_pkg", "."},
10861097
}...)
10871098
resultDir = "_pkg"
10881099
} else if cfg.Packaging == YarnArchive {
1089-
pkgCommands = append(pkgCommands, []string{"tar", "cfz", result, "."})
1100+
pkgCommands = append(pkgCommands, []string{"tar", "cf", result, fmt.Sprintf("--use-compress-program=%v", compressor), "."})
10901101
} else {
10911102
return nil, xerrors.Errorf("unknown Yarn packaging: %s", cfg.Packaging)
10921103
}
@@ -1246,7 +1257,7 @@ func (p *Package) buildGo(buildctx *buildContext, wd, result string) (res *packa
12461257
commands[PackageBuildPhaseBuild] = append(commands[PackageBuildPhaseBuild], []string{"rm", "-rf", "_deps"})
12471258

12481259
commands[PackageBuildPhasePackage] = append(commands[PackageBuildPhasePackage], []string{
1249-
"tar", "cfz", result, ".",
1260+
"tar", "cf", result, fmt.Sprintf("--use-compress-program=%v", compressor), ".",
12501261
})
12511262
if !cfg.DontTest && !buildctx.DontTest {
12521263
commands[PackageBuildPhasePackage] = append(commands[PackageBuildPhasePackage], [][]string{
@@ -1353,12 +1364,6 @@ func (p *Package) buildDocker(buildctx *buildContext, wd, result string) (res *p
13531364
pkgcmds = append(pkgcmds, []string{"tar", "fr", ef, "./" + provenanceBundleFilename})
13541365
}
13551366

1356-
compressor := "gzip"
1357-
pigz, err := exec.LookPath("pigz")
1358-
if err == nil {
1359-
compressor = pigz
1360-
}
1361-
13621367
pkgcmds = append(pkgcmds, []string{compressor, ef})
13631368
commands[PackageBuildPhasePackage] = pkgcmds
13641369
} else if len(cfg.Image) > 0 {
@@ -1386,7 +1391,7 @@ func (p *Package) buildDocker(buildctx *buildContext, wd, result string) (res *p
13861391
}
13871392
pkgCommands = append(pkgCommands, []string{"sh", "-c", fmt.Sprintf("echo %s | base64 -d > %s", base64.StdEncoding.EncodeToString(consts), dockerMetadataFile)})
13881393

1389-
archiveCmd := []string{"tar", "cfz", result, "./" + dockerImageNamesFiles, "./" + dockerMetadataFile}
1394+
archiveCmd := []string{"tar", "cf", result, fmt.Sprintf("--use-compress-program=%v", compressor), "./" + dockerImageNamesFiles, "./" + dockerMetadataFile}
13901395
if p.C.W.Provenance.Enabled {
13911396
archiveCmd = append(archiveCmd, "./"+provenanceBundleFilename)
13921397
}
@@ -1544,14 +1549,14 @@ func (p *Package) buildGeneric(buildctx *buildContext, wd, result string) (res *
15441549
if p.C.W.Provenance.Enabled {
15451550
return &packageBuild{
15461551
Commands: map[PackageBuildPhase][][]string{
1547-
PackageBuildPhasePackage: [][]string{{"tar", "cfz", result, "./" + provenanceBundleFilename}},
1552+
PackageBuildPhasePackage: [][]string{{"tar", "cf", result, fmt.Sprintf("--use-compress-program=%v", compressor), "./" + provenanceBundleFilename}},
15481553
},
15491554
}, nil
15501555
}
15511556

15521557
return &packageBuild{
15531558
Commands: map[PackageBuildPhase][][]string{
1554-
PackageBuildPhasePackage: [][]string{{"tar", "cfz", result, "--files-from", "/dev/null"}},
1559+
PackageBuildPhasePackage: [][]string{{"tar", "cf", result, fmt.Sprintf("--use-compress-program=%v", compressor), "--files-from", "/dev/null"}},
15551560
},
15561561
}, nil
15571562
}
@@ -1579,7 +1584,7 @@ func (p *Package) buildGeneric(buildctx *buildContext, wd, result string) (res *
15791584
return &packageBuild{
15801585
Commands: map[PackageBuildPhase][][]string{
15811586
PackageBuildPhaseBuild: commands,
1582-
PackageBuildPhasePackage: {{"tar", "cfz", result, "."}},
1587+
PackageBuildPhasePackage: {{"tar", "cf", result, fmt.Sprintf("--use-compress-program=%v", compressor), "."}},
15831588
},
15841589
}, nil
15851590
}

0 commit comments

Comments
 (0)