puppetlabs / r10k

Smarter Puppet deployment
Other
802 stars 355 forks source link

Feature: Add `extra_delete` option: rm files after sync #1359

Closed nyetsche closed 9 months ago

nyetsche commented 11 months ago

This PR implements the option to each module of a list of files to delete after the copy into the local directory.

The use case is repositories/modules with "unwanted" information. In our environment all modules downloaded with r10k are checked into our main Puppet git repository. We want to skip files in our repo that we don't need, and do so in a repeatable way.

Example Puppetfile with this feature:

mod 'puppetlabs-cron_core',
  type:    'forge',
  version: '1.2.0',
  extra_delete: ['.github', 'locales', '*/README_*.md', ]

This downloads puppetlabs-cron_core, then removes the directory .github, the directory locales, and the glob */README_*.md.

The module on filesytem without this option:

original
└── cron_core
    ├── CHANGELOG.md
    ├── CODEOWNERS
    ├── LICENSE
    ├── README.md
    ├── REFERENCE.md
    ├── data
    │   └── common.yaml
    ├── hiera.yaml
    ├── lib
    │   └── puppet
    │       ├── provider
    │       │   └── cron
    │       │       ├── crontab.rb
    │       │       └── filetype.rb
    │       └── type
    │           └── cron.rb
    ├── locales
    │   ├── config.yaml
    │   ├── ja
    │   │   └── puppetlabs-cron_core.po
    │   └── puppetlabs-cron_core.pot
    ├── metadata.json
    ├── pdk.yaml
    └── readmes
        └── README_ja_JP.md

11 directories, 16 files

The module on the filesytem with this option as show above:

excluded
└── cron_core
    ├── CHANGELOG.md
    ├── CODEOWNERS
    ├── LICENSE
    ├── README.md
    ├── REFERENCE.md
    ├── data
    │   └── common.yaml
    ├── hiera.yaml
    ├── lib
    │   └── puppet
    │       ├── provider
    │       │   └── cron
    │       │       ├── crontab.rb
    │       │       └── filetype.rb
    │       └── type
    │           └── cron.rb
    ├── metadata.json
    ├── pdk.yaml
    └── readmes

9 directories, 12 files

This option uses Dir.glob for matching: https://ruby-doc.org/core-2.6.3/Dir.html#method-c-glob

If a directory is listed, the entire directory is removed: (rm -rf).

Not setting extra_delete: ... is equivalent to extra_delete: [], which will cause no files to be deleted.

CLAassistant commented 11 months ago

CLA assistant check
All committers have signed the CLA.

dbarrous commented 11 months ago

This would be such a great feature to have!

github-actions[bot] commented 9 months ago

This PR has been marked stale because it has had no activity for 60 days. If you are still interested in getting this merged, please comment and we'll try to move it forward. Otherwise, it will be closed in 7 days.