Print all not-found packages (#304)

* Print all not-found packages

When trying to install several packages that are not found luet will now
print all packages that are not found, instead of only first one.

* changes to some failing tests
This commit is contained in:
Fredrik Lönnegren 2022-07-20 00:29:24 +02:00 committed by GitHub
parent 843858e241
commit 556e46daeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 13 deletions

View File

@ -23,11 +23,12 @@ import (
"github.com/google/go-containerregistry/pkg/name" "github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1" v1 "github.com/google/go-containerregistry/pkg/v1"
daemon "github.com/google/go-containerregistry/pkg/v1/daemon" daemon "github.com/google/go-containerregistry/pkg/v1/daemon"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/mudler/luet/pkg/api/core/context" "github.com/mudler/luet/pkg/api/core/context"
. "github.com/mudler/luet/pkg/api/core/image" . "github.com/mudler/luet/pkg/api/core/image"
"github.com/mudler/luet/pkg/helpers/file" "github.com/mudler/luet/pkg/helpers/file"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
) )
var _ = Describe("Extract", func() { var _ = Describe("Extract", func() {
@ -61,10 +62,10 @@ var _ = Describe("Extract", func() {
ExtractFiles(ctx, "", []string{}, []string{}), ExtractFiles(ctx, "", []string{}, []string{}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmpdir) // clean up // defer os.RemoveAll(tmpdir) // clean up
Expect(file.Exists(filepath.Join(tmpdir, "usr", "bin"))).To(BeTrue()) Expect(filepath.Join(tmpdir, "usr", "bin")).To(BeADirectory())
Expect(file.Exists(filepath.Join(tmpdir, "bin", "sh"))).To(BeTrue()) Expect(filepath.Join(tmpdir, "bin", "busybox")).To(BeARegularFile())
}) })
It("Extract specific dir", func() { It("Extract specific dir", func() {
@ -75,9 +76,9 @@ var _ = Describe("Extract", func() {
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmpdir) // clean up defer os.RemoveAll(tmpdir) // clean up
Expect(file.Exists(filepath.Join(tmpdir, "usr", "sbin"))).To(BeTrue()) Expect(filepath.Join(tmpdir, "usr", "sbin")).To(BeADirectory())
Expect(file.Exists(filepath.Join(tmpdir, "usr", "bin"))).To(BeTrue()) Expect(filepath.Join(tmpdir, "usr", "bin")).To(BeADirectory())
Expect(file.Exists(filepath.Join(tmpdir, "bin", "sh"))).To(BeFalse()) Expect(filepath.Join(tmpdir, "bin", "busybox")).ToNot(BeARegularFile())
}) })
It("Extract a dir with includes/excludes", func() { It("Extract a dir with includes/excludes", func() {
@ -103,8 +104,8 @@ var _ = Describe("Extract", func() {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmpdir) // clean up defer os.RemoveAll(tmpdir) // clean up
Expect(file.Exists(filepath.Join(tmpdir, "usr", "bin"))).To(BeTrue()) Expect(filepath.Join(tmpdir, "usr", "bin")).To(BeADirectory())
Expect(file.Exists(filepath.Join(tmpdir, "bin", "sh"))).To(BeFalse()) Expect(filepath.Join(tmpdir, "bin", "busybox")).ToNot(BeARegularFile())
}) })
}) })
}) })

View File

@ -21,6 +21,7 @@ import (
"path/filepath" "path/filepath"
"github.com/mudler/luet/pkg/api/core/types" "github.com/mudler/luet/pkg/api/core/types"
"github.com/mudler/luet/pkg/compiler" "github.com/mudler/luet/pkg/compiler"
"github.com/mudler/luet/pkg/api/core/context" "github.com/mudler/luet/pkg/api/core/context"
@ -91,7 +92,7 @@ ENV PACKAGE_CATEGORY=app-admin`))
} }
Expect(b.BuildImage(opts)).ToNot(HaveOccurred()) Expect(b.BuildImage(opts)).ToNot(HaveOccurred())
Expect(b.ExportImage(opts)).ToNot(HaveOccurred()) Expect(b.ExportImage(opts)).ToNot(HaveOccurred())
Expect(fileHelper.Exists(filepath.Join(tmpdir2, "output1.tar"))).To(BeTrue()) Expect(filepath.Join(tmpdir2, "output1.tar")).To(BeARegularFile())
Expect(b.BuildImage(opts)).ToNot(HaveOccurred()) Expect(b.BuildImage(opts)).ToNot(HaveOccurred())
err = lspec.WriteStepImageDefinition(lspec.Image, filepath.Join(tmpdir, "LuetDockerfile")) err = lspec.WriteStepImageDefinition(lspec.Image, filepath.Join(tmpdir, "LuetDockerfile"))

View File

@ -25,18 +25,20 @@ import (
"sync" "sync"
"github.com/hashicorp/go-multierror" "github.com/hashicorp/go-multierror"
"github.com/mudler/luet/pkg/api/core/config" "github.com/mudler/luet/pkg/api/core/config"
"github.com/mudler/luet/pkg/api/core/logger" "github.com/mudler/luet/pkg/api/core/logger"
"github.com/mudler/luet/pkg/helpers" "github.com/mudler/luet/pkg/helpers"
"github.com/mudler/luet/pkg/tree" "github.com/mudler/luet/pkg/tree"
"github.com/pterm/pterm"
"github.com/mudler/luet/pkg/api/core/bus" "github.com/mudler/luet/pkg/api/core/bus"
"github.com/mudler/luet/pkg/api/core/types" "github.com/mudler/luet/pkg/api/core/types"
artifact "github.com/mudler/luet/pkg/api/core/types/artifact" artifact "github.com/mudler/luet/pkg/api/core/types/artifact"
pkg "github.com/mudler/luet/pkg/database" pkg "github.com/mudler/luet/pkg/database"
fileHelper "github.com/mudler/luet/pkg/helpers/file" fileHelper "github.com/mudler/luet/pkg/helpers/file"
"github.com/mudler/luet/pkg/solver" "github.com/mudler/luet/pkg/solver"
"github.com/pterm/pterm"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -556,6 +558,8 @@ func (l *LuetInstaller) Install(cp types.Packages, s *System) error {
// Resolvers might decide to remove some packages from being installed // Resolvers might decide to remove some packages from being installed
if !solver.IsRelaxedResolver(l.Options.SolverOptions) { if !solver.IsRelaxedResolver(l.Options.SolverOptions) {
var packagesNotFound []string
for _, p := range cp { for _, p := range cp {
found := false found := false
@ -577,18 +581,29 @@ func (l *LuetInstaller) Install(cp types.Packages, s *System) error {
for _, m := range match { for _, m := range match {
if m.Package.GetName() == p.GetName() { if m.Package.GetName() == p.GetName() {
found = true found = true
break
} }
for _, pack := range m.Package.GetProvides() { for _, pack := range m.Package.GetProvides() {
if pack.GetName() == p.GetName() { if pack.GetName() == p.GetName() {
found = true found = true
break
} }
} }
} }
if !found { if !found {
return fmt.Errorf("package '%s' not found", p.HumanReadableString()) packagesNotFound = append(packagesNotFound, p.HumanReadableString())
} }
} }
if len(packagesNotFound) > 0 {
prefix := "package"
if len(packagesNotFound) > 1 {
prefix = "packages"
}
return fmt.Errorf("%s '%s' not found", prefix, strings.Join(packagesNotFound, "', '"))
}
} }
// Check if we have to process something, or return to the user an error // Check if we have to process something, or return to the user an error