git post-receive hook to update multiple servers

帅比萌擦擦* 提交于 2019-12-13 16:53:55

问题


I'm using git post-receive hook to deploy versions of the web application from three branches (master, staging, and stable) on three servers (development, testing and production). The pairing between branches and servers is currently hard-coded in the script. However I'd like to remove this restriction and make this hook possible to manage unlimited quantity of branches. It can be done in the following way:

  • move all per-branch config options to some separate files, for example .git/???/<branch_name>
  • the main script will check if such file is available for every branch, source it and then deploy on the remote server using configuration parameters from that file.

However I don't know where exactly in .git directory can I place such files. Or maybe there is a better solution?


回答1:


Your options, as far as I can tell:

  • Use a stronger convention for server naming, so that config isn't necessary, beyond the base domain name. Leave that in the script. (That is, branchX -> branchX-deploy.example.com.)

  • Put a config file wherever you feel like in the .git directory, like you suggested. If it's not a filename git cares about, it'll never notice it. I'm not sure why you'd want to do this, though.

  • Put it in .git/config. Git lets you define arbitrary config parameters of the form branch.<name>.foo. (I have no idea if this is a feature or an oversight. It's not documented, as far as I know.) In your case, something like branch.master.deploy_server set to development.example.com. Your script could then just go through all branches, and check whether that config option is set or not. (Use git config --get.)

  • Put a config file in your repository. This seems a lot better than hiding it away. You might as well track the settings. If necessary, provide a way to override them - supply a different config file as an argument, supply individual branches/servers as options, interactive prompts, whatever suits you.

Personally, I'd probably do the last one. Tracking settings, even if they're only default settings, can't hurt you.



来源:https://stackoverflow.com/questions/4155144/git-post-receive-hook-to-update-multiple-servers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!