Skip to content
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
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Japsty
Copy link
Contributor

@Japsty Japsty commented Oct 15, 2024

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

@Japsty Japsty force-pushed the gh-812-tt-pack-allow-to-ignore-paths branch 3 times, most recently from ff296ba to 3fdb91c Compare October 21, 2024 10:04
@Japsty Japsty marked this pull request as ready for review October 21, 2024 10:06
@Japsty Japsty force-pushed the gh-812-tt-pack-allow-to-ignore-paths branch 4 times, most recently from 4fa8e8b to 6c87f23 Compare October 21, 2024 11:45
cli/pack/common.go Outdated Show resolved Hide resolved
@Japsty Japsty force-pushed the gh-812-tt-pack-allow-to-ignore-paths branch 7 times, most recently from b93703e to 22c8d2b Compare October 29, 2024 21:29
@Japsty Japsty requested a review from psergee November 5, 2024 08:54
}

if err = removeIgnoredFiles(appPath, ignorePatterns); err != nil {
return fmt.Errorf("failed to remove ignored files: %v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("failed to remove ignored files: %v", err)
return fmt.Errorf("failed to remove ignored files: %s", err)

if !inst.IsFileApp {
ignorePatterns, err := readPackIgnore(appPath)
if err != nil {
return fmt.Errorf("failed to read .packignore: %v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("failed to read .packignore: %v", err)
return fmt.Errorf("failed to read .packignore: %s", err)

if !inst.IsFileApp {
ignorePatterns, err := readPackIgnore(appPath)
if err != nil {
return fmt.Errorf("failed to read .packignore: %v", err)
Copy link
Collaborator

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.

@@ -383,6 +394,16 @@ func prepareBundle(cmdCtx *cmdcontext.CmdCtx, packCtx *PackCtx,
}
}

projectPath := filepath.Dir(packCtx.configFilePath)
Copy link
Collaborator

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.

projectPath := filepath.Dir(packCtx.configFilePath)
ignorePatterns, err := readPackIgnore(projectPath)
if err != nil {
return "", fmt.Errorf("failed to read .packignore: %v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return "", fmt.Errorf("failed to read .packignore: %v", err)
return "", fmt.Errorf("failed to read .packignore: %s", err)

} else {
err = os.Remove(path)
if err != nil {
return fmt.Errorf("failed to remove file %q: %v", path, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("failed to remove file %q: %v", path, err)
return fmt.Errorf("failed to remove file %q: %s", path, err)

filePath := filepath.ToSlash(path)

if strings.HasSuffix(pattern, "/") {
if strings.HasPrefix(filePath, pattern) {
Copy link
Collaborator

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
Copy link
Collaborator

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 {
Copy link
Collaborator

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",
Copy link
Collaborator

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.

@Japsty Japsty force-pushed the gh-812-tt-pack-allow-to-ignore-paths branch 7 times, most recently from 5e2ca12 to 32981d4 Compare November 18, 2024 10:02
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)
@Japsty Japsty force-pushed the gh-812-tt-pack-allow-to-ignore-paths branch from 32981d4 to 0d23fde Compare November 18, 2024 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to ignore paths on artifact pack
2 participants