-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pack: added .packignore #985
Open
Japsty
wants to merge
1
commit into
tarantool:master
Choose a base branch
from
Japsty:gh-812-tt-pack-allow-to-ignore-paths
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1068,6 +1068,26 @@ func Test_prepareBundle(t *testing.T) { | |
{assert.FileExists, "app/tt.yaml"}, | ||
}, | ||
}, | ||
{ | ||
name: "Packing env with packignore", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no tests for ignoring app files/dirs. |
||
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 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
instances.enabled/app | ||
modules | ||
app2/var | ||
app.lua |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../test/integration/pack/test_bundles/bundle1/app2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../test/integration/pack/test_bundles/bundle1/instances_enabled | ||
psergee marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../test/integration/pack/test_bundles/bundle1/modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Empty file.
14 changes: 14 additions & 0 deletions
14
test/integration/pack/test_bundles/bundle_with_app_packignore/app2/app2-scm-1.rockspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} | ||
|
Empty file.
3 changes: 3 additions & 0 deletions
3
test/integration/pack/test_bundles/bundle_with_app_packignore/app2/instances.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
inst1: | ||
|
||
inst2: |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions
1
test/integration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app1.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../app.lua |
2 changes: 2 additions & 0 deletions
2
...tegration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/.packignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
testfile | ||
testdir |
14 changes: 14 additions & 0 deletions
14
...n/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/app2-scm-1.rockspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} | ||
|
Empty file.
3 changes: 3 additions & 0 deletions
3
...ration/pack/test_bundles/bundle_with_app_packignore/instances_enabled/app2/instances.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
inst1: | ||
|
||
inst2: |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
11 changes: 11 additions & 0 deletions
11
test/integration/pack/test_bundles/bundle_with_app_packignore/tt.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
2 changes: 2 additions & 0 deletions
2
test/integration/pack/test_bundles/bundle_with_packignore/.packignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
modules | ||
app.lua |
Empty file.
14 changes: 14 additions & 0 deletions
14
test/integration/pack/test_bundles/bundle_with_packignore/app2/app2-scm-1.rockspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} | ||
|
Empty file.
3 changes: 3 additions & 0 deletions
3
test/integration/pack/test_bundles/bundle_with_packignore/app2/instances.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
inst1: | ||
|
||
inst2: |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions
1
test/integration/pack/test_bundles/bundle_with_packignore/instances_enabled/app1.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../app.lua |
14 changes: 14 additions & 0 deletions
14
...ation/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/app2-scm-1.rockspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} | ||
|
Empty file.
3 changes: 3 additions & 0 deletions
3
...ntegration/pack/test_bundles/bundle_with_packignore/instances_enabled/app2/instances.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
inst1: | ||
|
||
inst2: |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
11 changes: 11 additions & 0 deletions
11
test/integration/pack/test_bundles/bundle_with_packignore/tt.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we remove files before copying the application. This approach will surprise the user.
We should skip copying such files, not removing them from the source directory.