configuration files in version control while deploying
-
06-10-2020 - |
Question
I have a particular problem with config files and deployment. When I deploy my project, it eventually moves to two different branches: staging and production (using SVN here)
I make the branch from my local working copy of the project. What this ends up doing is overwriting staging and development's copy of the config files, so I manually have to go in and make the correct changes every time I deploy.
Does it make sense to delete the config files from SVN completely since it's set in stone? Or is there another way in doing this?
Solution
What I usually do is maintain multiple configuration files in the repository, but not under the actual name (e.g. in a dedicated folder that gets excluded from deployment). My deployment scripts then copy the appropriate config file into the final location. So my deployment routine goes:
- checkout
- compile
- run deployment script
OTHER TIPS
You don't want to delete the files from SVN - since that will cause it to delete them from the server when you deploy.
SVN offers a feature called svn: ignore that you can use to exclude one or multiple individual files from version control or match a pattern of filenames to ignore. Basically, ignoring files means that SVN will leave them as they are on each working copy or deployment server, so they can be different in each place.
There are two ways to use ignore from the command line.
A: Edit the ignore properties for a directory.
- Use
cd trunk/blah
to change to the directory that contains files you want to ignore. - Use
svn propedit svn:ignore .
to edit the ignore properties for this directory. This will open a text editor. - In the file that opens, add or modify lines which will represent the file(s) you want to ignore. For example, adding a line of
*.txt
will cause SVN to ignore all files ending in .txt. Adding a line ofconfig.php
will cause SVN to ignore the config.php file. - Save and exit the file.
- Commit the property change.
svn commit -m "New Ignores"
B: Use a single command to set the SVN ignore property on a directory.
- Use
cd trunk/blah
to change to the directory that contains files you want to ignore. - Use
svn propset svn:ignore config.php .
to set the SVN ignore property to ignore the config.php file. -
- Commit the property change.
svn commit -m "New Ignores"
- Commit the property change.
Good introductory article on svn:ignore. "Official SVN documentation."