From 07e6aedaad97e5b44c6941edc8b16f5c6b4612aa Mon Sep 17 00:00:00 2001 From: Japsty Date: Tue, 15 Oct 2024 16:40:00 +0300 Subject: [PATCH] pack: added .packignore In some cases, there are files that may be useful, but should not be part of artifact. The ability to add files and directories to the .packignore file has been added, which allows you to ignore these files and directories when packing. Closes: [812](https://github.com/tarantool/tt/issues/812) --- cli/pack/common.go | 23 ++++ cli/pack/common_test.go | 20 ++++ cli/pack/ignore.go | 97 ++++++++++++++++ .../bundle_with_packignore/.packignore | 4 + .../testdata/bundle_with_packignore/app.lua | 0 cli/pack/testdata/bundle_with_packignore/app2 | 1 + .../bundle_with_packignore/instances_enabled | 1 + .../testdata/bundle_with_packignore/modules | 1 + .../testdata/bundle_with_packignore/tt.yaml | 11 ++ cli/rocks/third_party/luarocks | 2 +- .../bundle_with_app_packignore/app.lua | 0 .../app2/app2-scm-1.rockspec | 14 +++ .../bundle_with_app_packignore/app2/init.lua | 0 .../app2/instances.yaml | 3 + .../app2/var/lib/inst1/test.snap | 0 .../app2/var/lib/inst1/test.vylog | 0 .../app2/var/lib/inst1/test.xlog | 0 .../app2/var/lib/inst2/test.snap | 0 .../app2/var/lib/inst2/test.xlog | 0 .../app2/var/log/inst1/test.log | 0 .../app2/var/log/inst2/test.log | 0 .../app2/var/run/inst1/app.pid | 0 .../app2/var/run/inst2/app2.pid | 0 .../instances_enabled/app1.lua | 1 + .../instances_enabled/app2/.packignore | 0 .../app2/app2-scm-1.rockspec | 14 +++ .../instances_enabled/app2/init.lua | 0 .../instances_enabled/app2/instances.yaml | 3 + .../app2/var/lib/inst1/test.snap | 0 .../app2/var/lib/inst1/test.vylog | 0 .../app2/var/lib/inst1/test.xlog | 0 .../app2/var/lib/inst2/test.snap | 0 .../app2/var/lib/inst2/test.xlog | 0 .../app2/var/log/inst1/test.log | 0 .../app2/var/log/inst2/test.log | 0 .../app2/var/run/inst1/app.pid | 0 .../app2/var/run/inst2/app2.pid | 0 .../modules/test_module.txt | 0 .../bundle_with_app_packignore/tt.yaml | 11 ++ .../bundle_with_packignore/.packignore | 2 + .../bundle_with_packignore/app.lua | 0 .../app2/app2-scm-1.rockspec | 14 +++ .../bundle_with_packignore/app2/init.lua | 0 .../app2/instances.yaml | 3 + .../app2/var/lib/inst1/test.snap | 0 .../app2/var/lib/inst1/test.vylog | 0 .../app2/var/lib/inst1/test.xlog | 0 .../app2/var/lib/inst2/test.snap | 0 .../app2/var/lib/inst2/test.xlog | 0 .../app2/var/log/inst1/test.log | 0 .../app2/var/log/inst2/test.log | 0 .../app2/var/run/inst1/app.pid | 0 .../app2/var/run/inst2/app2.pid | 0 .../instances_enabled/app1.lua | 1 + .../app2/app2-scm-1.rockspec | 14 +++ .../instances_enabled/app2/init.lua | 0 .../instances_enabled/app2/instances.yaml | 3 + .../app2/var/lib/inst1/test.snap | 0 .../app2/var/lib/inst1/test.vylog | 0 .../app2/var/lib/inst1/test.xlog | 0 .../app2/var/lib/inst2/test.snap | 0 .../app2/var/lib/inst2/test.xlog | 0 .../app2/var/log/inst1/test.log | 0 .../app2/var/log/inst2/test.log | 0 .../app2/var/run/inst1/app.pid | 0 .../app2/var/run/inst2/app2.pid | 0 .../modules/test_module.txt | 0 .../bundle_with_packignore/tt.yaml | 11 ++ test/integration/pack/test_pack.py | 106 ++++++++++++++++++ 69 files changed, 359 insertions(+), 1 deletion(-) create mode 100644 cli/pack/ignore.go create mode 100644 cli/pack/testdata/bundle_with_packignore/.packignore create mode 100644 cli/pack/testdata/bundle_with_packignore/app.lua create mode 120000 cli/pack/testdata/bundle_with_packignore/app2 create mode 120000 cli/pack/testdata/bundle_with_packignore/instances_enabled create mode 120000 cli/pack/testdata/bundle_with_packignore/modules create mode 100644 cli/pack/testdata/bundle_with_packignore/tt.yaml create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/app.lua create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/app2/app2-scm-1.rockspec create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/app2/init.lua create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/app2/instances.yaml create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/lib/inst1/test.snap create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/lib/inst1/test.vylog create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/lib/inst1/test.xlog create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/lib/inst2/test.snap create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/lib/inst2/test.xlog create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/log/inst1/test.log create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/log/inst2/test.log create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/run/inst1/app.pid create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/run/inst2/app2.pid create mode 120000 test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app1.lua create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/.packignore create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/app2-scm-1.rockspec create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/init.lua create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/instances.yaml create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/lib/inst1/test.snap create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/lib/inst1/test.vylog create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/lib/inst1/test.xlog create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/lib/inst2/test.snap create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/lib/inst2/test.xlog create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/log/inst1/test.log create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/log/inst2/test.log create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/run/inst1/app.pid create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/run/inst2/app2.pid create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/modules/test_module.txt create mode 100644 test/integration/pack/test_bundles/bundle_with_app_packignore/tt.yaml create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/.packignore create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/app.lua create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/app2/app2-scm-1.rockspec create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/app2/init.lua create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/app2/instances.yaml create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/app2/var/lib/inst1/test.snap create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/app2/var/lib/inst1/test.vylog create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/app2/var/lib/inst1/test.xlog create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/app2/var/lib/inst2/test.snap create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/app2/var/lib/inst2/test.xlog create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/app2/var/log/inst1/test.log create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/app2/var/log/inst2/test.log create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/app2/var/run/inst1/app.pid create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/app2/var/run/inst2/app2.pid create mode 120000 test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app1.lua create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/app2-scm-1.rockspec create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/init.lua create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/instances.yaml create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/lib/inst1/test.snap create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/lib/inst1/test.vylog create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/lib/inst1/test.xlog create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/lib/inst2/test.snap create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/lib/inst2/test.xlog create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/log/inst1/test.log create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/log/inst2/test.log create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/run/inst1/app.pid create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/run/inst2/app2.pid create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/modules/test_module.txt create mode 100644 test/integration/pack/test_bundles/bundle_with_packignore/tt.yaml diff --git a/cli/pack/common.go b/cli/pack/common.go index 3f352da37..de0c6eac2 100644 --- a/cli/pack/common.go +++ b/cli/pack/common.go @@ -33,6 +33,8 @@ const ( versionLuaFileName = "VERSION.lua" rocksManifestPath = ".rocks/share/tarantool/rocks/manifest" + + ignoreFile = ".packignore" ) var ( @@ -285,6 +287,17 @@ func copyApplications(bundleEnvPath string, packCtx *PackCtx, } inst := instances[0] appPath := inst.AppDir + if !inst.IsFileApp { + ignorePatterns, err := readPackIgnore(appPath) + if err != nil { + return fmt.Errorf("failed to read %s: %s", ignoreFile, err) + } + + if err = removeIgnoredFiles(appPath, ignorePatterns); err != nil { + return fmt.Errorf("failed to remove ignored files: %s", err) + } + } + if inst.IsFileApp { appPath = inst.InstanceScript resolvedAppPath, err := filepath.EvalSymlinks(appPath) @@ -383,6 +396,16 @@ func prepareBundle(cmdCtx *cmdcontext.CmdCtx, packCtx *PackCtx, } } + projectPath := cmdCtx.Cli.ConfigDir + ignorePatterns, err := readPackIgnore(projectPath) + if err != nil { + return "", fmt.Errorf("failed to read .packignore: %s", err) + } + + if err = removeIgnoredFiles(bundleEnvPath, ignorePatterns); err != nil { + return "", fmt.Errorf("failed to remove ignored files: %s", err) + } + if buildRocks { err = buildAppRocks(cmdCtx, packCtx, cliOpts, bundleEnvPath) if err != nil && !os.IsNotExist(err) { diff --git a/cli/pack/common_test.go b/cli/pack/common_test.go index e7fc81b68..e383f2696 100644 --- a/cli/pack/common_test.go +++ b/cli/pack/common_test.go @@ -1068,6 +1068,26 @@ func Test_prepareBundle(t *testing.T) { {assert.FileExists, "app/tt.yaml"}, }, }, + { + name: "Packing env with packignore", + params: params{ + configPath: "testdata/bundle_with_packignore/tt.yaml", + tntExecutable: tntExecutable, + packCtx: PackCtx{Name: "app"}, + }, + wantErr: false, + checks: []check{ + {assert.DirExists, "instances.enabled"}, + {assert.NoFileExists, "instances.enabled/app"}, + + {assert.NoDirExists, "modules"}, + + {assert.DirExists, "app2"}, + {assert.NoDirExists, "app2/var"}, + + {assert.NoFileExists, "app.lua"}, + }, + }, } for _, tt := range tests { diff --git a/cli/pack/ignore.go b/cli/pack/ignore.go new file mode 100644 index 000000000..fa60171d5 --- /dev/null +++ b/cli/pack/ignore.go @@ -0,0 +1,97 @@ +package pack + +import ( + "bufio" + "fmt" + "os" + "path/filepath" + "strings" +) + +// readPackIgnore reads the .packignore file and returns a slice of ignore patterns. +func readPackIgnore(projectPath string) (map[string]struct{}, error) { + ignoreFilePath := filepath.Join(projectPath, ".packignore") + file, err := os.Open(ignoreFilePath) + if err != nil { + if os.IsNotExist(err) { + return map[string]struct{}{}, nil + } + return nil, err + } + defer file.Close() + + patterns := make(map[string]struct{}) + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := scanner.Text() + line = strings.TrimSpace(line) + if line == "" || strings.HasPrefix(line, "#") { + continue + } + patterns[line] = struct{}{} + } + + if err := scanner.Err(); err != nil { + return nil, err + } + return patterns, nil +} + +// shouldIgnore checks if the given file path matches any of the ignore patterns. +func shouldIgnore(path string, patterns map[string]struct{}) (bool, error) { + for pattern := range patterns { + pattern = filepath.ToSlash(pattern) + filePath := filepath.ToSlash(path) + + if strings.HasPrefix(filePath, pattern) { + return true, nil + } + + match, err := filepath.Match(pattern, filePath) + if err != nil { + return false, err + } + if match { + return true, nil + } + } + return false, nil +} + +// removeIgnoredFiles walks through the directory and removes files or directories +// that match the ignore patterns. +func removeIgnoredFiles(bundleEnvPath string, patterns map[string]struct{}) error { + return filepath.Walk(bundleEnvPath, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + relPath, err := filepath.Rel(bundleEnvPath, path) + if err != nil { + return err + } + + relPathUnix := filepath.ToSlash(relPath) + + ignore, err := shouldIgnore(relPathUnix, patterns) + if err != nil { + return err + } + + if ignore { + if info.IsDir() { + err = os.RemoveAll(path) + if err != nil { + return fmt.Errorf("failed to remove directory %q: %s", path, err) + } + return filepath.SkipDir + } else { + err = os.Remove(path) + if err != nil { + return fmt.Errorf("failed to remove file %q: %s", path, err) + } + } + } + return nil + }) +} diff --git a/cli/pack/testdata/bundle_with_packignore/.packignore b/cli/pack/testdata/bundle_with_packignore/.packignore new file mode 100644 index 000000000..e198e0c08 --- /dev/null +++ b/cli/pack/testdata/bundle_with_packignore/.packignore @@ -0,0 +1,4 @@ +instances.enabled/app +modules +app2/var +app.lua \ No newline at end of file diff --git a/cli/pack/testdata/bundle_with_packignore/app.lua b/cli/pack/testdata/bundle_with_packignore/app.lua new file mode 100644 index 000000000..e69de29bb diff --git a/cli/pack/testdata/bundle_with_packignore/app2 b/cli/pack/testdata/bundle_with_packignore/app2 new file mode 120000 index 000000000..deebc8de1 --- /dev/null +++ b/cli/pack/testdata/bundle_with_packignore/app2 @@ -0,0 +1 @@ +../../../../test/integration/pack/test_bundles/bundle1/app2 \ No newline at end of file diff --git a/cli/pack/testdata/bundle_with_packignore/instances_enabled b/cli/pack/testdata/bundle_with_packignore/instances_enabled new file mode 120000 index 000000000..c02d4c2d9 --- /dev/null +++ b/cli/pack/testdata/bundle_with_packignore/instances_enabled @@ -0,0 +1 @@ +../../../../test/integration/pack/test_bundles/bundle1/instances_enabled \ No newline at end of file diff --git a/cli/pack/testdata/bundle_with_packignore/modules b/cli/pack/testdata/bundle_with_packignore/modules new file mode 120000 index 000000000..e7b46c2b3 --- /dev/null +++ b/cli/pack/testdata/bundle_with_packignore/modules @@ -0,0 +1 @@ +../../../../test/integration/pack/test_bundles/bundle1/modules \ No newline at end of file diff --git a/cli/pack/testdata/bundle_with_packignore/tt.yaml b/cli/pack/testdata/bundle_with_packignore/tt.yaml new file mode 100644 index 000000000..fae23cd96 --- /dev/null +++ b/cli/pack/testdata/bundle_with_packignore/tt.yaml @@ -0,0 +1,11 @@ +env: + bin_dir: bin + inc_dir: include + instances_enabled: . + tarantoolctl_layout: false +app: + run_dir: var/run + log_dir: var/log + wal_dir: var/lib + memtx_dir: var/lib + vinyl_dir: var/lib diff --git a/cli/rocks/third_party/luarocks b/cli/rocks/third_party/luarocks index f13f4ad36..a788845d8 160000 --- a/cli/rocks/third_party/luarocks +++ b/cli/rocks/third_party/luarocks @@ -1 +1 @@ -Subproject commit f13f4ad36cc565f5f918c68c11c035bb2f0b6e6e +Subproject commit a788845d842d14f4df2e5b2d3c0006eee4c4c9e4 diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/app.lua b/test/integration/pack/test_bundles/bundle_with_app_packignore/app.lua new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/app2-scm-1.rockspec b/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/app2-scm-1.rockspec new file mode 100644 index 000000000..6df4a5d6e --- /dev/null +++ b/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/app2-scm-1.rockspec @@ -0,0 +1,14 @@ +package = 'app2' +version = 'scm-1' +source = { + url = '/dev/null', +} +-- Put any modules your app depends on here +dependencies = { + 'tarantool', + 'lua >= 5.1', +} +build = { + type = 'none'; +} + diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/init.lua b/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/init.lua new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/instances.yaml b/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/instances.yaml new file mode 100644 index 000000000..e80ded4fa --- /dev/null +++ b/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/instances.yaml @@ -0,0 +1,3 @@ +inst1: + +inst2: diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/lib/inst1/test.snap b/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/lib/inst1/test.snap new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/lib/inst1/test.vylog b/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/lib/inst1/test.vylog new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/lib/inst1/test.xlog b/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/lib/inst1/test.xlog new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/lib/inst2/test.snap b/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/lib/inst2/test.snap new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/lib/inst2/test.xlog b/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/lib/inst2/test.xlog new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/log/inst1/test.log b/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/log/inst1/test.log new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/log/inst2/test.log b/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/log/inst2/test.log new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/run/inst1/app.pid b/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/run/inst1/app.pid new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/run/inst2/app2.pid b/test/integration/pack/test_bundles/bundle_with_app_packignore/app2/var/run/inst2/app2.pid new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app1.lua b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app1.lua new file mode 120000 index 000000000..6dee7136a --- /dev/null +++ b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app1.lua @@ -0,0 +1 @@ +../app.lua \ No newline at end of file diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/.packignore b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/.packignore new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/app2-scm-1.rockspec b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/app2-scm-1.rockspec new file mode 100644 index 000000000..6df4a5d6e --- /dev/null +++ b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/app2-scm-1.rockspec @@ -0,0 +1,14 @@ +package = 'app2' +version = 'scm-1' +source = { + url = '/dev/null', +} +-- Put any modules your app depends on here +dependencies = { + 'tarantool', + 'lua >= 5.1', +} +build = { + type = 'none'; +} + diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/init.lua b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/init.lua new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/instances.yaml b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/instances.yaml new file mode 100644 index 000000000..e80ded4fa --- /dev/null +++ b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/instances.yaml @@ -0,0 +1,3 @@ +inst1: + +inst2: diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/lib/inst1/test.snap b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/lib/inst1/test.snap new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/lib/inst1/test.vylog b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/lib/inst1/test.vylog new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/lib/inst1/test.xlog b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/lib/inst1/test.xlog new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/lib/inst2/test.snap b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/lib/inst2/test.snap new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/lib/inst2/test.xlog b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/lib/inst2/test.xlog new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/log/inst1/test.log b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/log/inst1/test.log new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/log/inst2/test.log b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/log/inst2/test.log new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/run/inst1/app.pid b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/run/inst1/app.pid new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/run/inst2/app2.pid b/test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/var/run/inst2/app2.pid new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/modules/test_module.txt b/test/integration/pack/test_bundles/bundle_with_app_packignore/modules/test_module.txt new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_app_packignore/tt.yaml b/test/integration/pack/test_bundles/bundle_with_app_packignore/tt.yaml new file mode 100644 index 000000000..8f10d7f05 --- /dev/null +++ b/test/integration/pack/test_bundles/bundle_with_app_packignore/tt.yaml @@ -0,0 +1,11 @@ +env: + instances_enabled: instances_enabled + restart_on_failure: true +modules: + directory: modules +app: + run_dir: var/run + log_dir: var/log + wal_dir: var/lib + memtx_dir: var/lib + vinyl_dir: var/lib diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/.packignore b/test/integration/pack/test_bundles/bundle_with_packignore/.packignore new file mode 100644 index 000000000..6717b3a40 --- /dev/null +++ b/test/integration/pack/test_bundles/bundle_with_packignore/.packignore @@ -0,0 +1,2 @@ +modules +app.lua \ No newline at end of file diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/app.lua b/test/integration/pack/test_bundles/bundle_with_packignore/app.lua new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/app2/app2-scm-1.rockspec b/test/integration/pack/test_bundles/bundle_with_packignore/app2/app2-scm-1.rockspec new file mode 100644 index 000000000..6df4a5d6e --- /dev/null +++ b/test/integration/pack/test_bundles/bundle_with_packignore/app2/app2-scm-1.rockspec @@ -0,0 +1,14 @@ +package = 'app2' +version = 'scm-1' +source = { + url = '/dev/null', +} +-- Put any modules your app depends on here +dependencies = { + 'tarantool', + 'lua >= 5.1', +} +build = { + type = 'none'; +} + diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/app2/init.lua b/test/integration/pack/test_bundles/bundle_with_packignore/app2/init.lua new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/app2/instances.yaml b/test/integration/pack/test_bundles/bundle_with_packignore/app2/instances.yaml new file mode 100644 index 000000000..e80ded4fa --- /dev/null +++ b/test/integration/pack/test_bundles/bundle_with_packignore/app2/instances.yaml @@ -0,0 +1,3 @@ +inst1: + +inst2: diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/lib/inst1/test.snap b/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/lib/inst1/test.snap new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/lib/inst1/test.vylog b/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/lib/inst1/test.vylog new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/lib/inst1/test.xlog b/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/lib/inst1/test.xlog new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/lib/inst2/test.snap b/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/lib/inst2/test.snap new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/lib/inst2/test.xlog b/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/lib/inst2/test.xlog new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/log/inst1/test.log b/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/log/inst1/test.log new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/log/inst2/test.log b/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/log/inst2/test.log new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/run/inst1/app.pid b/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/run/inst1/app.pid new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/run/inst2/app2.pid b/test/integration/pack/test_bundles/bundle_with_packignore/app2/var/run/inst2/app2.pid new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app1.lua b/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app1.lua new file mode 120000 index 000000000..6dee7136a --- /dev/null +++ b/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app1.lua @@ -0,0 +1 @@ +../app.lua \ No newline at end of file diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/app2-scm-1.rockspec b/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/app2-scm-1.rockspec new file mode 100644 index 000000000..6df4a5d6e --- /dev/null +++ b/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/app2-scm-1.rockspec @@ -0,0 +1,14 @@ +package = 'app2' +version = 'scm-1' +source = { + url = '/dev/null', +} +-- Put any modules your app depends on here +dependencies = { + 'tarantool', + 'lua >= 5.1', +} +build = { + type = 'none'; +} + diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/init.lua b/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/init.lua new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/instances.yaml b/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/instances.yaml new file mode 100644 index 000000000..e80ded4fa --- /dev/null +++ b/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/instances.yaml @@ -0,0 +1,3 @@ +inst1: + +inst2: diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/lib/inst1/test.snap b/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/lib/inst1/test.snap new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/lib/inst1/test.vylog b/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/lib/inst1/test.vylog new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/lib/inst1/test.xlog b/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/lib/inst1/test.xlog new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/lib/inst2/test.snap b/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/lib/inst2/test.snap new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/lib/inst2/test.xlog b/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/lib/inst2/test.xlog new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/log/inst1/test.log b/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/log/inst1/test.log new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/log/inst2/test.log b/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/log/inst2/test.log new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/run/inst1/app.pid b/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/run/inst1/app.pid new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/run/inst2/app2.pid b/test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/var/run/inst2/app2.pid new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/modules/test_module.txt b/test/integration/pack/test_bundles/bundle_with_packignore/modules/test_module.txt new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/pack/test_bundles/bundle_with_packignore/tt.yaml b/test/integration/pack/test_bundles/bundle_with_packignore/tt.yaml new file mode 100644 index 000000000..8f10d7f05 --- /dev/null +++ b/test/integration/pack/test_bundles/bundle_with_packignore/tt.yaml @@ -0,0 +1,11 @@ +env: + instances_enabled: instances_enabled + restart_on_failure: true +modules: + directory: modules +app: + run_dir: var/run + log_dir: var/log + wal_dir: var/lib + memtx_dir: var/lib + vinyl_dir: var/lib diff --git a/test/integration/pack/test_pack.py b/test/integration/pack/test_pack.py index e2ae3b2e5..609704020 100644 --- a/test/integration/pack/test_pack.py +++ b/test/integration/pack/test_pack.py @@ -1836,3 +1836,109 @@ def test_pack_app_local_tarantool(tt_cmd, tmpdir_with_tarantool, tmp_path): build_output = tt_process.stdout.read() assert "Bundle is packed successfully" in build_output + + +@pytest.mark.docker +def test_pack_deb_packignore(tt_cmd, tmp_path): + if shutil.which('docker') is None: + pytest.skip("docker is not installed in this system") + + # check if docker daemon is up + rc, _ = run_command_and_get_output(['docker', 'ps']) + assert rc == 0 + + tmp_path = os.path.join(tmp_path, "bundle_with_packignore") + shutil.copytree(os.path.join(os.path.dirname(__file__), "test_bundles", + "bundle_with_packignore"), + tmp_path, symlinks=True, ignore=None, + copy_function=shutil.copy2, ignore_dangling_symlinks=True, + dirs_exist_ok=True) + + base_dir = tmp_path + + rc, output = run_command_and_get_output( + [tt_cmd, "pack", "deb"], + cwd=base_dir, env=dict(os.environ, PWD=tmp_path)) + assert rc == 0 + + package_file_name = "bundle_with_packignore_0.1.0.0-1_" + get_arch() + ".deb" + package_file = os.path.join(base_dir, package_file_name) + assert os.path.isfile(package_file) + + unpacked_pkg_dir = os.path.join(tmp_path, 'unpacked') + os.mkdir(unpacked_pkg_dir) + + rc, output = run_command_and_get_output(['docker', 'run', '--rm', '-v', + '{0}:/usr/src/'.format(base_dir), + '-v', '{0}:/tmp/unpack'.format(unpacked_pkg_dir), + '-w', '/usr/src', + 'jrei/systemd-ubuntu', + '/bin/bash', '-c', + '/bin/dpkg -i {0}' + '&& id tarantool ' + ' && dpkg -x {0} /tmp/unpack ' + ' && chown {1}:{2} /tmp/unpack -R'. + format(package_file_name, os.getuid(), os.getgid()) + ]) + assert rc == 0 + + env_path = os.path.join(unpacked_pkg_dir, 'usr', 'share', 'tarantool', 'bundle_with_packignore') + for path in ['tt.yaml', 'instances.enabled', 'app2', 'bin/tt', 'bin/tarantool']: + assert os.path.exists(os.path.join(env_path, path)) + + for path in ['modules', 'app.lua', 'app2/var/lib/inst1', 'app2/var/log', + 'app2/var/run/inst2/app2.pid', 'app2/init.lua']: + assert not os.path.exists(os.path.join(env_path, path)) + + +@pytest.mark.docker +def test_pack_deb_app_packignore(tt_cmd, tmp_path): + if shutil.which('docker') is None: + pytest.skip("docker is not installed in this system") + + # check if docker daemon is up + rc, _ = run_command_and_get_output(['docker', 'ps']) + assert rc == 0 + + tmp_path = os.path.join(tmp_path, "bundle_with_app_packignore") + shutil.copytree(os.path.join(os.path.dirname(__file__), "test_bundles", + "bundle_with_app_packignore"), + tmp_path, symlinks=True, ignore=None, + copy_function=shutil.copy2, ignore_dangling_symlinks=True, + dirs_exist_ok=True) + + base_dir = tmp_path + + rc, output = run_command_and_get_output( + [tt_cmd, "pack", "deb"], + cwd=base_dir, env=dict(os.environ, PWD=tmp_path)) + assert rc == 0 + + package_file_name = "bundle_with_app_packignore_0.1.0.0-1_" + get_arch() + ".deb" + package_file = os.path.join(base_dir, package_file_name) + assert os.path.isfile(package_file) + + unpacked_pkg_dir = os.path.join(tmp_path, 'unpacked') + os.mkdir(unpacked_pkg_dir) + + rc, output = run_command_and_get_output(['docker', 'run', '--rm', '-v', + '{0}:/usr/src/'.format(base_dir), + '-v', '{0}:/tmp/unpack'.format(unpacked_pkg_dir), + '-w', '/usr/src', + 'jrei/systemd-ubuntu', + '/bin/bash', '-c', + '/bin/dpkg -i {0}' + '&& id tarantool ' + ' && dpkg -x {0} /tmp/unpack ' + ' && chown {1}:{2} /tmp/unpack -R'. + format(package_file_name, os.getuid(), os.getgid()) + ]) + assert rc == 0 + + env_path = os.path.join(unpacked_pkg_dir, 'usr', 'share', 'tarantool', 'bundle_with_app_packignore') + for path in ['tt.yaml', 'instances.enabled', 'app2', 'bin/tt', 'bin/tarantool']: + assert os.path.exists(os.path.join(env_path, path)) + + for path in ['modules', 'app.lua', 'app2/var/lib/inst1', 'app2/var/log', + 'app2/var/run/inst2/app2.pid', 'app2/init.lua']: + assert not os.path.exists(os.path.join(env_path, path)) \ No newline at end of file