-
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
base: master
Are you sure you want to change the base?
pack: added .packignore #985
Conversation
ff296ba
to
3fdb91c
Compare
4fa8e8b
to
6c87f23
Compare
cli/pack/common.go
Outdated
@@ -277,14 +277,30 @@ func getDestAppDir(bundleEnvPath, appName string, | |||
|
|||
// copyApplications copies applications from current env to the result bundle. | |||
func copyApplications(bundleEnvPath string, packCtx *PackCtx, | |||
cliOpts, newOpts *config.CliOpts) error { | |||
var err error | |||
cliOpts, newOpts *config.CliOpts, toIgnore map[string]struct{}) error { |
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.
The name of this function is "copy applications". One of the arguments is a set of paths to do not copy. Do we exclude the same paths for all applications? If so, this is not what was expected.
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.
Changed the implementation, now files are deleted from the directory after full copying by a separate function 'removeIgnoredFiles'
b93703e
to
22c8d2b
Compare
cli/pack/common.go
Outdated
} | ||
|
||
if err = removeIgnoredFiles(appPath, ignorePatterns); err != nil { | ||
return fmt.Errorf("failed to remove ignored files: %v", err) |
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.
return fmt.Errorf("failed to remove ignored files: %v", err) | |
return fmt.Errorf("failed to remove ignored files: %s", err) |
cli/pack/common.go
Outdated
if !inst.IsFileApp { | ||
ignorePatterns, err := readPackIgnore(appPath) | ||
if err != nil { | ||
return fmt.Errorf("failed to read .packignore: %v", err) |
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.
return fmt.Errorf("failed to read .packignore: %v", err) | |
return fmt.Errorf("failed to read .packignore: %s", err) |
cli/pack/common.go
Outdated
if !inst.IsFileApp { | ||
ignorePatterns, err := readPackIgnore(appPath) | ||
if err != nil { | ||
return fmt.Errorf("failed to read .packignore: %v", err) |
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.
It would be nice to have this file name as a const.
cli/pack/common.go
Outdated
@@ -383,6 +394,16 @@ func prepareBundle(cmdCtx *cmdcontext.CmdCtx, packCtx *PackCtx, | |||
} | |||
} | |||
|
|||
projectPath := filepath.Dir(packCtx.configFilePath) |
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.
Let's get if from common context. As I remember, this is ConfigDir member.
cli/pack/common.go
Outdated
projectPath := filepath.Dir(packCtx.configFilePath) | ||
ignorePatterns, err := readPackIgnore(projectPath) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to read .packignore: %v", err) |
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.
return "", fmt.Errorf("failed to read .packignore: %v", err) | |
return "", fmt.Errorf("failed to read .packignore: %s", err) |
cli/pack/ignore.go
Outdated
} else { | ||
err = os.Remove(path) | ||
if err != nil { | ||
return fmt.Errorf("failed to remove file %q: %v", path, err) |
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.
return fmt.Errorf("failed to remove file %q: %v", path, err) | |
return fmt.Errorf("failed to remove file %q: %s", path, err) |
cli/pack/ignore.go
Outdated
filePath := filepath.ToSlash(path) | ||
|
||
if strings.HasSuffix(pattern, "/") { | ||
if strings.HasPrefix(filePath, pattern) { |
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.
How is it possible for filePath, which is a relative path, to have a prefix with first '/'?
It would be nice to have unit-tests for this function.
@@ -0,0 +1,4 @@ | |||
var/lib/inst1 | |||
var/log | |||
var/run/inst2/app2.pid |
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.
run_dir should not be copied, even without the .packignore file.
return fmt.Errorf("failed to read .packignore: %v", err) | ||
} | ||
|
||
if err = removeIgnoredFiles(appPath, ignorePatterns); err != nil { |
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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
There are no tests for ignoring app files/dirs.
5e2ca12
to
32981d4
Compare
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](tarantool#812)
32981d4
to
0d23fde
Compare
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