Compare commits

...

9 Commits

Author SHA1 Message Date
Ettore Di Giacinto
0a4fe57f33 Tag 0.17.7 2021-08-09 16:18:51 +02:00
Ettore Di Giacinto
ccf83b0d5f Avoid deadlocking by FindPackages calls 2021-08-09 15:13:53 +02:00
Ettore Di Giacinto
57cefc7d6b Fixup data race when updating revdeps 2021-08-09 14:09:10 +02:00
Ettore Di Giacinto
97ff647f07 Turn tmpdir in abs path if required
Fixes #239
2021-08-09 13:17:16 +02:00
Ettore Di Giacinto
b7ac1e03d5 Add test for file conflicts on upgrade of the same package
This allows to be certain that we don't raise a conflict error while
upgrading the same package
2021-08-09 13:02:08 +02:00
Ettore Di Giacinto
ff092db97d Increase http timeout to 120s by default 2021-08-09 12:58:01 +02:00
Ettore Di Giacinto
2789f59f53 Add --values flag also to luet tree images 2021-08-09 12:57:36 +02:00
Ettore Di Giacinto
10ae872a3e Simplify revdep code
Isolate common code into a function and also fix a sublte bug hiding in
that code.

We need to stab a copy of the package inside our PackageMap to avoid
having symlinks pointing at the same values when iterating over
requires. ( e.g. happened in this case:
https://github.com/rancher-sandbox/cOS-toolkit/pull/467#issuecomment-895060115
)
2021-08-09 12:47:27 +02:00
Ettore Di Giacinto
65a55e242e Tag 0.17.6 2021-08-07 18:04:48 +02:00
11 changed files with 147 additions and 32 deletions

View File

@@ -75,7 +75,7 @@ Build packages specifying multiple definition trees:
viper.BindPFlag("compression", cmd.Flags().Lookup("compression"))
viper.BindPFlag("nodeps", cmd.Flags().Lookup("nodeps"))
viper.BindPFlag("onlydeps", cmd.Flags().Lookup("onlydeps"))
viper.BindPFlag("values", cmd.Flags().Lookup("values"))
util.BindValuesFlags(cmd)
viper.BindPFlag("backend-args", cmd.Flags().Lookup("backend-args"))
viper.BindPFlag("image-repository", cmd.Flags().Lookup("image-repository"))
@@ -101,7 +101,7 @@ Build packages specifying multiple definition trees:
all := viper.GetBool("all")
compressionType := viper.GetString("compression")
imageRepository := viper.GetString("image-repository")
values := viper.GetStringSlice("values")
values := util.ValuesFlags()
wait := viper.GetBool("wait")
push := viper.GetBool("push")
pull := viper.GetBool("pull")

View File

@@ -41,7 +41,7 @@ var Verbose bool
var LockedCommands = []string{"install", "uninstall", "upgrade"}
const (
LuetCLIVersion = "0.17.5"
LuetCLIVersion = "0.17.7"
LuetEnvPrefix = "LUET"
license = `
Luet Copyright (C) 2019-2021 Ettore Di Giacinto

View File

@@ -23,6 +23,7 @@ import (
//. "github.com/mudler/luet/pkg/config"
"github.com/ghodss/yaml"
helpers "github.com/mudler/luet/cmd/helpers"
"github.com/mudler/luet/cmd/util"
"github.com/mudler/luet/pkg/compiler"
"github.com/mudler/luet/pkg/compiler/backend"
"github.com/mudler/luet/pkg/compiler/types/options"
@@ -50,6 +51,7 @@ func NewTreeImageCommand() *cobra.Command {
if len(args) != 1 {
Fatal("Expects one package as parameter")
}
util.BindValuesFlags(cmd)
viper.BindPFlag("image-repository", cmd.Flags().Lookup("image-repository"))
},
@@ -59,6 +61,7 @@ func NewTreeImageCommand() *cobra.Command {
treePath, _ := cmd.Flags().GetStringArray("tree")
imageRepository := viper.GetString("image-repository")
pullRepo, _ := cmd.Flags().GetStringArray("pull-repository")
values := util.ValuesFlags()
out, _ := cmd.Flags().GetString("output")
if out != "terminal" {
@@ -80,6 +83,7 @@ func NewTreeImageCommand() *cobra.Command {
luetCompiler := compiler.NewLuetCompiler(
compilerBackend,
reciper.GetDatabase(),
options.WithBuildValues(values),
options.WithPushRepository(imageRepository),
options.WithPullRepositories(pullRepo),
options.WithSolverOptions(opts),

View File

@@ -17,6 +17,7 @@ package util
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/mudler/luet/pkg/config"
. "github.com/mudler/luet/pkg/config"
@@ -35,6 +36,14 @@ func BindSolverFlags(cmd *cobra.Command) {
LuetCfg.Viper.BindPFlag("solver.max_attempts", cmd.Flags().Lookup("solver-attempts"))
}
func BindValuesFlags(cmd *cobra.Command) {
viper.BindPFlag("values", cmd.Flags().Lookup("values"))
}
func ValuesFlags() []string {
return viper.GetStringSlice("values")
}
func SetSystemConfig() {
dbpath := LuetCfg.Viper.GetString("system.database_path")
rootfs := LuetCfg.Viper.GetString("system.rootfs")

View File

@@ -17,7 +17,6 @@
package config
import (
"errors"
"fmt"
"io/ioutil"
"os"
@@ -27,6 +26,8 @@ import (
"strings"
"time"
"github.com/pkg/errors"
fileHelper "github.com/mudler/luet/pkg/helpers/file"
pkg "github.com/mudler/luet/pkg/package"
@@ -417,6 +418,14 @@ system:
}
func (c *LuetSystemConfig) InitTmpDir() error {
if !filepath.IsAbs(c.TmpDirBase) {
abs, err := fileHelper.Rel2Abs(c.TmpDirBase)
if err != nil {
return errors.Wrap(err, "while converting relative path to absolute path")
}
c.TmpDirBase = abs
}
if _, err := os.Stat(c.TmpDirBase); err != nil {
if os.IsNotExist(err) {
err = os.MkdirAll(c.TmpDirBase, os.ModePerm)

View File

@@ -45,7 +45,7 @@ func NewHttpClient(r RepoData) *HttpClient {
}
func NewGrabClient() *grab.Client {
httpTimeout := 30
httpTimeout := 120
timeout := os.Getenv("HTTP_TIMEOUT")
if timeout != "" {
timeoutI, err := strconv.Atoi(timeout)

View File

@@ -143,6 +143,7 @@ func (db *InMemoryDatabase) getRevdeps(p Package, visited map[string]interface{}
if err != nil {
return res, err
}
for _, pp := range packs {
// db.Lock()
list := db.RevDepsDatabase[pp.GetFingerPrint()]
@@ -195,6 +196,14 @@ func (db *InMemoryDatabase) CreatePackage(p Package) (string, error) {
return ID, nil
}
func (db *InMemoryDatabase) updateRevDep(k, v string, b Package) {
_, ok := db.RevDepsDatabase[k]
if !ok {
db.RevDepsDatabase[k] = make(map[string]Package)
}
db.RevDepsDatabase[k][v] = b.Clone()
}
func (db *InMemoryDatabase) populateCaches(p Package) {
pd, _ := p.(*DefaultPackage)
@@ -226,20 +235,19 @@ func (db *InMemoryDatabase) populateCaches(p Package) {
}
db.CacheNoVersion[p.GetPackageName()][p.GetVersion()] = nil
db.Unlock()
// Updating Revdeps
// Given that when we populate the cache we don't have the full db at hand
// We cycle over reverse dependency of a package to update their entry if they are matching
// the version selector
db.Lock()
toUpdate, ok := db.RevDepsDatabase[pd.GetPackageName()]
if ok {
for _, pp := range toUpdate {
for _, re := range pp.GetRequires() {
if match, _ := pd.VersionMatchSelector(re.GetVersion(), nil); match {
_, ok = db.RevDepsDatabase[pd.GetFingerPrint()]
if !ok {
db.RevDepsDatabase[pd.GetFingerPrint()] = make(map[string]Package)
}
db.RevDepsDatabase[pd.GetFingerPrint()][pp.GetFingerPrint()] = pp
db.updateRevDep(pd.GetFingerPrint(), pp.GetFingerPrint(), pp)
}
}
}
@@ -249,30 +257,12 @@ func (db *InMemoryDatabase) populateCaches(p Package) {
for _, re := range pd.GetRequires() {
packages, _ := db.FindPackages(re)
db.Lock()
for _, pa := range packages {
_, ok := db.RevDepsDatabase[pa.GetFingerPrint()]
if !ok {
db.RevDepsDatabase[pa.GetFingerPrint()] = make(map[string]Package)
}
db.RevDepsDatabase[pa.GetFingerPrint()][pd.GetFingerPrint()] = pd
_, ok = db.RevDepsDatabase[pa.GetPackageName()]
if !ok {
db.RevDepsDatabase[pa.GetPackageName()] = make(map[string]Package)
}
db.RevDepsDatabase[pa.GetPackageName()][pd.GetPackageName()] = pd
db.updateRevDep(pa.GetFingerPrint(), pd.GetFingerPrint(), pd)
db.updateRevDep(pa.GetPackageName(), pd.GetPackageName(), pd)
}
_, ok := db.RevDepsDatabase[re.GetFingerPrint()]
if !ok {
db.RevDepsDatabase[re.GetFingerPrint()] = make(map[string]Package)
}
db.RevDepsDatabase[re.GetFingerPrint()][pd.GetFingerPrint()] = pd
_, ok = db.RevDepsDatabase[re.GetPackageName()]
if !ok {
db.RevDepsDatabase[re.GetPackageName()] = make(map[string]Package)
}
db.RevDepsDatabase[re.GetPackageName()][pd.GetPackageName()] = pd
db.updateRevDep(re.GetFingerPrint(), pd.GetFingerPrint(), pd)
db.updateRevDep(re.GetPackageName(), pd.GetPackageName(), pd)
db.Unlock()
}
}

View File

@@ -136,6 +136,18 @@ type Packages []Package
type DefaultPackages []*DefaultPackage
type PackageMap map[string]Package
func (pm PackageMap) String() string {
rr := []string{}
for _, r := range pm {
rr = append(rr, r.HumanReadableString())
}
return fmt.Sprint(rr)
}
func (d DefaultPackages) Hash(salt string) string {
overallFp := ""

View File

@@ -0,0 +1,6 @@
image: "alpine"
prelude:
- mkdir /foo
steps:
- echo conflict > /foo/test1
package_dir: /foo

View File

@@ -0,0 +1,7 @@
packages:
- category: "test1"
name: "noconflict"
version: "1.0"
- category: "test1"
name: "noconflict"
version: "1.1"

View File

@@ -0,0 +1,78 @@
#!/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/nofileconflicts_upgrade" --destination $tmpdir/testbuild --compression gzip --all
buildst=$?
assertEquals 'builds successfully' "$buildst" "0"
assertTrue 'create packages' "[ -e '$tmpdir/testbuild/noconflict-test1-1.0.package.tar.gz' ]"
assertTrue 'create packages' "[ -e '$tmpdir/testbuild/noconflict-test1-1.1.package.tar.gz' ]"
}
testRepo() {
assertTrue 'no repository' "[ ! -e '$tmpdir/testbuild/repository.yaml' ]"
luet create-repo --tree "$ROOT_DIR/tests/fixtures/nofileconflicts_upgrade" \
--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/noconflict@1.0
installst=$?
#assertTrue 'package installed' "[ -e '$tmpdir/testrootfs/c' ]"
}
testUpgrade() {
out=$(luet upgrade -y --config $tmpdir/luet.yaml)
installst=$?
assertEquals 'install test succeeded' "$installst" "0"
assertNotContains 'does find conflicts' "$out" "Error: file conflict found: file conflict between packages to be installed"
installed=$(luet --config $tmpdir/luet.yaml search --installed)
assertContains 'does upgrade' "$installed" "test1/noconflict-1.1"
}
# Load shUnit2.
. "$ROOT_DIR/tests/integration/shunit2"/shunit2