문제

I have 2 branches in Git - staging and production. They are deployed to the same VPS where there is one production database and a separate staging database. This allows us to stage new features without affecting the production environment. Then, when we're ready, we replicate the database changes from staging to production.

What is the best way to set this up so that the staging branch has separate database credentials to production? At the moment, the database creds are stored in a single file. I've been thinking about using gitignore to ignore this file in both branches and edit it manually so that it remains different on each branch. Is this the best thing to do or is there a better way?

도움이 되었습니까?

해결책

We use a cascading approach:

  1. Default settings are in a common "config" file.
  2. For each stage of development, it has its own configuration file, for example we have a config_prod and a config_dev.
  3. Each stage runs as a different (system) user, and for that user we set an environment variable PROJ_SETTINGS and point it to the file that we need to load.

The code then read the defaults, and then overrides them with whatever is available from the resource pointed to by the environment variable (if it exists).

Setting of this variable is taken care of by our normal devops/automation scripts. We have a few advantages:

  1. Keeps all configuration under version control.
  2. Easy to switch settings without modifying the source.

다른 팁

Yes gitignoring the database.yml file is an approach I've used in a few organizations.

We usually keep a database.yml.sample in source control so make it easier. Users just copy that to database.yml and modify as appropriate.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top