For sure we all have repositories for services we haven't updated in a while. Services that we set up locally, test, deploy, and that's it. May be see it again in some time when it's time to patch or add new features.
Some weeks ago I was working with my team in one of those projects, and a new teammate was assigned a small task there, but he couldn't spin up locally. We spent almost 2-3 hours, just to find out that some configs in the local YAML files were missing, and other ones had changed the key name.
Sounds familiar?
Samplr
That was my motivation to build this command:
unmultimedio / samplr
Generate sample files (and keep them updated!) after you .gitignore your real ones.
Samplr
Samplr is a language-agnostic command that will generate updated commitable sample files, while you keep original ones git-ignored.
See it in action (1m video)Installation
Follow instructions here.
Why?
We all .gitignore
files in our repos. Many of those for security purposes, like configuration files with secrets or frequently-changing URLs that we don't want to commit and clutter in every PR everytime we change them.
So, what do we normally do? We make a copy of the original file, and append a .sample
to it. This serves the purpose for new repo clones to get a configuration file structure, and we just need to fill the secrets or URLs locally.
Actual file | File that we commit | So we can do |
---|---|---|
# configuration.yml
some: variables
url: http://aws.url/changes.frequently
foo: bar
token: MY.S3CUR3.T0K3N
|
# configuration.yml.sample
some: variables
url: REPLACE_ME_DEV_URL
foo: bar
token: REPLACE_ME_TOKEN
|
Samplr is a small command that takes a file with a path that matches with a regex in your config, and scans the content for some keywords to generate a copy of the file, obscuring the secrets you're not supposed to check in your repo.
Imagine having something like:
# conf.yaml that's gitignored
foo: foo value
secret: S3CR3T
bar: var value
And a git hook that automatically updates the sample copy every commit with:
# conf.sample.yaml that will be checked in
foo: foo value
secret: REPLACE_ME
bar: var value
Well, now all of our projects magically update our sample files everytime there's a change in the configuration files.
Gotchas
If you read carefully the README, you'll find that this is a command that's not really tied to git or gitignored files, it's just the use case I've found and what I'm using it for at the moment. But in reality, is a file copier with a way to obscure content.
Happy sampling!
Top comments (0)