diff --git a/cmd/create-repo.go b/cmd/create-repo.go index efb2d894..ce9abfe2 100644 --- a/cmd/create-repo.go +++ b/cmd/create-repo.go @@ -18,8 +18,8 @@ import ( "os" "github.com/mudler/luet/pkg/compiler" + . "github.com/mudler/luet/pkg/config" installer "github.com/mudler/luet/pkg/installer" - . "github.com/mudler/luet/pkg/logger" pkg "github.com/mudler/luet/pkg/package" @@ -42,8 +42,11 @@ var createrepoCmd = &cobra.Command{ viper.BindPFlag("tree-compression", cmd.Flags().Lookup("tree-compression")) viper.BindPFlag("tree-path", cmd.Flags().Lookup("tree-path")) viper.BindPFlag("reset-revision", cmd.Flags().Lookup("reset-revision")) + viper.BindPFlag("repo", cmd.Flags().Lookup("repo")) }, Run: func(cmd *cobra.Command, args []string) { + var err error + var repo installer.Repository tree := viper.GetString("tree") dst := viper.GetString("output") @@ -55,11 +58,40 @@ var createrepoCmd = &cobra.Command{ reset := viper.GetBool("reset-revision") treetype := viper.GetString("tree-compression") treepath := viper.GetString("tree-path") + source_repo := viper.GetString("repo") + + if source_repo != "" { + // Search for system repository + lrepo, err := LuetCfg.GetSystemRepository(source_repo) + if err != nil { + Fatal("Error: " + err.Error()) + } + + if tree == "" { + tree = lrepo.TreePath + } + + if t == "" { + t = lrepo.Type + } + + repo, err = installer.GenerateRepository(lrepo.Name, + lrepo.Description, t, + lrepo.Urls, + lrepo.Priority, + packages, + tree, + pkg.NewInMemoryDatabase(false)) + + } else { + repo, err = installer.GenerateRepository(name, descr, t, urls, 1, packages, + tree, pkg.NewInMemoryDatabase(false)) + } - repo, err := installer.GenerateRepository(name, descr, t, urls, 1, packages, tree, pkg.NewInMemoryDatabase(false)) if err != nil { Fatal("Error: " + err.Error()) } + if treetype != "" { repo.SetTreeCompressionType(compiler.CompressionImplementation(treetype)) } @@ -88,6 +120,7 @@ func init() { createrepoCmd.Flags().StringSlice("urls", []string{}, "Repository URLs") createrepoCmd.Flags().String("type", "disk", "Repository type (disk)") createrepoCmd.Flags().Bool("reset-revision", false, "Reset repository revision.") + createrepoCmd.Flags().String("repo", "", "Use repository defined in configuration.") createrepoCmd.Flags().String("tree-compression", "none", "Compression alg: none, gzip") createrepoCmd.Flags().String("tree-path", installer.TREE_TARBALL, "Repository tree filename") diff --git a/tests/integration/02_create_repo_from_config.sh b/tests/integration/02_create_repo_from_config.sh new file mode 100755 index 00000000..55cd55d6 --- /dev/null +++ b/tests/integration/02_create_repo_from_config.sh @@ -0,0 +1,97 @@ +#!/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/buildableseed" --destination $tmpdir/testbuild --compression gzip test/c-1.0 > /dev/null + buildst=$? + assertEquals 'builds successfully' "$buildst" "0" + assertTrue 'create package dep B' "[ -e '$tmpdir/testbuild/b-test-1.0.package.tar.gz' ]" + assertTrue 'create package' "[ -e '$tmpdir/testbuild/c-test-1.0.package.tar.gz' ]" +} + +testConfig() { + mkdir $tmpdir/testrootfs + cat < $tmpdir/luet.yaml +general: + debug: true +system: + rootfs: $tmpdir/testrootfs + database_path: "/" + database_engine: "boltdb" +repositories: + - name: "main" + type: "disk" + enable: true + urls: + - "$tmpdir/testbuild" +EOF + luet config --config $tmpdir/luet.yaml + res=$? + assertEquals 'config test successfully' "$res" "0" +} + +testRepo() { + assertTrue 'no repository' "[ ! -e '$tmpdir/testbuild/repository.yaml' ]" + luet create-repo --tree "$ROOT_DIR/tests/fixtures/buildableseed" \ + --config $tmpdir/luet.yaml \ + --output $tmpdir/testbuild \ + --packages $tmpdir/testbuild \ + --repo "main" \ + + createst=$? + assertEquals 'create repo successfully' "$createst" "0" + assertTrue 'create repository' "[ -e '$tmpdir/testbuild/repository.yaml' ]" +} + +testInstall() { + luet install --config $tmpdir/luet.yaml test/c-1.0 + #luet install --config $tmpdir/luet.yaml test/c-1.0 > /dev/null + installst=$? + assertEquals 'install test successfully' "$installst" "0" + assertTrue 'package installed' "[ -e '$tmpdir/testrootfs/c' ]" +} + +testReInstall() { + output=$(luet install --config $tmpdir/luet.yaml test/c-1.0) + installst=$? + assertEquals 'install test successfully' "$installst" "0" + assertContains 'contains warning' "$output" 'Filtering out' +} + +testUnInstall() { + luet uninstall --config $tmpdir/luet.yaml test/c-1.0 + installst=$? + assertEquals 'uninstall test successfully' "$installst" "0" + assertTrue 'package uninstalled' "[ ! -e '$tmpdir/testrootfs/c' ]" +} + +testInstallAgain() { + assertTrue 'package uninstalled' "[ ! -e '$tmpdir/testrootfs/c' ]" + output=$(luet install --config $tmpdir/luet.yaml test/c-1.0) + installst=$? + assertEquals 'install test successfully' "$installst" "0" + assertNotContains 'contains warning' "$output" 'Filtering out' + assertTrue 'package installed' "[ -e '$tmpdir/testrootfs/c' ]" + assertTrue 'package in cache' "[ -e '$tmpdir/testrootfs/packages/c-test-1.0.package.tar.gz' ]" +} + +testCleanup() { + luet cleanup --config $tmpdir/luet.yaml + installst=$? + assertEquals 'install test successfully' "$installst" "0" + assertTrue 'package installed' "[ ! -e '$tmpdir/testrootfs/packages/c-test-1.0.package.tar.gz' ]" +} + +# Load shUnit2. +. "$ROOT_DIR/tests/integration/shunit2"/shunit2 + diff --git a/tests/integration/run.sh b/tests/integration/run.sh index ab19f786..83aa532f 100755 --- a/tests/integration/run.sh +++ b/tests/integration/run.sh @@ -13,4 +13,5 @@ export PATH=$ROOT_DIR/tests/integration/bin/:$PATH "$ROOT_DIR/tests/integration/01_simple.sh" "$ROOT_DIR/tests/integration/01_simple_gzip.sh" +"$ROOT_DIR/tests/integration/02_create_repo_from_config.sh"