2021-04-08 13:22:18 +00:00
|
|
|
// Copyright © 2019 Ettore Di Giacinto <mudler@sabayon.org>
|
2019-11-23 14:43:14 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package installer_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
|
|
// . "github.com/mudler/luet/pkg/installer"
|
2020-05-01 09:47:49 +00:00
|
|
|
|
2021-01-22 18:59:26 +00:00
|
|
|
"fmt"
|
2019-11-23 14:43:14 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2021-01-22 18:59:26 +00:00
|
|
|
"path/filepath"
|
2019-11-23 14:43:14 +00:00
|
|
|
|
2021-10-19 11:05:25 +00:00
|
|
|
"github.com/mudler/luet/pkg/api/core/types"
|
2019-11-23 14:43:14 +00:00
|
|
|
"github.com/mudler/luet/pkg/compiler"
|
|
|
|
backend "github.com/mudler/luet/pkg/compiler/backend"
|
2021-04-12 17:00:36 +00:00
|
|
|
artifact "github.com/mudler/luet/pkg/compiler/types/artifact"
|
2021-06-01 14:43:31 +00:00
|
|
|
compilerspec "github.com/mudler/luet/pkg/compiler/types/spec"
|
2019-11-23 14:43:14 +00:00
|
|
|
"github.com/mudler/luet/pkg/helpers"
|
2021-06-01 14:43:31 +00:00
|
|
|
fileHelper "github.com/mudler/luet/pkg/helpers/file"
|
2019-11-23 14:43:14 +00:00
|
|
|
. "github.com/mudler/luet/pkg/installer"
|
|
|
|
pkg "github.com/mudler/luet/pkg/package"
|
|
|
|
"github.com/mudler/luet/pkg/tree"
|
2021-06-01 14:43:31 +00:00
|
|
|
|
2019-11-23 14:43:14 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
)
|
|
|
|
|
2021-04-12 17:00:36 +00:00
|
|
|
func dockerStubRepo(tmpdir, tree, image string, push, force bool) (*LuetSystemRepository, error) {
|
2021-01-22 18:59:26 +00:00
|
|
|
return GenerateRepository(
|
2021-09-16 10:58:12 +00:00
|
|
|
WithName("test"),
|
|
|
|
WithDescription("description"),
|
|
|
|
WithType("docker"),
|
|
|
|
WithUrls(image),
|
|
|
|
WithPriority(1),
|
|
|
|
WithSource(tmpdir),
|
|
|
|
WithTree(tree),
|
|
|
|
WithDatabase(pkg.NewInMemoryDatabase(false)),
|
|
|
|
WithCompilerBackend(backend.NewSimpleDockerBackend()),
|
|
|
|
WithImagePrefix(image),
|
|
|
|
WithPushImages(push),
|
|
|
|
WithForce(force))
|
2021-01-22 18:59:26 +00:00
|
|
|
}
|
|
|
|
|
2019-11-23 14:43:14 +00:00
|
|
|
var _ = Describe("Repository", func() {
|
|
|
|
Context("Generation", func() {
|
2020-05-01 09:47:49 +00:00
|
|
|
It("Generate repository metadata", func() {
|
|
|
|
|
|
|
|
tmpdir, err := ioutil.TempDir("", "tree")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer os.RemoveAll(tmpdir) // clean up
|
|
|
|
|
|
|
|
generalRecipe := tree.NewCompilerRecipe(pkg.NewInMemoryDatabase(false))
|
|
|
|
|
|
|
|
err = generalRecipe.Load("../../tests/fixtures/buildable")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(len(generalRecipe.GetDatabase().GetPackages())).To(Equal(3))
|
|
|
|
|
2021-04-12 17:00:36 +00:00
|
|
|
compiler := compiler.NewLuetCompiler(backend.NewSimpleDockerBackend(), generalRecipe.GetDatabase())
|
2020-05-01 09:47:49 +00:00
|
|
|
|
|
|
|
spec, err := compiler.FromPackage(&pkg.DefaultPackage{Name: "b", Category: "test", Version: "1.0"})
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(spec.GetPackage().GetPath()).ToNot(Equal(""))
|
|
|
|
|
|
|
|
tmpdir, err = ioutil.TempDir("", "tree")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer os.RemoveAll(tmpdir) // clean up
|
|
|
|
|
2020-12-12 11:10:24 +00:00
|
|
|
Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "chmod +x generate.sh", "./generate.sh"}))
|
|
|
|
Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2"}))
|
2020-05-01 09:47:49 +00:00
|
|
|
|
|
|
|
spec.SetOutputPath(tmpdir)
|
|
|
|
|
|
|
|
artifact, err := compiler.Compile(false, spec)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Exists(artifact.Path)).To(BeTrue())
|
2021-04-12 17:00:36 +00:00
|
|
|
Expect(helpers.Untar(artifact.Path, tmpdir, false)).ToNot(HaveOccurred())
|
2020-05-01 09:47:49 +00:00
|
|
|
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Exists(spec.Rel("test5"))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel("test6"))).To(BeTrue())
|
2020-05-01 09:47:49 +00:00
|
|
|
|
2021-06-01 14:43:31 +00:00
|
|
|
content1, err := fileHelper.Read(spec.Rel("test5"))
|
2020-05-01 09:47:49 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-06-01 14:43:31 +00:00
|
|
|
content2, err := fileHelper.Read(spec.Rel("test6"))
|
2020-05-01 09:47:49 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(content1).To(Equal("artifact5\n"))
|
|
|
|
Expect(content2).To(Equal("artifact6\n"))
|
|
|
|
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Exists(spec.Rel("b-test-1.0.package.tar"))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel("b-test-1.0.metadata.yaml"))).To(BeTrue())
|
2020-05-01 09:47:49 +00:00
|
|
|
|
2021-01-20 16:24:22 +00:00
|
|
|
repo, err := stubRepo(tmpdir, "../../tests/fixtures/buildable")
|
2020-05-01 09:47:49 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(repo.GetName()).To(Equal("test"))
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Exists(spec.Rel(REPOSITORY_SPECFILE))).ToNot(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(TREE_TARBALL + ".gz"))).ToNot(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(REPOSITORY_METAFILE + ".tar"))).ToNot(BeTrue())
|
2021-01-18 16:58:32 +00:00
|
|
|
err = repo.Write(tmpdir, false, true)
|
2020-05-01 09:47:49 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Exists(spec.Rel(REPOSITORY_SPECFILE))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(TREE_TARBALL + ".gz"))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(REPOSITORY_METAFILE + ".tar"))).To(BeTrue())
|
2020-05-01 09:47:49 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("Generate repository metadata of files ONLY referenced in a tree", func() {
|
2019-11-23 14:43:14 +00:00
|
|
|
|
|
|
|
tmpdir, err := ioutil.TempDir("", "tree")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer os.RemoveAll(tmpdir) // clean up
|
|
|
|
|
|
|
|
generalRecipe := tree.NewCompilerRecipe(pkg.NewInMemoryDatabase(false))
|
|
|
|
|
|
|
|
err = generalRecipe.Load("../../tests/fixtures/buildable")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2020-05-01 09:47:49 +00:00
|
|
|
generalRecipe2 := tree.NewCompilerRecipe(pkg.NewInMemoryDatabase(false))
|
|
|
|
|
|
|
|
err = generalRecipe2.Load("../../tests/fixtures/finalizers")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(len(generalRecipe2.GetDatabase().GetPackages())).To(Equal(1))
|
2019-11-29 18:01:52 +00:00
|
|
|
Expect(len(generalRecipe.GetDatabase().GetPackages())).To(Equal(3))
|
2019-11-23 14:43:14 +00:00
|
|
|
|
2021-04-12 17:00:36 +00:00
|
|
|
compiler2 := compiler.NewLuetCompiler(backend.NewSimpleDockerBackend(), generalRecipe2.GetDatabase())
|
2020-05-01 09:47:49 +00:00
|
|
|
spec2, err := compiler2.FromPackage(&pkg.DefaultPackage{Name: "alpine", Category: "seed", Version: "1.0"})
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2021-04-12 17:00:36 +00:00
|
|
|
compiler := compiler.NewLuetCompiler(backend.NewSimpleDockerBackend(), generalRecipe.GetDatabase())
|
2019-11-23 14:43:14 +00:00
|
|
|
|
|
|
|
spec, err := compiler.FromPackage(&pkg.DefaultPackage{Name: "b", Category: "test", Version: "1.0"})
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(spec.GetPackage().GetPath()).ToNot(Equal(""))
|
2020-05-01 09:47:49 +00:00
|
|
|
Expect(spec2.GetPackage().GetPath()).ToNot(Equal(""))
|
2019-11-23 14:43:14 +00:00
|
|
|
|
|
|
|
tmpdir, err = ioutil.TempDir("", "tree")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer os.RemoveAll(tmpdir) // clean up
|
|
|
|
|
2020-12-12 11:10:24 +00:00
|
|
|
Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "chmod +x generate.sh", "./generate.sh"}))
|
|
|
|
Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2"}))
|
2019-11-23 14:43:14 +00:00
|
|
|
|
|
|
|
spec.SetOutputPath(tmpdir)
|
2020-05-01 09:47:49 +00:00
|
|
|
spec2.SetOutputPath(tmpdir)
|
2019-12-30 13:46:45 +00:00
|
|
|
|
|
|
|
artifact, err := compiler.Compile(false, spec)
|
2019-11-23 14:43:14 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Exists(artifact.Path)).To(BeTrue())
|
2021-04-12 17:00:36 +00:00
|
|
|
Expect(helpers.Untar(artifact.Path, tmpdir, false)).ToNot(HaveOccurred())
|
2019-11-23 14:43:14 +00:00
|
|
|
|
2020-05-01 09:47:49 +00:00
|
|
|
artifact2, err := compiler2.Compile(false, spec2)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Exists(artifact2.Path)).To(BeTrue())
|
2021-04-12 17:00:36 +00:00
|
|
|
Expect(helpers.Untar(artifact2.Path, tmpdir, false)).ToNot(HaveOccurred())
|
2020-05-01 09:47:49 +00:00
|
|
|
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Exists(spec.Rel("test5"))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel("test6"))).To(BeTrue())
|
2019-11-23 14:43:14 +00:00
|
|
|
|
2021-06-01 14:43:31 +00:00
|
|
|
content1, err := fileHelper.Read(spec.Rel("test5"))
|
2019-11-23 14:43:14 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-06-01 14:43:31 +00:00
|
|
|
content2, err := fileHelper.Read(spec.Rel("test6"))
|
2019-11-23 14:43:14 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(content1).To(Equal("artifact5\n"))
|
|
|
|
Expect(content2).To(Equal("artifact6\n"))
|
|
|
|
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Exists(spec.Rel("b-test-1.0.package.tar"))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel("b-test-1.0.metadata.yaml"))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec2.Rel("alpine-seed-1.0.package.tar"))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec2.Rel("alpine-seed-1.0.metadata.yaml"))).To(BeTrue())
|
2019-11-23 14:43:14 +00:00
|
|
|
|
2021-01-20 16:24:22 +00:00
|
|
|
repo, err := stubRepo(tmpdir, "../../tests/fixtures/buildable")
|
2019-11-23 14:43:14 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(repo.GetName()).To(Equal("test"))
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Exists(spec.Rel(REPOSITORY_SPECFILE))).ToNot(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(TREE_TARBALL + ".gz"))).ToNot(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(REPOSITORY_METAFILE + ".tar"))).ToNot(BeTrue())
|
2021-01-18 16:58:32 +00:00
|
|
|
err = repo.Write(tmpdir, false, true)
|
2019-11-23 14:43:14 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Exists(spec.Rel(REPOSITORY_SPECFILE))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(TREE_TARBALL + ".gz"))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(REPOSITORY_METAFILE + ".tar"))).To(BeTrue())
|
2020-05-01 09:47:49 +00:00
|
|
|
|
|
|
|
// We check now that the artifact not referenced in the tree
|
|
|
|
// (spec2) is not indexed in the repository
|
|
|
|
repository, err := NewLuetSystemRepositoryFromYaml([]byte(`
|
|
|
|
name: "test"
|
|
|
|
type: "disk"
|
|
|
|
urls:
|
|
|
|
- "`+tmpdir+`"
|
|
|
|
`), pkg.NewInMemoryDatabase(false))
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
repos, err := repository.Sync(true)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
_, err = repos.GetTree().GetDatabase().FindPackage(spec.GetPackage())
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
_, err = repos.GetTree().GetDatabase().FindPackage(spec2.GetPackage())
|
|
|
|
Expect(err).To(HaveOccurred()) // should throw error
|
2019-11-23 14:43:14 +00:00
|
|
|
})
|
2021-09-16 10:58:12 +00:00
|
|
|
|
|
|
|
It("Generate repository metadata of files referenced in a tree and from packages", func() {
|
|
|
|
|
|
|
|
tmpdir, err := ioutil.TempDir("", "tree")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer os.RemoveAll(tmpdir) // clean up
|
|
|
|
|
|
|
|
generalRecipe := tree.NewCompilerRecipe(pkg.NewInMemoryDatabase(false))
|
|
|
|
|
|
|
|
err = generalRecipe.Load("../../tests/fixtures/buildable")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
generalRecipe2 := tree.NewCompilerRecipe(pkg.NewInMemoryDatabase(false))
|
|
|
|
|
|
|
|
err = generalRecipe2.Load("../../tests/fixtures/finalizers")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(len(generalRecipe2.GetDatabase().GetPackages())).To(Equal(1))
|
|
|
|
Expect(len(generalRecipe.GetDatabase().GetPackages())).To(Equal(3))
|
|
|
|
|
|
|
|
compiler2 := compiler.NewLuetCompiler(backend.NewSimpleDockerBackend(), generalRecipe2.GetDatabase())
|
|
|
|
spec2, err := compiler2.FromPackage(&pkg.DefaultPackage{Name: "alpine", Category: "seed", Version: "1.0"})
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
compiler := compiler.NewLuetCompiler(backend.NewSimpleDockerBackend(), generalRecipe.GetDatabase())
|
|
|
|
|
|
|
|
spec, err := compiler.FromPackage(&pkg.DefaultPackage{Name: "b", Category: "test", Version: "1.0"})
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(spec.GetPackage().GetPath()).ToNot(Equal(""))
|
|
|
|
Expect(spec2.GetPackage().GetPath()).ToNot(Equal(""))
|
|
|
|
|
|
|
|
tmpdir, err = ioutil.TempDir("", "tree")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer os.RemoveAll(tmpdir) // clean up
|
|
|
|
|
|
|
|
Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "chmod +x generate.sh", "./generate.sh"}))
|
|
|
|
Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2"}))
|
|
|
|
|
|
|
|
spec.SetOutputPath(tmpdir)
|
|
|
|
spec2.SetOutputPath(tmpdir)
|
|
|
|
|
|
|
|
artifact, err := compiler.Compile(false, spec)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(fileHelper.Exists(artifact.Path)).To(BeTrue())
|
|
|
|
Expect(helpers.Untar(artifact.Path, tmpdir, false)).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
artifact2, err := compiler2.Compile(false, spec2)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(fileHelper.Exists(artifact2.Path)).To(BeTrue())
|
|
|
|
Expect(helpers.Untar(artifact2.Path, tmpdir, false)).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(fileHelper.Exists(spec.Rel("test5"))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel("test6"))).To(BeTrue())
|
|
|
|
|
|
|
|
content1, err := fileHelper.Read(spec.Rel("test5"))
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
content2, err := fileHelper.Read(spec.Rel("test6"))
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(content1).To(Equal("artifact5\n"))
|
|
|
|
Expect(content2).To(Equal("artifact6\n"))
|
|
|
|
|
|
|
|
// will contain both
|
|
|
|
Expect(fileHelper.Exists(spec.Rel("b-test-1.0.package.tar"))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel("b-test-1.0.metadata.yaml"))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec2.Rel("alpine-seed-1.0.package.tar"))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec2.Rel("alpine-seed-1.0.metadata.yaml"))).To(BeTrue())
|
|
|
|
|
|
|
|
repo, err := GenerateRepository(
|
|
|
|
WithName("test"),
|
|
|
|
WithDescription("description"),
|
|
|
|
WithType("disk"),
|
|
|
|
WithUrls(tmpdir),
|
|
|
|
WithPriority(1),
|
|
|
|
WithSource(tmpdir),
|
|
|
|
FromMetadata(true), // Enabling from metadata makes the package visible
|
|
|
|
WithTree("../../tests/fixtures/buildable"),
|
|
|
|
WithDatabase(pkg.NewInMemoryDatabase(false)),
|
|
|
|
)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(repo.GetName()).To(Equal("test"))
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(REPOSITORY_SPECFILE))).ToNot(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(TREE_TARBALL + ".gz"))).ToNot(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(REPOSITORY_METAFILE + ".tar"))).ToNot(BeTrue())
|
|
|
|
err = repo.Write(tmpdir, false, true)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(REPOSITORY_SPECFILE))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(TREE_TARBALL + ".gz"))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(REPOSITORY_METAFILE + ".tar"))).To(BeTrue())
|
|
|
|
|
|
|
|
// We check now that the artifact not referenced in the tree
|
|
|
|
// (spec2) is not indexed in the repository
|
|
|
|
repository, err := NewLuetSystemRepositoryFromYaml([]byte(`
|
|
|
|
name: "test"
|
|
|
|
type: "disk"
|
|
|
|
urls:
|
|
|
|
- "`+tmpdir+`"
|
|
|
|
`), pkg.NewInMemoryDatabase(false))
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
repos, err := repository.Sync(true)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
_, err = repos.GetTree().GetDatabase().FindPackage(spec.GetPackage())
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
_, err = repos.GetTree().GetDatabase().FindPackage(spec2.GetPackage())
|
|
|
|
Expect(err).ToNot(HaveOccurred()) // should NOT throw error
|
|
|
|
})
|
2019-11-23 14:43:14 +00:00
|
|
|
})
|
|
|
|
Context("Matching packages", func() {
|
|
|
|
It("Matches packages in different repositories by priority", func() {
|
|
|
|
package1 := &pkg.DefaultPackage{Name: "Test"}
|
|
|
|
package2 := &pkg.DefaultPackage{Name: "Test2"}
|
|
|
|
builder1 := tree.NewInstallerRecipe(pkg.NewInMemoryDatabase(false))
|
|
|
|
builder2 := tree.NewInstallerRecipe(pkg.NewInMemoryDatabase(false))
|
|
|
|
|
2019-11-29 18:01:52 +00:00
|
|
|
_, err := builder1.GetDatabase().CreatePackage(package1)
|
2019-11-23 14:43:14 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2019-11-29 18:01:52 +00:00
|
|
|
_, err = builder2.GetDatabase().CreatePackage(package2)
|
2019-11-23 14:43:14 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-10-19 11:05:25 +00:00
|
|
|
repo1 := &LuetSystemRepository{LuetRepository: &types.LuetRepository{Name: "test1"}, Tree: builder1}
|
|
|
|
repo2 := &LuetSystemRepository{LuetRepository: &types.LuetRepository{Name: "test2"}, Tree: builder2}
|
2019-11-23 14:43:14 +00:00
|
|
|
repositories := Repositories{repo1, repo2}
|
|
|
|
matches := repositories.PackageMatches([]pkg.Package{package1})
|
|
|
|
Expect(matches).To(Equal([]PackageMatch{{Repo: repo1, Package: package1}}))
|
|
|
|
|
|
|
|
})
|
2021-01-22 18:59:26 +00:00
|
|
|
})
|
|
|
|
Context("Docker repository", func() {
|
|
|
|
repoImage := os.Getenv("UNIT_TEST_DOCKER_IMAGE_REPOSITORY")
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
|
|
|
if repoImage == "" {
|
|
|
|
Skip("UNIT_TEST_DOCKER_IMAGE_REPOSITORY not specified")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
It("generates images", func() {
|
|
|
|
b := backend.NewSimpleDockerBackend()
|
|
|
|
tmpdir, err := ioutil.TempDir("", "tree")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer os.RemoveAll(tmpdir) // clean up
|
|
|
|
|
|
|
|
generalRecipe := tree.NewCompilerRecipe(pkg.NewInMemoryDatabase(false))
|
|
|
|
|
|
|
|
err = generalRecipe.Load("../../tests/fixtures/buildable")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(len(generalRecipe.GetDatabase().GetPackages())).To(Equal(3))
|
|
|
|
|
2021-04-12 17:00:36 +00:00
|
|
|
localcompiler := compiler.NewLuetCompiler(backend.NewSimpleDockerBackend(), generalRecipe.GetDatabase())
|
2021-01-22 18:59:26 +00:00
|
|
|
|
|
|
|
spec, err := localcompiler.FromPackage(&pkg.DefaultPackage{Name: "b", Category: "test", Version: "1.0"})
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(spec.GetPackage().GetPath()).ToNot(Equal(""))
|
|
|
|
|
|
|
|
tmpdir, err = ioutil.TempDir("", "tree")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer os.RemoveAll(tmpdir) // clean up
|
2019-11-23 14:43:14 +00:00
|
|
|
|
2021-01-22 18:59:26 +00:00
|
|
|
spec.SetOutputPath(tmpdir)
|
|
|
|
|
2021-04-12 17:00:36 +00:00
|
|
|
a, err := localcompiler.Compile(false, spec)
|
2021-01-22 18:59:26 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Exists(a.Path)).To(BeTrue())
|
2021-04-12 17:00:36 +00:00
|
|
|
Expect(helpers.Untar(a.Path, tmpdir, false)).ToNot(HaveOccurred())
|
2021-01-22 18:59:26 +00:00
|
|
|
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Exists(spec.Rel("test5"))).To(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel("test6"))).To(BeTrue())
|
2021-01-22 18:59:26 +00:00
|
|
|
|
|
|
|
repo, err := dockerStubRepo(tmpdir, "../../tests/fixtures/buildable", repoImage, true, true)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(repo.GetName()).To(Equal("test"))
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Exists(spec.Rel(REPOSITORY_SPECFILE))).ToNot(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(TREE_TARBALL + ".gz"))).ToNot(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(REPOSITORY_METAFILE + ".tar"))).ToNot(BeTrue())
|
2021-01-22 18:59:26 +00:00
|
|
|
err = repo.Write(repoImage, false, true)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(b.ImageAvailable(fmt.Sprintf("%s:%s", repoImage, "tree.tar.gz"))).To(BeTrue())
|
|
|
|
Expect(b.ImageAvailable(fmt.Sprintf("%s:%s", repoImage, "repository.meta.yaml.tar"))).To(BeTrue())
|
|
|
|
Expect(b.ImageAvailable(fmt.Sprintf("%s:%s", repoImage, "repository.yaml"))).To(BeTrue())
|
|
|
|
Expect(b.ImageAvailable(fmt.Sprintf("%s:%s", repoImage, "b-test-1.0"))).To(BeTrue())
|
|
|
|
|
|
|
|
extracted, err := ioutil.TempDir("", "extracted")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer os.RemoveAll(extracted) // clean up
|
|
|
|
|
|
|
|
c := repo.Client()
|
|
|
|
|
|
|
|
f, err := c.DownloadFile("repository.yaml")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Read(f)).To(ContainSubstring("name: test"))
|
2021-01-22 18:59:26 +00:00
|
|
|
|
2021-04-12 17:00:36 +00:00
|
|
|
a, err = c.DownloadArtifact(&artifact.PackageArtifact{
|
2021-01-22 18:59:26 +00:00
|
|
|
Path: "test.tar",
|
2021-04-12 17:00:36 +00:00
|
|
|
CompileSpec: &compilerspec.LuetCompilationSpec{
|
2021-01-22 18:59:26 +00:00
|
|
|
Package: &pkg.DefaultPackage{
|
|
|
|
Name: "b",
|
|
|
|
Category: "test",
|
|
|
|
Version: "1.0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(a.Unpack(extracted, false)).ToNot(HaveOccurred())
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Read(filepath.Join(extracted, "test6"))).To(Equal("artifact6\n"))
|
2021-01-22 18:59:26 +00:00
|
|
|
})
|
2021-02-09 16:27:25 +00:00
|
|
|
|
|
|
|
It("generates images of virtual packages", func() {
|
|
|
|
b := backend.NewSimpleDockerBackend()
|
|
|
|
tmpdir, err := ioutil.TempDir("", "tree")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer os.RemoveAll(tmpdir) // clean up
|
|
|
|
|
|
|
|
generalRecipe := tree.NewCompilerRecipe(pkg.NewInMemoryDatabase(false))
|
|
|
|
|
|
|
|
err = generalRecipe.Load("../../tests/fixtures/virtuals")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(len(generalRecipe.GetDatabase().GetPackages())).To(Equal(5))
|
|
|
|
|
2021-04-12 17:00:36 +00:00
|
|
|
localcompiler := compiler.NewLuetCompiler(backend.NewSimpleDockerBackend(), generalRecipe.GetDatabase())
|
2021-02-09 16:27:25 +00:00
|
|
|
|
|
|
|
spec, err := localcompiler.FromPackage(&pkg.DefaultPackage{Name: "a", Category: "test", Version: "1.99"})
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(spec.GetPackage().GetPath()).ToNot(Equal(""))
|
|
|
|
|
|
|
|
tmpdir, err = ioutil.TempDir("", "tree")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer os.RemoveAll(tmpdir) // clean up
|
|
|
|
|
|
|
|
spec.SetOutputPath(tmpdir)
|
|
|
|
|
2021-04-12 17:00:36 +00:00
|
|
|
a, err := localcompiler.Compile(false, spec)
|
2021-02-09 16:27:25 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Exists(a.Path)).To(BeTrue())
|
2021-04-12 17:00:36 +00:00
|
|
|
Expect(helpers.Untar(a.Path, tmpdir, false)).ToNot(HaveOccurred())
|
2021-02-09 16:27:25 +00:00
|
|
|
|
|
|
|
repo, err := dockerStubRepo(tmpdir, "../../tests/fixtures/virtuals", repoImage, true, true)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(repo.GetName()).To(Equal("test"))
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Exists(spec.Rel(REPOSITORY_SPECFILE))).ToNot(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(TREE_TARBALL + ".gz"))).ToNot(BeTrue())
|
|
|
|
Expect(fileHelper.Exists(spec.Rel(REPOSITORY_METAFILE + ".tar"))).ToNot(BeTrue())
|
2021-02-09 16:27:25 +00:00
|
|
|
err = repo.Write(repoImage, false, true)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(b.ImageAvailable(fmt.Sprintf("%s:%s", repoImage, "tree.tar.gz"))).To(BeTrue())
|
|
|
|
Expect(b.ImageAvailable(fmt.Sprintf("%s:%s", repoImage, "repository.meta.yaml.tar"))).To(BeTrue())
|
|
|
|
Expect(b.ImageAvailable(fmt.Sprintf("%s:%s", repoImage, "repository.yaml"))).To(BeTrue())
|
|
|
|
Expect(b.ImageAvailable(fmt.Sprintf("%s:%s", repoImage, "a-test-1.99"))).To(BeTrue())
|
|
|
|
|
|
|
|
extracted, err := ioutil.TempDir("", "extracted")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer os.RemoveAll(extracted) // clean up
|
|
|
|
|
|
|
|
c := repo.Client()
|
|
|
|
|
|
|
|
f, err := c.DownloadFile("repository.yaml")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.Read(f)).To(ContainSubstring("name: test"))
|
2021-02-09 16:27:25 +00:00
|
|
|
|
2021-04-12 17:00:36 +00:00
|
|
|
a, err = c.DownloadArtifact(&artifact.PackageArtifact{
|
2021-02-09 16:27:25 +00:00
|
|
|
Path: "test.tar",
|
2021-04-12 17:00:36 +00:00
|
|
|
CompileSpec: &compilerspec.LuetCompilationSpec{
|
2021-02-09 16:27:25 +00:00
|
|
|
Package: &pkg.DefaultPackage{
|
|
|
|
Name: "a",
|
|
|
|
Category: "test",
|
|
|
|
Version: "1.99",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(a.Unpack(extracted, false)).ToNot(HaveOccurred())
|
|
|
|
|
2021-06-01 14:43:31 +00:00
|
|
|
Expect(fileHelper.DirectoryIsEmpty(extracted)).To(BeFalse())
|
2021-02-09 16:27:25 +00:00
|
|
|
content, err := ioutil.ReadFile(filepath.Join(extracted, ".virtual"))
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(string(content)).To(Equal(""))
|
|
|
|
})
|
2021-03-06 16:22:01 +00:00
|
|
|
|
|
|
|
It("Searches files", func() {
|
|
|
|
repos := Repositories{
|
|
|
|
&LuetSystemRepository{
|
|
|
|
Index: compiler.ArtifactIndex{
|
2021-04-12 17:00:36 +00:00
|
|
|
&artifact.PackageArtifact{
|
|
|
|
CompileSpec: &compilerspec.LuetCompilationSpec{
|
2021-03-06 16:22:01 +00:00
|
|
|
Package: &pkg.DefaultPackage{},
|
|
|
|
},
|
|
|
|
Path: "bar",
|
|
|
|
Files: []string{"boo"},
|
|
|
|
},
|
2021-04-12 17:00:36 +00:00
|
|
|
&artifact.PackageArtifact{
|
2021-03-06 16:22:01 +00:00
|
|
|
Path: "d",
|
|
|
|
Files: []string{"baz"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
matches := repos.SearchPackages("bo", FileSearch)
|
|
|
|
Expect(len(matches)).To(Equal(1))
|
2021-04-12 17:00:36 +00:00
|
|
|
Expect(matches[0].Artifact.Path).To(Equal("bar"))
|
2021-03-06 16:22:01 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("Searches packages", func() {
|
|
|
|
repo := &LuetSystemRepository{
|
|
|
|
Index: compiler.ArtifactIndex{
|
2021-04-12 17:00:36 +00:00
|
|
|
&artifact.PackageArtifact{
|
2021-03-06 16:22:01 +00:00
|
|
|
Path: "foo",
|
2021-04-12 17:00:36 +00:00
|
|
|
CompileSpec: &compilerspec.LuetCompilationSpec{
|
2021-03-06 16:22:01 +00:00
|
|
|
Package: &pkg.DefaultPackage{
|
|
|
|
Name: "foo",
|
|
|
|
Category: "bar",
|
|
|
|
Version: "1.0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-04-12 17:00:36 +00:00
|
|
|
&artifact.PackageArtifact{
|
2021-03-06 16:22:01 +00:00
|
|
|
Path: "baz",
|
2021-04-12 17:00:36 +00:00
|
|
|
CompileSpec: &compilerspec.LuetCompilationSpec{
|
2021-03-06 16:22:01 +00:00
|
|
|
Package: &pkg.DefaultPackage{
|
|
|
|
Name: "foo",
|
|
|
|
Category: "baz",
|
|
|
|
Version: "1.0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
a, err := repo.SearchArtefact(&pkg.DefaultPackage{
|
|
|
|
Name: "foo",
|
|
|
|
Category: "baz",
|
|
|
|
Version: "1.0",
|
|
|
|
})
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-04-12 17:00:36 +00:00
|
|
|
Expect(a.Path).To(Equal("baz"))
|
2021-03-06 16:22:01 +00:00
|
|
|
|
|
|
|
a, err = repo.SearchArtefact(&pkg.DefaultPackage{
|
|
|
|
Name: "foo",
|
|
|
|
Category: "bar",
|
|
|
|
Version: "1.0",
|
|
|
|
})
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-04-12 17:00:36 +00:00
|
|
|
Expect(a.Path).To(Equal("foo"))
|
2021-03-06 16:22:01 +00:00
|
|
|
|
|
|
|
// Doesn't exist. so must fail
|
|
|
|
_, err = repo.SearchArtefact(&pkg.DefaultPackage{
|
|
|
|
Name: "foo",
|
|
|
|
Category: "bar",
|
|
|
|
Version: "1.1",
|
|
|
|
})
|
|
|
|
Expect(err).To(HaveOccurred())
|
|
|
|
})
|
2019-11-23 14:43:14 +00:00
|
|
|
})
|
|
|
|
})
|