Skip to content

Commit c5071e7

Browse files
authored
Drop the isBuildLess optimization. (#1975)
There is only a single package in Wolfi that exhibits this. Signed-off-by: Matt Moore <mattmoor@chainguard.dev>
1 parent a9f69e6 commit c5071e7

File tree

2 files changed

+64
-79
lines changed

2 files changed

+64
-79
lines changed

.github/workflows/wolfi-presubmit.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ jobs:
7474
- fping
7575
- subversion
7676
- sudo
77+
- py3-supported-python
7778
# TODO: https://github.com/wolfi-dev/os/issues/26442
7879
#- xmlto
7980

pkg/build/build.go

Lines changed: 63 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -521,13 +521,6 @@ func (b *Build) overlayBinSh() error {
521521
return nil
522522
}
523523

524-
// isBuildLess returns true if the build context does not actually do any building.
525-
// TODO(kaniini): Improve the heuristic for this by checking for uses/runs statements
526-
// in the pipeline.
527-
func (b *Build) isBuildLess() bool {
528-
return len(b.Configuration.Pipeline) == 0
529-
}
530-
531524
// getBuildConfigPURL determines the package URL for the melange config file
532525
// itself.
533526
func (b Build) getBuildConfigPURL() (*purl.PackageURL, error) {
@@ -732,69 +725,67 @@ func (b *Build) BuildPackage(ctx context.Context) error {
732725
linterQueue := []linterTarget{}
733726
cfg := b.workspaceConfig(ctx)
734727

735-
if !b.isBuildLess() {
736-
// Prepare guest directory
737-
if err := os.MkdirAll(b.GuestDir, 0o755); err != nil {
738-
return fmt.Errorf("mkdir -p %s: %w", b.GuestDir, err)
739-
}
740-
741-
log.Infof("building workspace in '%s' with apko", b.GuestDir)
742-
743-
guestFS := apkofs.DirFS(b.GuestDir, apkofs.WithCreateDir())
744-
imgRef, err := b.buildGuest(ctx, b.Configuration.Environment, guestFS)
745-
if err != nil {
746-
return fmt.Errorf("unable to build guest: %w", err)
747-
}
728+
// Prepare guest directory
729+
if err := os.MkdirAll(b.GuestDir, 0o755); err != nil {
730+
return fmt.Errorf("mkdir -p %s: %w", b.GuestDir, err)
731+
}
748732

749-
cfg.ImgRef = imgRef
750-
log.Debugf("ImgRef = %s", cfg.ImgRef)
733+
log.Infof("building workspace in '%s' with apko", b.GuestDir)
751734

752-
// TODO(kaniini): Make overlay-binsh work with Docker and Kubernetes.
753-
// Probably needs help from apko.
754-
if err := b.overlayBinSh(); err != nil {
755-
return fmt.Errorf("unable to install overlay /bin/sh: %w", err)
756-
}
735+
guestFS := apkofs.DirFS(b.GuestDir, apkofs.WithCreateDir())
736+
imgRef, err := b.buildGuest(ctx, b.Configuration.Environment, guestFS)
737+
if err != nil {
738+
return fmt.Errorf("unable to build guest: %w", err)
739+
}
757740

758-
if err := b.Runner.StartPod(ctx, cfg); err != nil {
759-
return fmt.Errorf("unable to start pod: %w", err)
760-
}
761-
if !b.DebugRunner {
762-
defer func() {
763-
if err := b.Runner.TerminatePod(context.WithoutCancel(ctx), cfg); err != nil {
764-
log.Warnf("unable to terminate pod: %s", err)
765-
}
766-
}()
767-
}
741+
cfg.ImgRef = imgRef
742+
log.Debugf("ImgRef = %s", cfg.ImgRef)
768743

769-
// run the main pipeline
770-
log.Debug("running the main pipeline")
771-
pipelines := b.Configuration.Pipeline
772-
if err := pr.runPipelines(ctx, pipelines); err != nil {
773-
return fmt.Errorf("unable to run package %s pipeline: %w", b.Configuration.Name(), err)
774-
}
744+
// TODO(kaniini): Make overlay-binsh work with Docker and Kubernetes.
745+
// Probably needs help from apko.
746+
if err := b.overlayBinSh(); err != nil {
747+
return fmt.Errorf("unable to install overlay /bin/sh: %w", err)
748+
}
775749

776-
for i, p := range pipelines {
777-
uniqueID := strconv.Itoa(i)
778-
pkg, err := p.SBOMPackageForUpstreamSource(b.Configuration.Package.LicenseExpression(), namespace, uniqueID)
779-
if err != nil {
780-
return fmt.Errorf("creating SBOM package for upstream source: %w", err)
750+
if err := b.Runner.StartPod(ctx, cfg); err != nil {
751+
return fmt.Errorf("unable to start pod: %w", err)
752+
}
753+
if !b.DebugRunner {
754+
defer func() {
755+
if err := b.Runner.TerminatePod(context.WithoutCancel(ctx), cfg); err != nil {
756+
log.Warnf("unable to terminate pod: %s", err)
781757
}
758+
}()
759+
}
782760

783-
if pkg == nil {
784-
// This particular pipeline step doesn't tell us about the upstream source code.
785-
continue
786-
}
761+
// run the main pipeline
762+
log.Debug("running the main pipeline")
763+
pipelines := b.Configuration.Pipeline
764+
if err := pr.runPipelines(ctx, pipelines); err != nil {
765+
return fmt.Errorf("unable to run package %s pipeline: %w", b.Configuration.Name(), err)
766+
}
787767

788-
b.SBOMGroup.AddUpstreamSourcePackage(pkg)
768+
for i, p := range pipelines {
769+
uniqueID := strconv.Itoa(i)
770+
pkg, err := p.SBOMPackageForUpstreamSource(b.Configuration.Package.LicenseExpression(), namespace, uniqueID)
771+
if err != nil {
772+
return fmt.Errorf("creating SBOM package for upstream source: %w", err)
789773
}
790774

791-
// add the main package to the linter queue
792-
lintTarget := linterTarget{
793-
pkgName: b.Configuration.Package.Name,
794-
disabled: b.Configuration.Package.Checks.Disabled,
775+
if pkg == nil {
776+
// This particular pipeline step doesn't tell us about the upstream source code.
777+
continue
795778
}
796-
linterQueue = append(linterQueue, lintTarget)
779+
780+
b.SBOMGroup.AddUpstreamSourcePackage(pkg)
781+
}
782+
783+
// add the main package to the linter queue
784+
lintTarget := linterTarget{
785+
pkgName: b.Configuration.Package.Name,
786+
disabled: b.Configuration.Package.Checks.Disabled,
797787
}
788+
linterQueue = append(linterQueue, lintTarget)
798789

799790
// run any pipelines for subpackages
800791
for _, sp := range b.Configuration.Subpackages {
@@ -803,14 +794,12 @@ func (b *Build) BuildPackage(ctx context.Context) error {
803794
return err
804795
}
805796

806-
if !b.isBuildLess() {
807-
log.Infof("running pipeline for subpackage %s", sp.Name)
797+
log.Infof("running pipeline for subpackage %s", sp.Name)
808798

809-
ctx := clog.WithLogger(ctx, log.With("subpackage", sp.Name))
799+
ctx := clog.WithLogger(ctx, log.With("subpackage", sp.Name))
810800

811-
if err := pr.runPipelines(ctx, sp.Pipeline); err != nil {
812-
return fmt.Errorf("unable to run subpackage %s pipeline: %w", sp.Name, err)
813-
}
801+
if err := pr.runPipelines(ctx, sp.Pipeline); err != nil {
802+
return fmt.Errorf("unable to run subpackage %s pipeline: %w", sp.Name, err)
814803
}
815804

816805
// add the main package to the linter queue
@@ -952,11 +941,9 @@ func (b *Build) BuildPackage(ctx context.Context) error {
952941
log.Warnf("unable to clean workspace: %s", err)
953942
}
954943

955-
if !b.isBuildLess() {
956-
// clean build guest container
957-
if err := os.RemoveAll(b.GuestDir); err != nil {
958-
log.Warnf("unable to clean guest container: %s", err)
959-
}
944+
// clean build guest container
945+
if err := os.RemoveAll(b.GuestDir); err != nil {
946+
log.Warnf("unable to clean guest container: %s", err)
960947
}
961948

962949
// generate APKINDEX.tar.gz and sign it
@@ -1075,17 +1062,14 @@ func (b *Build) buildFlavor() string {
10751062

10761063
func (b *Build) buildWorkspaceConfig(ctx context.Context) *container.Config {
10771064
log := clog.FromContext(ctx)
1078-
if b.isBuildLess() {
1079-
return &container.Config{
1080-
Arch: b.Arch,
1081-
WorkspaceDir: b.WorkspaceDir,
1082-
}
1083-
}
10841065

1085-
mounts := []container.BindMount{
1086-
{Source: b.WorkspaceDir, Destination: container.DefaultWorkspaceDir},
1087-
{Source: "/etc/resolv.conf", Destination: container.DefaultResolvConfPath},
1088-
}
1066+
mounts := []container.BindMount{{
1067+
Source: b.WorkspaceDir,
1068+
Destination: container.DefaultWorkspaceDir,
1069+
}, {
1070+
Source: "/etc/resolv.conf",
1071+
Destination: container.DefaultResolvConfPath,
1072+
}}
10891073

10901074
if b.CacheDir != "" {
10911075
if fi, err := os.Stat(b.CacheDir); err == nil && fi.IsDir() {

0 commit comments

Comments
 (0)