项目中托管特定代码:也推送到 Github?
想象一下这个常见的场景:我编写了一个很酷的项目,我想与世界分享。所以:我把它放在 Github 上,并从我自己的网站上的 Github 获取它,以便人们可以看到演示。这也使得更新变得容易:只需从我的本地盒子推送到 Github,然后在我的服务器上获取。
我想跟踪访问者,因此我将 Google Analytics 以及其他一些特定于站点的内容(例如我站点上所有页面的全局标题)添加到项目中。然而,每个从 Github 查看我的项目的人也都会得到所有这些东西。
有一些解决方案可以防止这种情况发生。我可以为我的网站创建一个特定的“部署分支”,但这很麻烦。我可以在我的代码中进行某种切换(if ip === myip showStats()
),但这很丑陋。
另一种选择可能是使用 githooks,但我没有任何经验。
还有其他建议吗?人们在结帐时获得像这样的特定于部署的代码时是否会感到烦恼?
Imagine this common scenario: i hacked together a cool project i want to share with the world. So: i put it on Github, and fetch it from Github on my own website so people can see a demo. This also makes updating easy: just push from my local box to Github, fetch on my server.
I'd like to track visitors so i add Google Analytics and maybe some other site-specific stuff (like a global header for all pages on my site) to the project. However, everybody who checks out my project from Github gets all that stuff too.
There are a few solutions to prevent that. I could make a specific 'deployment branch' for my website, but that's cumbersome. I could make some kind of switch in my code (if ip === myip showStats()
), but that's ugly.
Another option might be to use githooks, but i haven't got any experience with that.
Any other suggestions? Are people even bothered when getting deployment-specific code like that in their checkouts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
与 Breun 的建议类似,(所以你的问题将得到双重回答)我使用 settings.py 文件部署我的 Python 项目,该文件定义了生产计算机上所需的设置。 (debug=False,正确的数据库设置和文件路径...)
在文件末尾,我尝试像这样导入developmentsettings.py:
该文件在版本控制中不存在,因此这将失败并默默地传递服务器。在我的开发计算机上,我手动创建文件并覆盖特定设置以满足我的开发需求。 (例如 sqlite 而不是 postgres)
这可以扩展到更复杂的部署策略,涉及 Fabric、Buildout、Capistrano 和 Chef 等内容。在(分布式)团队中工作时,这一切都变得更加重要。
我当前的开发流程现在如下:编辑代码,$ git commit -m“comment”,$ git Push,$ fab部署主生产(<-这会将“master”从原点拉到服务器上)
Similar to Breun's suggestion, (so your question will be double answered) I deploy my Python projects with a settings.py file which defines the settings that are needed on the production machine. (debug=False, proper database settings and file paths...)
At the end of the file, I try to import developmentsettings.py like this:
The file does not exist in version control, so this will fail and silently pass on the server. On my dev machine, I manually create the file and override specific settings to match my dev needs. (things like sqlite instead of postgres)
This can be extended into a more sophisticated deployment strategy, involving stuff like Fabric, Buildout, Capistrano and Chef. This all gets more important when working in (distributed) teams.
My current development flow now goes like: edit code, $ git commit -m "comment", $ git push, $ fab deploy master production (<- this pulls 'master' from origin onto the server)
为特定于部署的设置创建配置文件。例如,您可以为任何默认设置设置一个conf/defaults.conf,并让用户将任何本地部署特定的覆盖放在conf/local.conf中。
Create a configuration file for deployment-specific settings. You could for instance have a conf/defaults.conf for any default settings and let users put any local deployment-specific overrides in conf/local.conf.
并将您的settings.php 文件添加到.gitignore,否则您可能会上传它。
与全世界分享你的 Google Analytics (API) 代码并不是一个好主意,因为如果有人使用你的代码而不更改它,你的统计数据就会被搞砸。
And add your settings.php file to the .gitignore, otherwise you might upload it.
Sharing your Google analytics (api)code with the world isn't a good idea because your stats are going to be screwed up of someone uses your code without changing it.