diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index e17dbeca..79fb662d 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -956,12 +956,12 @@ func (cs *LuetCompiler) FromPackage(p pkg.Package) (*compilerspec.LuetCompilatio opts := options.Compiler{} - artifactMetadataFile := filepath.Join(p.GetTreeDir(), p.GetMetadataFilePath()) - - if fi, err := os.Stat(artifactMetadataFile); err == nil { - f, err := os.Open(fi.Name()) + artifactMetadataFile := filepath.Join(p.GetTreeDir(), "..", p.GetMetadataFilePath()) + Debug("Checking if metadata file is present", artifactMetadataFile) + if _, err := os.Stat(artifactMetadataFile); err == nil { + f, err := os.Open(artifactMetadataFile) if err != nil { - return nil, errors.Wrapf(err, "could not open %s", fi.Name()) + return nil, errors.Wrapf(err, "could not open %s", artifactMetadataFile) } dat, err := ioutil.ReadAll(f) if err != nil { @@ -972,11 +972,14 @@ func (cs *LuetCompiler) FromPackage(p pkg.Package) (*compilerspec.LuetCompilatio return nil, errors.Wrap(err, "could not decode package from yaml") } + Debug("Read build options:", art.CompileSpec.BuildOptions) opts = art.CompileSpec.BuildOptions opts.PushImageRepository = "" } else if !os.IsNotExist(err) { Debug("error reading already existing artifact metadata file: ", err.Error()) + } else if os.IsNotExist(err) { + Debug("metadata file not present, skipping", artifactMetadataFile) } bytes, err := cs.templatePackage(opts.BuildValues, pack) diff --git a/pkg/installer/repository_local.go b/pkg/installer/repository_local.go index d834bbc2..8390bc01 100644 --- a/pkg/installer/repository_local.go +++ b/pkg/installer/repository_local.go @@ -42,6 +42,10 @@ func buildPackageIndex(path string, db pkg.PackageDatabase) ([]*artifact.Package var art []*artifact.PackageArtifact var ff = func(currentpath string, info os.FileInfo, err error) error { + if err != nil { + Debug("Failed walking", err.Error()) + return err + } if !strings.HasSuffix(info.Name(), ".metadata.yaml") { return nil // Skip with no errors diff --git a/pkg/package/package.go b/pkg/package/package.go index 53cfa7ec..8e6bc6dd 100644 --- a/pkg/package/package.go +++ b/pkg/package/package.go @@ -117,6 +117,8 @@ type Package interface { GetMetadataFilePath() string SetTreeDir(s string) GetTreeDir() string + + JSON() ([]byte, error) } type Tree interface { @@ -245,7 +247,7 @@ type DefaultPackage struct { Labels map[string]string `json:"labels,omitempty"` // Affects YAML field names too. - treeDir string + TreeDir string `json:"treedir,omitempty"` } // State represent the package state @@ -263,10 +265,10 @@ func NewPackage(name, version string, requires []*DefaultPackage, conflicts []*D } func (p *DefaultPackage) SetTreeDir(s string) { - p.treeDir = s + p.TreeDir = s } func (p *DefaultPackage) GetTreeDir() string { - return p.treeDir + return p.TreeDir } func (p *DefaultPackage) String() string { b, err := p.JSON() diff --git a/tests/integration/27_buildwithnotree_values.sh b/tests/integration/27_buildwithnotree_values.sh index a1c1328b..95ce406e 100755 --- a/tests/integration/27_buildwithnotree_values.sh +++ b/tests/integration/27_buildwithnotree_values.sh @@ -181,6 +181,121 @@ EOF } +testBuildWithNoTree3() { + cat < $tmpdir/default.yaml +bb: "newinterpolation" +foo: "sq" +EOF + mkdir $tmpdir/testbuild3 + mkdir $tmpdir/emptytree + luet build --from-repositories --values $tmpdir/default.yaml --tree $tmpdir/emptytree --config $tmpdir/luet.yaml test/c --destination $tmpdir/testbuild3 --compression gzip --all + buildst=$? + assertEquals 'builds successfully' "$buildst" "0" + assertTrue 'create package B' "[ -e '$tmpdir/testbuild3/b-distro-0.3.package.tar.gz' ]" + assertTrue 'create package A' "[ -e '$tmpdir/testbuild3/a-distro-0.1.package.tar.gz' ]" + assertTrue 'create package C' "[ -e '$tmpdir/testbuild3/c-distro-0.3.package.tar.gz' ]" + assertTrue 'create package foo' "[ -e '$tmpdir/testbuild3/foo-test-1.1.package.tar.gz' ]" +} + +testRepo3() { + assertTrue 'no repository' "[ ! -e '$tmpdir/testbuild3/repository.yaml' ]" + luet create-repo --config $tmpdir/luet.yaml --from-repositories --tree $tmpdir/emptytree \ + --output $tmpdir/testbuild3 \ + --packages $tmpdir/testbuild3 \ + --name "test" \ + --descr "Test Repo" \ + --urls $tmpdir/testrootfs \ + --type disk + + createst=$? + assertEquals 'create repo successfully' "$createst" "0" + assertTrue 'create repository' "[ -e '$tmpdir/testbuild3/repository.yaml' ]" +} + +testInstall3() { + mkdir $tmpdir/testrootfs3 + + cat < $tmpdir/luet2.yaml +general: + debug: true +system: + rootfs: $tmpdir/testrootfs3 + database_path: "/" + database_engine: "boltdb" +config_from_host: true +repositories: + - name: "main" + type: "disk" + enable: true + urls: + - "$tmpdir/testbuild3" +EOF + luet install -y --config $tmpdir/luet2.yaml distro/a + installst=$? + assertEquals 'install test successfully' "$installst" "0" + + assertTrue 'package installed A' "[ -e '$tmpdir/testrootfs3/a' ]" + # Build time can interpolate on fields which aren't package properties. + assertTrue 'extra field on A' "[ -e '$tmpdir/testrootfs3/build-extra-sq' ]" + assertTrue 'package installed A interpolated with values' "[ -e '$tmpdir/testrootfs3/a-newinterpolation' ]" + # Finalizers can interpolate only on package field. No extra fields are allowed at this time. + assertTrue 'finalizer executed on A' "[ -e '$tmpdir/testrootfs3/finalize-a' ]" + + installed=$(luet --config $tmpdir/luet2.yaml search --installed .) + searchst=$? + assertEquals 'search exists successfully' "$searchst" "0" + + assertContains 'contains distro/a-0.1' "$installed" 'distro/a-0.1' + + luet uninstall -y --config $tmpdir/luet2.yaml distro/a + installst=$? + assertEquals 'install test successfully' "$installst" "0" + + # We do the same check for the others + luet install -y --config $tmpdir/luet2.yaml distro/b + installst=$? + assertEquals 'install test successfully' "$installst" "0" + + assertTrue 'package installed B' "[ -e '$tmpdir/testrootfs3/b' ]" + assertTrue 'package installed B interpolated with values' "[ -e '$tmpdir/testrootfs3/b-newinterpolation' ]" + assertTrue 'extra field on B' "[ -e '$tmpdir/testrootfs3/build-extra-sq' ]" + assertTrue 'finalizer executed on B' "[ -e '$tmpdir/testrootfs3/finalize-b' ]" + installed=$(luet --config $tmpdir/luet2.yaml search --installed .) + searchst=$? + assertEquals 'search exists successfully' "$searchst" "0" + + assertContains 'contains distro/b-0.3' "$installed" 'distro/b-0.3' + + luet uninstall -y --config $tmpdir/luet2.yaml distro/b + installst=$? + assertEquals 'install test successfully' "$installst" "0" + + luet install -y --config $tmpdir/luet2.yaml distro/c + installst=$? + assertEquals 'install test successfully' "$installst" "0" + + assertTrue 'package installed C' "[ -e '$tmpdir/testrootfs3/c' ]" + assertTrue 'extra field on C' "[ -e '$tmpdir/testrootfs3/build-extra-sq' ]" + assertTrue 'package installed C interpolated with values' "[ -e '$tmpdir/testrootfs3/c-newinterpolation' ]" + assertTrue 'finalizer executed on C' "[ -e '$tmpdir/testrootfs3/finalize-c' ]" + + installed=$(luet --config $tmpdir/luet2.yaml search --installed .) + searchst=$? + assertEquals 'search exists successfully' "$searchst" "0" + + assertContains 'contains distro/c-0.3' "$installed" 'distro/c-0.3' + + luet uninstall -y --config $tmpdir/luet2.yaml distro/c + installst=$? + assertEquals 'install test successfully' "$installst" "0" + + luet install -y --config $tmpdir/luet2.yaml test/foo + installst=$? + assertEquals 'install test successfully' "$installst" "0" + + assertTrue 'package installed foo' "[ -e '$tmpdir/testrootfs3/foo' ]" + assertTrue 'package installed foo interpolated with values' "[ -e '$tmpdir/testrootfs3/foo-newinterpolation' ]" +} # Load shUnit2. . "$ROOT_DIR/tests/integration/shunit2"/shunit2