项目中托管特定代码:也推送到 Github?

发布于 2024-10-08 07:50:21 字数 446 浏览 10 评论 0原文

想象一下这个常见的场景:我编写了一个很酷的项目,我想与世界分享。所以:我把它放在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

舞袖。长 2024-10-15 07:50:22

与 Breun 的建议类似,(所以你的问题将得到双重回答)我使用 settings.py 文件部署我的 Python 项目,该文件定义了生产计算机上所需的设置。 (debug=False,正确的数据库设置和文件路径...)

在文件末尾,我尝试像这样导入developmentsettings.py:

try:
    from projectnaam import developmentsettings
except:
    pass

该文件在版本控制中不存在,因此这将失败并默默地传递服务器。在我的开发计算机上,我手动创建文件并覆盖特定设置以满足我的开发需求。 (例如 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:

try:
    from projectnaam import developmentsettings
except:
    pass

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)

何以笙箫默 2024-10-15 07:50:22

为特定于部署的设置创建配置文件。例如,您可以为任何默认设置设置一个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.

红尘作伴 2024-10-15 07:50:22

并将您的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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文