mirror of
https://github.com/mudler/luet.git
synced 2025-09-05 01:00:44 +00:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
db8bf2b85e | ||
|
5eb586ddb0 | ||
|
f9747cdf87 | ||
|
becac7d853 | ||
|
5aa5bffb48 | ||
|
9aa3159787 | ||
|
9cb6e65bb6 | ||
|
92b243d7aa |
49
.chglog/CHANGELOG.tpl.md
Normal file
49
.chglog/CHANGELOG.tpl.md
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
{{ if .Versions -}}
|
||||||
|
{{ if .Unreleased.CommitGroups -}}
|
||||||
|
{{ range .Unreleased.CommitGroups -}}
|
||||||
|
### {{ .Title }}
|
||||||
|
{{ range .Commits -}}
|
||||||
|
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end -}}
|
||||||
|
{{ else }}
|
||||||
|
{{ range .Unreleased.Commits -}}
|
||||||
|
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end -}}
|
||||||
|
{{ end -}}
|
||||||
|
|
||||||
|
{{ range .Versions }}
|
||||||
|
<a name="{{ .Tag.Name }}"></a>
|
||||||
|
|
||||||
|
{{ if .CommitGroups -}}
|
||||||
|
{{ range .CommitGroups -}}
|
||||||
|
### {{ .Title }}
|
||||||
|
{{ range .Commits -}}
|
||||||
|
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end -}}
|
||||||
|
{{ else }}
|
||||||
|
{{ range .Commits -}}
|
||||||
|
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} (https://github.com/mudler/luet/commit/{{.Hash.Short}})
|
||||||
|
{{ end }}
|
||||||
|
{{ end -}}
|
||||||
|
|
||||||
|
{{- if .NoteGroups -}}
|
||||||
|
{{ range .NoteGroups -}}
|
||||||
|
### {{ .Title }}
|
||||||
|
{{ range .Notes }}
|
||||||
|
{{ .Body }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end -}}
|
||||||
|
{{ end -}}
|
||||||
|
{{ end -}}
|
||||||
|
|
||||||
|
{{- if .Versions }}
|
||||||
|
[Unreleased]: {{ .Info.RepositoryURL }}/compare/{{ $latest := index .Versions 0 }}{{ $latest.Tag.Name }}...HEAD
|
||||||
|
{{ range .Versions -}}
|
||||||
|
{{ if .Tag.Previous -}}
|
||||||
|
[{{ .Tag.Name }}]: {{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}
|
||||||
|
{{ end -}}
|
||||||
|
{{ end -}}
|
||||||
|
{{ end -}}
|
27
.chglog/config.yml
Executable file
27
.chglog/config.yml
Executable file
@@ -0,0 +1,27 @@
|
|||||||
|
style: github
|
||||||
|
template: CHANGELOG.tpl.md
|
||||||
|
info:
|
||||||
|
title: CHANGELOG
|
||||||
|
repository_url: https://github.com/mudler/luet
|
||||||
|
options:
|
||||||
|
commits:
|
||||||
|
# filters:
|
||||||
|
# Type:
|
||||||
|
# - feat
|
||||||
|
# - fix
|
||||||
|
# - perf
|
||||||
|
# - refactor
|
||||||
|
commit_groups:
|
||||||
|
title_maps:
|
||||||
|
feat: Features
|
||||||
|
fix: Bug Fixes
|
||||||
|
perf: Performance Improvements
|
||||||
|
refactor: Code Refactoring
|
||||||
|
ci: Continous Integration
|
||||||
|
header:
|
||||||
|
pattern: "(.*)"
|
||||||
|
pattern_maps:
|
||||||
|
- Subject
|
||||||
|
notes:
|
||||||
|
keywords:
|
||||||
|
- BREAKING CHANGE
|
143
cmd/reinstall.go
Normal file
143
cmd/reinstall.go
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
// Copyright © 2021 Ettore Di Giacinto <mudler@mocaccino.org>
|
||||||
|
//
|
||||||
|
// 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 cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
installer "github.com/mudler/luet/pkg/installer"
|
||||||
|
"github.com/mudler/luet/pkg/solver"
|
||||||
|
|
||||||
|
helpers "github.com/mudler/luet/cmd/helpers"
|
||||||
|
. "github.com/mudler/luet/pkg/config"
|
||||||
|
. "github.com/mudler/luet/pkg/logger"
|
||||||
|
pkg "github.com/mudler/luet/pkg/package"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var reinstallCmd = &cobra.Command{
|
||||||
|
Use: "reinstall <pkg1> <pkg2> <pkg3>",
|
||||||
|
Short: "reinstall a set of packages",
|
||||||
|
Long: `Reinstall a group of packages in the system:
|
||||||
|
|
||||||
|
$ luet reinstall -y system/busybox shells/bash system/coreutils ...
|
||||||
|
`,
|
||||||
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
LuetCfg.Viper.BindPFlag("system.database_path", cmd.Flags().Lookup("system-dbpath"))
|
||||||
|
LuetCfg.Viper.BindPFlag("system.database_engine", cmd.Flags().Lookup("system-engine"))
|
||||||
|
LuetCfg.Viper.BindPFlag("system.rootfs", cmd.Flags().Lookup("system-target"))
|
||||||
|
LuetCfg.Viper.BindPFlag("solver.type", cmd.Flags().Lookup("solver-type"))
|
||||||
|
LuetCfg.Viper.BindPFlag("solver.discount", cmd.Flags().Lookup("solver-discount"))
|
||||||
|
LuetCfg.Viper.BindPFlag("solver.rate", cmd.Flags().Lookup("solver-rate"))
|
||||||
|
LuetCfg.Viper.BindPFlag("solver.max_attempts", cmd.Flags().Lookup("solver-attempts"))
|
||||||
|
LuetCfg.Viper.BindPFlag("onlydeps", cmd.Flags().Lookup("onlydeps"))
|
||||||
|
LuetCfg.Viper.BindPFlag("force", cmd.Flags().Lookup("force"))
|
||||||
|
LuetCfg.Viper.BindPFlag("for", cmd.Flags().Lookup("for"))
|
||||||
|
|
||||||
|
LuetCfg.Viper.BindPFlag("yes", cmd.Flags().Lookup("yes"))
|
||||||
|
},
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
var toUninstall pkg.Packages
|
||||||
|
var toAdd pkg.Packages
|
||||||
|
|
||||||
|
stype := LuetCfg.Viper.GetString("solver.type")
|
||||||
|
discount := LuetCfg.Viper.GetFloat64("solver.discount")
|
||||||
|
rate := LuetCfg.Viper.GetFloat64("solver.rate")
|
||||||
|
attempts := LuetCfg.Viper.GetInt("solver.max_attempts")
|
||||||
|
force := LuetCfg.Viper.GetBool("force")
|
||||||
|
onlydeps := LuetCfg.Viper.GetBool("onlydeps")
|
||||||
|
concurrent, _ := cmd.Flags().GetBool("solver-concurrent")
|
||||||
|
yes := LuetCfg.Viper.GetBool("yes")
|
||||||
|
dbpath := LuetCfg.Viper.GetString("system.database_path")
|
||||||
|
rootfs := LuetCfg.Viper.GetString("system.rootfs")
|
||||||
|
engine := LuetCfg.Viper.GetString("system.database_engine")
|
||||||
|
downloadOnly, _ := cmd.Flags().GetBool("download-only")
|
||||||
|
|
||||||
|
LuetCfg.System.DatabaseEngine = engine
|
||||||
|
LuetCfg.System.DatabasePath = dbpath
|
||||||
|
LuetCfg.System.Rootfs = rootfs
|
||||||
|
|
||||||
|
for _, a := range args {
|
||||||
|
pack, err := helpers.ParsePackageStr(a)
|
||||||
|
if err != nil {
|
||||||
|
Fatal("Invalid package string ", a, ": ", err.Error())
|
||||||
|
}
|
||||||
|
toUninstall = append(toUninstall, pack)
|
||||||
|
toAdd = append(toAdd, pack)
|
||||||
|
}
|
||||||
|
|
||||||
|
// This shouldn't be necessary, but we need to unmarshal the repositories to a concrete struct, thus we need to port them back to the Repositories type
|
||||||
|
repos := installer.Repositories{}
|
||||||
|
for _, repo := range LuetCfg.SystemRepositories {
|
||||||
|
if !repo.Enable {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
r := installer.NewSystemRepository(repo)
|
||||||
|
repos = append(repos, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
LuetCfg.GetSolverOptions().Type = stype
|
||||||
|
LuetCfg.GetSolverOptions().LearnRate = float32(rate)
|
||||||
|
LuetCfg.GetSolverOptions().Discount = float32(discount)
|
||||||
|
LuetCfg.GetSolverOptions().MaxAttempts = attempts
|
||||||
|
|
||||||
|
if concurrent {
|
||||||
|
LuetCfg.GetSolverOptions().Implementation = solver.ParallelSimple
|
||||||
|
} else {
|
||||||
|
LuetCfg.GetSolverOptions().Implementation = solver.SingleCoreSimple
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug("Solver", LuetCfg.GetSolverOptions().CompactString())
|
||||||
|
|
||||||
|
// Load config protect configs
|
||||||
|
installer.LoadConfigProtectConfs(LuetCfg)
|
||||||
|
|
||||||
|
inst := installer.NewLuetInstaller(installer.LuetInstallerOptions{
|
||||||
|
Concurrency: LuetCfg.GetGeneral().Concurrency,
|
||||||
|
SolverOptions: *LuetCfg.GetSolverOptions(),
|
||||||
|
NoDeps: true,
|
||||||
|
Force: force,
|
||||||
|
OnlyDeps: onlydeps,
|
||||||
|
PreserveSystemEssentialData: true,
|
||||||
|
Ask: !yes,
|
||||||
|
DownloadOnly: downloadOnly,
|
||||||
|
})
|
||||||
|
inst.Repositories(repos)
|
||||||
|
|
||||||
|
system := &installer.System{Database: LuetCfg.GetSystemDB(), Target: LuetCfg.GetSystem().Rootfs}
|
||||||
|
err := inst.Swap(toUninstall, toAdd, system)
|
||||||
|
if err != nil {
|
||||||
|
Fatal("Error: " + err.Error())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
|
||||||
|
reinstallCmd.Flags().String("system-dbpath", "", "System db path")
|
||||||
|
reinstallCmd.Flags().String("system-target", "", "System rootpath")
|
||||||
|
reinstallCmd.Flags().String("system-engine", "", "System DB engine")
|
||||||
|
|
||||||
|
reinstallCmd.Flags().String("solver-type", "", "Solver strategy ( Defaults none, available: "+AvailableResolvers+" )")
|
||||||
|
reinstallCmd.Flags().Float32("solver-rate", 0.7, "Solver learning rate")
|
||||||
|
reinstallCmd.Flags().Float32("solver-discount", 1.0, "Solver discount rate")
|
||||||
|
reinstallCmd.Flags().Int("solver-attempts", 9000, "Solver maximum attempts")
|
||||||
|
reinstallCmd.Flags().Bool("onlydeps", false, "Consider **only** package dependencies")
|
||||||
|
reinstallCmd.Flags().Bool("force", false, "Skip errors and keep going (potentially harmful)")
|
||||||
|
reinstallCmd.Flags().Bool("solver-concurrent", false, "Use concurrent solver (experimental)")
|
||||||
|
reinstallCmd.Flags().BoolP("yes", "y", false, "Don't ask questions")
|
||||||
|
reinstallCmd.Flags().Bool("download-only", false, "Download only")
|
||||||
|
|
||||||
|
RootCmd.AddCommand(reinstallCmd)
|
||||||
|
}
|
@@ -41,7 +41,7 @@ var Verbose bool
|
|||||||
var LockedCommands = []string{"install", "uninstall", "upgrade"}
|
var LockedCommands = []string{"install", "uninstall", "upgrade"}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LuetCLIVersion = "0.17.0"
|
LuetCLIVersion = "0.17.2"
|
||||||
LuetEnvPrefix = "LUET"
|
LuetEnvPrefix = "LUET"
|
||||||
license = `
|
license = `
|
||||||
Luet Copyright (C) 2019-2021 Ettore Di Giacinto
|
Luet Copyright (C) 2019-2021 Ettore Di Giacinto
|
||||||
@@ -63,7 +63,7 @@ func version() string {
|
|||||||
return fmt.Sprintf("%s-g%s %s", LuetCLIVersion, BuildCommit, BuildTime)
|
return fmt.Sprintf("%s-g%s %s", LuetCLIVersion, BuildCommit, BuildTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
var noBannerCommands = []string{"search", "exec", "tree", "database", "box"}
|
var noBannerCommands = []string{"search", "exec", "tree", "database", "box", "cleanup"}
|
||||||
|
|
||||||
func displayVersionBanner() {
|
func displayVersionBanner() {
|
||||||
display := true
|
display := true
|
||||||
|
10
pkg/helpers/slice.go
Normal file
10
pkg/helpers/slice.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package helpers
|
||||||
|
|
||||||
|
func Contains(s []string, e string) bool {
|
||||||
|
for _, a := range s {
|
||||||
|
if a == e {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
@@ -27,6 +27,7 @@ import (
|
|||||||
"github.com/mudler/luet/pkg/bus"
|
"github.com/mudler/luet/pkg/bus"
|
||||||
artifact "github.com/mudler/luet/pkg/compiler/types/artifact"
|
artifact "github.com/mudler/luet/pkg/compiler/types/artifact"
|
||||||
"github.com/mudler/luet/pkg/config"
|
"github.com/mudler/luet/pkg/config"
|
||||||
|
"github.com/mudler/luet/pkg/helpers"
|
||||||
fileHelper "github.com/mudler/luet/pkg/helpers/file"
|
fileHelper "github.com/mudler/luet/pkg/helpers/file"
|
||||||
"github.com/mudler/luet/pkg/helpers/match"
|
"github.com/mudler/luet/pkg/helpers/match"
|
||||||
. "github.com/mudler/luet/pkg/logger"
|
. "github.com/mudler/luet/pkg/logger"
|
||||||
@@ -755,12 +756,63 @@ func (l *LuetInstaller) getFinalizers(allRepos pkg.PackageDatabase, solution sol
|
|||||||
return toFinalize, nil
|
return toFinalize, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *LuetInstaller) checkFileconflicts(toInstall map[string]ArtifactMatch, s *System) error {
|
||||||
|
Info("Checking for file conflicts..")
|
||||||
|
defer s.Clean() // Release memory
|
||||||
|
|
||||||
|
filesToInstall := []string{}
|
||||||
|
for _, m := range toInstall {
|
||||||
|
a, err := l.downloadPackage(m)
|
||||||
|
if err != nil && !l.Options.Force {
|
||||||
|
return errors.Wrap(err, "Failed downloading package")
|
||||||
|
}
|
||||||
|
files, err := a.FileList()
|
||||||
|
if err != nil && !l.Options.Force {
|
||||||
|
return errors.Wrapf(err, "Could not get filelist for %s", a.CompileSpec.Package.HumanReadableString())
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, f := range files {
|
||||||
|
if helpers.Contains(filesToInstall, f) {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"file conflict between packages to be installed",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
exists, p, err := s.ExistsPackageFile(f)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed checking into system db")
|
||||||
|
}
|
||||||
|
if exists {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"file conflict between '%s' and '%s' ( file: %s )",
|
||||||
|
p.HumanReadableString(),
|
||||||
|
m.Package.HumanReadableString(),
|
||||||
|
f,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filesToInstall = append(filesToInstall, files...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (l *LuetInstaller) install(o Option, syncedRepos Repositories, toInstall map[string]ArtifactMatch, p pkg.Packages, solution solver.PackagesAssertions, allRepos pkg.PackageDatabase, s *System) error {
|
func (l *LuetInstaller) install(o Option, syncedRepos Repositories, toInstall map[string]ArtifactMatch, p pkg.Packages, solution solver.PackagesAssertions, allRepos pkg.PackageDatabase, s *System) error {
|
||||||
// Install packages into rootfs in parallel.
|
|
||||||
|
// Download packages in parallel first
|
||||||
if err := l.download(syncedRepos, toInstall); err != nil {
|
if err := l.download(syncedRepos, toInstall); err != nil {
|
||||||
return errors.Wrap(err, "Downloading packages")
|
return errors.Wrap(err, "Downloading packages")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check file conflicts
|
||||||
|
if err := l.checkFileconflicts(toInstall, s); err != nil {
|
||||||
|
if !l.Options.Force {
|
||||||
|
return errors.Wrap(err, "file conflict found")
|
||||||
|
} else {
|
||||||
|
Warning("file conflict found", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if l.Options.DownloadOnly {
|
if l.Options.DownloadOnly {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package installer
|
package installer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
"github.com/mudler/luet/pkg/helpers"
|
"github.com/mudler/luet/pkg/helpers"
|
||||||
fileHelper "github.com/mudler/luet/pkg/helpers/file"
|
fileHelper "github.com/mudler/luet/pkg/helpers/file"
|
||||||
@@ -10,8 +12,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type System struct {
|
type System struct {
|
||||||
Database pkg.PackageDatabase
|
Database pkg.PackageDatabase
|
||||||
Target string
|
Target string
|
||||||
|
fileIndex map[string]pkg.Package
|
||||||
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *System) World() (pkg.Packages, error) {
|
func (s *System) World() (pkg.Packages, error) {
|
||||||
@@ -52,3 +56,38 @@ func (s *System) ExecuteFinalizers(packs []pkg.Package) error {
|
|||||||
}
|
}
|
||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *System) buildFileIndex() {
|
||||||
|
s.Lock()
|
||||||
|
defer s.Unlock()
|
||||||
|
// Check if cache is empty or if it got modified
|
||||||
|
if s.fileIndex == nil { //|| len(s.Database.GetPackages()) != len(s.fileIndex) {
|
||||||
|
s.fileIndex = make(map[string]pkg.Package)
|
||||||
|
for _, p := range s.Database.World() {
|
||||||
|
files, _ := s.Database.GetPackageFiles(p)
|
||||||
|
for _, f := range files {
|
||||||
|
s.fileIndex[f] = p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *System) Clean() {
|
||||||
|
s.Lock()
|
||||||
|
defer s.Unlock()
|
||||||
|
s.fileIndex = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *System) ExistsPackageFile(file string) (bool, pkg.Package, error) {
|
||||||
|
Debug("Checking if file ", file, "belongs to any package")
|
||||||
|
s.buildFileIndex()
|
||||||
|
s.Lock()
|
||||||
|
defer s.Unlock()
|
||||||
|
if p, exists := s.fileIndex[file]; exists {
|
||||||
|
Debug(file, "belongs already to", p.HumanReadableString())
|
||||||
|
|
||||||
|
return exists, p, nil
|
||||||
|
}
|
||||||
|
Debug(file, "doesn't belong to any package")
|
||||||
|
return false, nil, nil
|
||||||
|
}
|
||||||
|
70
pkg/installer/system_test.go
Normal file
70
pkg/installer/system_test.go
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
// Copyright © 2021 Ettore Di Giacinto <mudler@mocaccino.org>
|
||||||
|
//
|
||||||
|
// 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"
|
||||||
|
|
||||||
|
. "github.com/mudler/luet/pkg/installer"
|
||||||
|
pkg "github.com/mudler/luet/pkg/package"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("System", func() {
|
||||||
|
Context("Files", func() {
|
||||||
|
var s *System
|
||||||
|
var db pkg.PackageDatabase
|
||||||
|
var a, b *pkg.DefaultPackage
|
||||||
|
|
||||||
|
BeforeEach(func() {
|
||||||
|
db = pkg.NewInMemoryDatabase(false)
|
||||||
|
s = &System{Database: db}
|
||||||
|
|
||||||
|
a = &pkg.DefaultPackage{Name: "test", Version: "1", Category: "t"}
|
||||||
|
|
||||||
|
db.CreatePackage(a)
|
||||||
|
db.SetPackageFiles(&pkg.PackageFile{PackageFingerprint: a.GetFingerPrint(), Files: []string{"foo", "f"}})
|
||||||
|
|
||||||
|
b = &pkg.DefaultPackage{Name: "test2", Version: "1", Category: "t"}
|
||||||
|
|
||||||
|
db.CreatePackage(b)
|
||||||
|
db.SetPackageFiles(&pkg.PackageFile{PackageFingerprint: b.GetFingerPrint(), Files: []string{"barz", "f"}})
|
||||||
|
})
|
||||||
|
|
||||||
|
It("detects when are already shipped by other packages", func() {
|
||||||
|
r, p, err := s.ExistsPackageFile("foo")
|
||||||
|
Expect(r).To(BeTrue())
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(p).To(Equal(a))
|
||||||
|
r, p, err = s.ExistsPackageFile("baz")
|
||||||
|
Expect(r).To(BeFalse())
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(p).To(BeNil())
|
||||||
|
|
||||||
|
r, p, err = s.ExistsPackageFile("f")
|
||||||
|
Expect(r).To(BeTrue())
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(p).To(Equal(b))
|
||||||
|
r, p, err = s.ExistsPackageFile("barz")
|
||||||
|
Expect(r).To(BeTrue())
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(p).To(Equal(b))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
6
tests/fixtures/fileconflicts/conflict1/build.yaml
vendored
Normal file
6
tests/fixtures/fileconflicts/conflict1/build.yaml
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
image: "alpine"
|
||||||
|
prelude:
|
||||||
|
- mkdir /foo
|
||||||
|
steps:
|
||||||
|
- echo conflict > /foo/test1
|
||||||
|
package_dir: /foo
|
7
tests/fixtures/fileconflicts/conflict1/collection.yaml
vendored
Normal file
7
tests/fixtures/fileconflicts/conflict1/collection.yaml
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
packages:
|
||||||
|
- category: "test1"
|
||||||
|
name: "conflict"
|
||||||
|
version: "1.0"
|
||||||
|
- category: "test2"
|
||||||
|
name: "conflict"
|
||||||
|
version: "1.0"
|
84
tests/integration/32_fileconflicts.sh
Executable file
84
tests/integration/32_fileconflicts.sh
Executable file
@@ -0,0 +1,84 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export LUET_NOLOCK=true
|
||||||
|
|
||||||
|
oneTimeSetUp() {
|
||||||
|
export tmpdir="$(mktemp -d)"
|
||||||
|
}
|
||||||
|
|
||||||
|
oneTimeTearDown() {
|
||||||
|
rm -rf "$tmpdir"
|
||||||
|
}
|
||||||
|
|
||||||
|
testBuild() {
|
||||||
|
mkdir $tmpdir/testbuild
|
||||||
|
luet build --tree "$ROOT_DIR/tests/fixtures/fileconflicts" --destination $tmpdir/testbuild --compression gzip --all
|
||||||
|
buildst=$?
|
||||||
|
assertEquals 'builds successfully' "$buildst" "0"
|
||||||
|
assertTrue 'create packages' "[ -e '$tmpdir/testbuild/conflict-test1-1.0.package.tar.gz' ]"
|
||||||
|
assertTrue 'create packages' "[ -e '$tmpdir/testbuild/conflict-test2-1.0.package.tar.gz' ]"
|
||||||
|
}
|
||||||
|
|
||||||
|
testRepo() {
|
||||||
|
assertTrue 'no repository' "[ ! -e '$tmpdir/testbuild/repository.yaml' ]"
|
||||||
|
luet create-repo --tree "$ROOT_DIR/tests/fixtures/fileconflicts" \
|
||||||
|
--output $tmpdir/testbuild \
|
||||||
|
--packages $tmpdir/testbuild \
|
||||||
|
--name "test" \
|
||||||
|
--descr "Test Repo" \
|
||||||
|
--urls $tmpdir/testrootfs \
|
||||||
|
--type disk > /dev/null
|
||||||
|
|
||||||
|
createst=$?
|
||||||
|
assertEquals 'create repo successfully' "$createst" "0"
|
||||||
|
assertTrue 'create repository' "[ -e '$tmpdir/testbuild/repository.yaml' ]"
|
||||||
|
}
|
||||||
|
|
||||||
|
testConfig() {
|
||||||
|
mkdir $tmpdir/testrootfs
|
||||||
|
cat <<EOF > $tmpdir/luet.yaml
|
||||||
|
general:
|
||||||
|
debug: true
|
||||||
|
system:
|
||||||
|
rootfs: $tmpdir/testrootfs
|
||||||
|
database_path: "/"
|
||||||
|
database_engine: "boltdb"
|
||||||
|
config_from_host: true
|
||||||
|
repositories:
|
||||||
|
- name: "main"
|
||||||
|
type: "disk"
|
||||||
|
enable: true
|
||||||
|
urls:
|
||||||
|
- "$tmpdir/testbuild"
|
||||||
|
EOF
|
||||||
|
luet config --config $tmpdir/luet.yaml
|
||||||
|
res=$?
|
||||||
|
assertEquals 'config test successfully' "$res" "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
testInstall() {
|
||||||
|
luet install -y --config $tmpdir/luet.yaml test1/conflict test2/conflict
|
||||||
|
#luet install -y --config $tmpdir/luet.yaml test/c@1.0 > /dev/null
|
||||||
|
installst=$?
|
||||||
|
assertEquals 'install test failed' "$installst" "1"
|
||||||
|
#assertTrue 'package installed' "[ -e '$tmpdir/testrootfs/c' ]"
|
||||||
|
}
|
||||||
|
|
||||||
|
testReInstall() {
|
||||||
|
luet install -y --config $tmpdir/luet.yaml test1/conflict
|
||||||
|
#luet install -y --config $tmpdir/luet.yaml test/c@1.0 > /dev/null
|
||||||
|
installst=$?
|
||||||
|
assertEquals 'install test succeeded' "$installst" "0"
|
||||||
|
luet install -y --config $tmpdir/luet.yaml test2/conflict
|
||||||
|
#luet install -y --config $tmpdir/luet.yaml test/c@1.0 > /dev/null
|
||||||
|
installst=$?
|
||||||
|
assertEquals 'install test succeeded' "$installst" "1"
|
||||||
|
luet install -y --force --config $tmpdir/luet.yaml test2/conflict
|
||||||
|
#luet install -y --config $tmpdir/luet.yaml test/c@1.0 > /dev/null
|
||||||
|
installst=$?
|
||||||
|
assertEquals 'install test succeeded' "$installst" "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Load shUnit2.
|
||||||
|
. "$ROOT_DIR/tests/integration/shunit2"/shunit2
|
||||||
|
|
70
tests/integration/33_reinstall.sh
Executable file
70
tests/integration/33_reinstall.sh
Executable file
@@ -0,0 +1,70 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export LUET_NOLOCK=true
|
||||||
|
|
||||||
|
oneTimeSetUp() {
|
||||||
|
export tmpdir="$(mktemp -d)"
|
||||||
|
}
|
||||||
|
|
||||||
|
oneTimeTearDown() {
|
||||||
|
rm -rf "$tmpdir"
|
||||||
|
}
|
||||||
|
|
||||||
|
testBuild() {
|
||||||
|
mkdir $tmpdir/testbuild
|
||||||
|
luet build --tree "$ROOT_DIR/tests/fixtures/fileconflicts" --destination $tmpdir/testbuild --compression gzip --all
|
||||||
|
buildst=$?
|
||||||
|
assertEquals 'builds successfully' "$buildst" "0"
|
||||||
|
assertTrue 'create packages' "[ -e '$tmpdir/testbuild/conflict-test1-1.0.package.tar.gz' ]"
|
||||||
|
assertTrue 'create packages' "[ -e '$tmpdir/testbuild/conflict-test2-1.0.package.tar.gz' ]"
|
||||||
|
}
|
||||||
|
|
||||||
|
testRepo() {
|
||||||
|
assertTrue 'no repository' "[ ! -e '$tmpdir/testbuild/repository.yaml' ]"
|
||||||
|
luet create-repo --tree "$ROOT_DIR/tests/fixtures/fileconflicts" \
|
||||||
|
--output $tmpdir/testbuild \
|
||||||
|
--packages $tmpdir/testbuild \
|
||||||
|
--name "test" \
|
||||||
|
--descr "Test Repo" \
|
||||||
|
--urls $tmpdir/testrootfs \
|
||||||
|
--type disk > /dev/null
|
||||||
|
|
||||||
|
createst=$?
|
||||||
|
assertEquals 'create repo successfully' "$createst" "0"
|
||||||
|
assertTrue 'create repository' "[ -e '$tmpdir/testbuild/repository.yaml' ]"
|
||||||
|
}
|
||||||
|
|
||||||
|
testConfig() {
|
||||||
|
mkdir $tmpdir/testrootfs
|
||||||
|
cat <<EOF > $tmpdir/luet.yaml
|
||||||
|
general:
|
||||||
|
debug: true
|
||||||
|
system:
|
||||||
|
rootfs: $tmpdir/testrootfs
|
||||||
|
database_path: "/"
|
||||||
|
database_engine: "boltdb"
|
||||||
|
config_from_host: true
|
||||||
|
repositories:
|
||||||
|
- name: "main"
|
||||||
|
type: "disk"
|
||||||
|
enable: true
|
||||||
|
urls:
|
||||||
|
- "$tmpdir/testbuild"
|
||||||
|
EOF
|
||||||
|
luet config --config $tmpdir/luet.yaml
|
||||||
|
res=$?
|
||||||
|
assertEquals 'config test successfully' "$res" "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
testReInstall() {
|
||||||
|
luet install -y --config $tmpdir/luet.yaml test1/conflict
|
||||||
|
installst=$?
|
||||||
|
assertEquals 'install test succeeded' "$installst" "0"
|
||||||
|
luet reinstall -y --config $tmpdir/luet.yaml test1/conflict
|
||||||
|
installst=$?
|
||||||
|
assertEquals 'reinstall test succeeded' "$installst" "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Load shUnit2.
|
||||||
|
. "$ROOT_DIR/tests/integration/shunit2"/shunit2
|
||||||
|
|
Reference in New Issue
Block a user