使用Git Push的分段和生产服务器的Web开发方案 [英] Web development scheme for staging and production servers using Git Push

查看:159
本文介绍了使用Git Push的分段和生产服务器的Web开发方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用git来管理一个动态网站(PHP + MySQL),我想从我的 localhost 发送我的文件到我的 staging 开发服务器。



我目前确信解决这个问题的最佳方法是使用这个git分支模型来组织我的本地git仓库。从那里开始,我将 release 分支用于 push 到我的临时服务器进行测试。如果 release 代码在临时服务器上运行,我就很高兴,然后可以将合并 master 分支和 push 到我的生产服务器。

推送到 Staging Server



正如许多 introductory git post s,我可能遇到问题 push ing一个非空回购,所以,如 this response ,我计划将推送 发布分支添加到 bare repo在服务器上,并有一个post-receive钩子 clone s bare 回购一个非空的回购,也可以作为网站托管目录。



推到生产服务r



这是我最新的混淆来源...



这让我很好奇,为什么@Paul指出,当推送到一个活的开发服务器时是完全不同的故事。我想我没有看到问题。遵循上面相同的步骤是否安全无忧,但是对于 master 分支?潜在的陷阱在哪里?



配置文件:



关于配置文件每个环境( .htaccess config.php 等),对来说似乎是最简单的。 gitignore 这些文件中的每一个都在其各自服务器上的相应仓库中。你能否立即看到任何错误?更好的解决方案?



访问数据:



最后,正如我最初所说,网站使用MySQL数据库来存储数据。您如何建议我从临时服务器 localhost 访问该数据(用于测试目的)?



I意识到我可能为单个帖子询问了太多问题,但是因为它们都与设置此开发方案的最佳方式有关,所以我认为这是必要的。

解决方案

推送到生产服务器



我假定在回复你引用,答案指的是推到生产服务器的另一个故事,只是因为我们可以将任何旧的提交推送到临时服务器进行测试,但是您只需将经过彻底测试的版本推送到生产服务器即可。



我认为您可以参考(使用 post-receive > git checkout -f 和适当设置的 GIT_WORK_TREE )是一个很好的从git部署的配置。

配置Files



这是一个合理的计划,但您必须谨慎使用 .gitignore 忽略配置文件 - 你可能想看看这个答案更多关于此:





访问数据



我认为有关您的登台服务器数据的问题确实是一个单独的问题,因为没有任何数据会存在于您的版本控制系统中 - 所以在这里增加关于该问题的另一个问题可能值得。您可以 有一个脚本来转储您的实时服务器上的数据并将其导入登台服务器,但我可以想到许多情况是不可取的,尤其是在客户详细信息和数据保护法律要考虑。


I am using git to manage a dynamic website (PHP + MySQL) and I want to send my files from my localhost to my staging and development servers in the most efficient and hassle-free way.

I am currently convinced that the best way for me to approach this problem is to use this git branching model to organize my local git repo. From there, I will use the release branches to push to my staging server for testing. Once I am happy that the release code works on the staging server, I can then merge with my master branch and push that to my production server.

Pushing to Staging Server:

As noted in many introductory git posts, I could run into problems pushing into a non-bare repo, so, as suggested in this response, I plan to push the release branch to a bare repo on the server and have a post-receive hook that clones the bare repo to a non-bare repo that also acts as the web-hosted directory.

Pushing to Production Server:

Here's my newest source of confusion...

In the response that I cited above, it made me curious as to why @Paul states that it's a completely different story when pushing to a live, development server. I guess I don't see the problem. Would it be safe and hassle-free to follow the same steps as above, but for the master branch? Where are the potential pit-falls?

Config Files:

With respect to configuration files that are unique to each environment (.htaccess, config.php, etc), it seems simplest to .gitignore each of those files in their respective repos on their respective servers. Can you see anything immediately wrong with this? Better solutions?

Accessing Data:

Finally, as I initially stated, the site uses MySQL databases to store data. How would you suggest I access that data (for testing purposes) from the staging server and localhost?

I realize that I may have asked way too many questions for a single post, but since they're all related to the best way to set up this development scheme, I thought it was necessary.

解决方案

Pushing to the production server

I assume that in the response you quote, the answer refers to pushing to the production server as "a different story", just because one can push any old commit to the staging server for testing, but you would be very careful only to push a thoroughly tested version to the production server.

I think the approach you refer to (of deploying by pushing to a bare repository with a post-receive that does git checkout -f with an appropriately set GIT_WORK_TREE) is a good one for deploying from git.

Config Files

That is a reasonable plan, but you have to be a somewhat careful about using .gitignore to ignore configuration files - you might want to look at this answer for more about this:

Accessing data

I think the question about data for your staging server really is a separate issue, since none of that data will be in your version control system - it might be worth adding another question here about that issue. You could have a script that dumps data on your live server and imports it to the staging server, but I can think of many situations in which that would be undesirable, particularly where customer details and data protections laws have to be considered.

这篇关于使用Git Push的分段和生产服务器的Web开发方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆