Store various content of a specific file in Git branches

I have config.php that are supposed to be different in content in different branches, for example. testing and master .

I asked in another question ( Prohibit merging of a file with the master with Git ) to prevent merging of this file.

But I wonder is this the right way to do this?

I believe this is a fairly common case of using different configuration files in different environments, and you want the configuration to be monitored, right?

+7
source share
4 answers

The classic way to do this is to create the default configuration file config.yml-dist (let's pretend your source file is called config.yml); you add the source file to .gitignore, and the version only dist.
After deploying the application or re-cloning the project, simply cp config.yml-dist config.yml and change the necessary parameters.

This method is used by many people whom I met in the PHP industry.

But, there I like more and what I find cleaner: using environment variables. Example:

 username: <%= ENV['MONGOID_USERNAME'] %> password: <%= ENV['MONGOID_PASSWORD'] %> database: <%= ENV['MONGOID_DATABASE'] %> 

Thus, you will have one configuration file with the version and you will not need to edit any.

+4
source

For the configuration file, one solution is to not modify it (thus, the merge problem!)

You would use a content filter filter :

content filter driver

You would run the version:

  • one value file (for the master environment)
  • single value file (for dev environment)
  • one template file (with placeholders, for example @ PORT_NUMBER@ )
  • one ' smudge ' script can be used based on the current branch and based on the contents of the extracted file (here the template file) to generate the actual configuration file (which remains 'private', i.e. non-version).
  • one ' clean ' script is able to detect any changes in values โ€‹โ€‹in a private configuration file and store these changed values โ€‹โ€‹in value (version) files.
+4
source

You can have a master branch that does not contain this file, and only have it in the branches โ€” that would be the easiest way.

Alternatively, and provided that the main configuration is stable enough, otherwise it will be a big pain - commit the config.php changes in each branch, and then always pull with a reboot when you receive the changes from master so that the configuration changes are reapplied every time.

+2
source

Why don't you save all the environment-specific configuration files, mainly the repo? Then, during the build or deployment process, you should use any configuration file. There are many different ways to implement it, depending on your build / deployment tool, but by any means, I think it's best to have it in branches.

My opinion is that you definitely want the configuration files to be saved in version control and deployed using the deployment tool, so you would not have old versions that would freeze due to lack of updates or a manual error.

Usually there is a folder structure like

 /configurations/test/properties/ /configurations/prod/properties/ 

and the deployment tool uses them for each environment on demand. Any sensitive information, such as passwords, can be either hashed or encypted: these technologies, such as secure storage, support this directly.

0
source

All Articles