turbo icon indicating copy to clipboard operation
turbo copied to clipboard

Prune does not respect .gitignore files inside packages

Open roman-yakobnyuk opened this issue 2 years ago • 8 comments

What version of Turborepo are you using?

1.2.12

What package manager are you using / does the bug impact?

Yarn v1

What operating system are you using?

Mac

Describe the Bug

When running a prune command to prepare folders for docker, those folders include files that are ignored by the .gitignore inside packages as well as at the root of the monorepo. One such example would be node_modules folder that gets copied to generated out/full folder with the following command:

yarn turbo prune --docker --scope="api-service"

Expected Behavior

I would expect prune to copy only files that are not ignored by git. (Or something like .turboignore)

To Reproduce

Run command specified above to generate pruned version.

TURBO-1970

roman-yakobnyuk avatar May 25 '22 00:05 roman-yakobnyuk

It's weird that there's no support for ignoring files/directories.

marcus-sa avatar Oct 24 '22 14:10 marcus-sa

.env type files would be another example of files that would often be a mistake to carry over

iamjaredwalters avatar Feb 15 '23 17:02 iamjaredwalters

@chris-olszewski do you know if there were any changes to this in the last year?

mehulkar avatar Oct 20 '23 17:10 mehulkar

Anyone found a solution for this?

weyert avatar Dec 21 '23 02:12 weyert

We talked about this at the team meeting and decided that we should do this! Feel free to make a PR or even a failing test case!

mehulkar avatar Dec 21 '23 14:12 mehulkar

Anyone found a solution for this?

I've used several different approaches. Here's one really ugly workaround I'm using in one case. After running turbo prune --docker ..., I run this command:

(cd out/full && git init . && git add . && git clean -fdX && rm -rf .git)

Another one is to first have git make a copy of the local repo (git clone $PATH_TO_SRC $PATH_TO_DST), and run turbo prune in that. The behavior here is a bit different than the above, insofar as git clone will only copy over committed files, so if you want turbo prune to include untracked or modified files, you'll need to commit them first.

Another approach I've used is to run turbo prune inside a nix flake build target, which automatically only uses your git files. But I'm not happy with that approach either because nix using a lot of extra disk storage that you need to regularly clear.

Lastly, I've used a Dockerfile to build the pruned output, where you can try to put your .gitignore contents into .dockerignore. I found three drawbacks: a) this doesn't fully work if you have special .gitignore files in subfolders, b) you need to copy the results back out of the docker image, which is a pain, c) you need to keep on top of deleting the images.

ellis avatar Mar 31 '24 18:03 ellis