Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to version control config files pragmatically?

Suppose we have a config file with sensitive passwords. I'd like to version control the whole project, including the config file as well, but I don't want to share my passwords.
That could be good, if this config file:

database_password=secret
foo=bar

becomes

database_password=*
foo=bar

and the other users of the vcs could also set up the password on they own. To ignoring the file isn't a good approach, the developers should be aware, if the config file changes.

Example:

Local version:

database_password=own_secret
foo=bar

config file in vcs:

database_password=*
foo=bar

Then suddenly, the config file changes:

database_password=*
foo=bar
baz=foo

And the local version would become for each developer:

database_password=own_secret
foo=bar
baz=foo

This is my solution. How could I achieve this behaviour? How do you store your config files? Is there a way to do that, or should I hack something?

like image 292
erenon Avatar asked Dec 29 '09 14:12

erenon


People also ask

Is git config version controlled?

git/config file. git doesn't let you version anything under the . git directory because the contents of the . git are local to your repo, and 2 people cloning from the same remote URL, need not have the same set of files under the .

Can you edit config files?

While you can edit many config files, be sure to make a copy of the file before making any changes.

What is .config extension?

A CONFIG file is a configuration file used by various applications. It contains plain text parameters that define settings or preferences for building or running a program. CONFIG files are often referenced by software development programs to configure applications. An example CONFIG file is Microsoft's Web.


3 Answers

Instead of version-controlling the actual configuration file, you could put a template or defaults file in version control, and a script that would ask for DB information and credential to generate the real config file, which would be excluded from (i.e. ignored by) version control. On checkout, developers could run this script to get a working environment. This script could also be invoked as part of any installation process that your application uses.

Also see my answer to a similar question.

like image 62
Phil Miller Avatar answered Oct 17 '22 22:10

Phil Miller


Not sure how your config is implemented, but having hierarchical overides is how I would handle this.

You have a main config that contains common config plus dummy username/password (or leave these out altogether). Each developer then creates a local override.config (or whatever) with their specific username/password. The main config goes under source control, the developer (or machine) local overrides do not.

I've done this in .NET but not PHP so I don't know how easy this would be I'm afraid.

like image 12
Paolo Avatar answered Oct 17 '22 21:10

Paolo


Create a local overrides file that contains the user specific info as PHP variables.

For instance create a file called local_overrides.php which contains the following:

$local_password = 'qUzaEAFK13uK2KHy';

Then in the file that includes your DB password do something like this

$overrides = 'local_overrides.php';

if (file_exists($overrides)) {
   #include_once($overrides);
   $db_password = $local_password;
} else {
   // perform appropriate action: set default? echo error message? log error?    
   $db_password = 'l1m1t3d!'
}

The local overrides file would never has to be seen by source control.

like image 5
Robert Groves Avatar answered Oct 17 '22 23:10

Robert Groves