在多阶段部署中使用 git-flow
在这里敲定我的部署方案。发布此问题后: 使用以下命令迁移生产站点Git 根本没有 VCS,我已经掌握了部署到本地存储库的要点。
我的本地开发服务器上有一个 git-flow 存储库,我可以推送到它,它将更新外部工作树。
我用 git-flow 设置了我的存储库,这是我的原始远程的样子:
$ git remote show origin
* remote origin
Fetch URL: ssh://user@host/var/git/dev/repo.git
Push URL: ssh://user@host/var/git/dev/repo.git
HEAD branch (remote HEAD is ambiguous, may be one of the following):
develop
master
Remote branches:
develop tracked
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local refs configured for 'git push':
develop pushes to develop (up to date)
master pushes to master (up to date)
我试图做的,是设置了 2 个伪环境。一台用于登台,一台用于生产。我希望它们的行为如下:
git push staging #pushes to remote staging repo with a post-receive hook "git checkout develop -f"
git push production #pushes to remote production repo with a post-receive hook "git checkout master -f"
这样,我们可以在本地开发并推送到我们的小型内部开发服务器并拥有所有历史记录。然后,当我们明确了登台/生产时,我们只需推出适当的分支即可。
我尝试使用单独的工作树创建裸存储库,就像我对开发服务器所做的那样(请参阅帖子开头的链接),并且简单地做了:
git push staging develop
git push production master
这里分别是遥控器:
$ git remote show staging
* remote staging
Fetch URL: ssh://user@host/var/git/dev/staging.git
Push URL: ssh://user@host/var/git/dev/staging.git
HEAD branch: develop
Remote branch:
develop tracked
Local ref configured for 'git push':
develop pushes to develop (up to date)
$ git remote show production
* remote produdction
Fetch URL: ssh://user@host/var/git/dev/production.git
Push URL: ssh://user@host/var/git/dev/production.git
HEAD branch: master
Remote branch:
master tracked
Local ref configured for 'git push':
master pushes to master (up to date)
所以,理论上,我们可以使用 git-内部流动,跟踪开发分支并推送给其他部门查看/QA。然后我们可以在内部进行发布,并将更改推送到暂存区,然后简单地将主分支推送到生产环境。
我想我的问题是——我的处理方式正确吗?当谈到 git 和 git-flow 时,我是一个真正的新手。我仔细研究了所有可用的资源,这是迄今为止我能想到的最好的资源。
对于在多阶段部署中使用 git-flow 的人们的任何见解,我们将不胜感激。
Drawing a blank with finalizing my deploy scheme here. After posting this question: Migrating a production site with no VCS at all to Git, I've got the gist of deploying to a local repo down.
My local development server has a git-flow repository on it that I can push to and it will update an external worktree.
I have my repo set up with git-flow and here's what my origin remote looks like:
$ git remote show origin
* remote origin
Fetch URL: ssh://user@host/var/git/dev/repo.git
Push URL: ssh://user@host/var/git/dev/repo.git
HEAD branch (remote HEAD is ambiguous, may be one of the following):
develop
master
Remote branches:
develop tracked
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local refs configured for 'git push':
develop pushes to develop (up to date)
master pushes to master (up to date)
What I attempted to do, was set up 2 pseudo-environments. One for staging and one for production. I want to have them behave as follows:
git push staging #pushes to remote staging repo with a post-receive hook "git checkout develop -f"
git push production #pushes to remote production repo with a post-receive hook "git checkout master -f"
This way, we can develop locally and push to our little internal development server and have all the history. Then when we're clear for staging/production, we just push out the appropriate branches.
I tried creating bare repos with separate work trees like I did with the development server (see my link at the beginning of the post), and simply did:
git push staging develop
git push production master
And here are the remotes, respectively:
$ git remote show staging
* remote staging
Fetch URL: ssh://user@host/var/git/dev/staging.git
Push URL: ssh://user@host/var/git/dev/staging.git
HEAD branch: develop
Remote branch:
develop tracked
Local ref configured for 'git push':
develop pushes to develop (up to date)
$ git remote show production
* remote produdction
Fetch URL: ssh://user@host/var/git/dev/production.git
Push URL: ssh://user@host/var/git/dev/production.git
HEAD branch: master
Remote branch:
master tracked
Local ref configured for 'git push':
master pushes to master (up to date)
So, in theory, we can use git-flow internally, track the develop branch and push it out for other departments to view/QA. Then we can do our releasing internally, and push the changes to staging and then simply push the master branch to production.
I guess my question is - am I going about this the right way? I am a real novice when it comes to git and git-flow. I've pored over all the resources available and this is the best I could come up with so far.
Any insights from folks who are using git-flow in multi-stage deployment would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我最终所做的,这与我上面提出的建议略有不同,源于我在这里发布的另一个问题: 部署 git 分支
一个 post-receive 钩子来统治它们。#
Post receive 钩子查看 refname:
If the refname = “refs/heads/master”(推送到 master 分支):
然后我使用 git 附带的 post-receive-email 钩子发送一封关于提交的漂亮的小电子邮件。目前正在为我们的问题跟踪器开发一个 API,以便我们可以通过提交等来关闭问题。
当 refname =“ref/heads/develop”(推动开发)时也会发生同样的情况:
奖励积分
3 个分支 - 生产、开发(暂存)和小型项目的问题跟踪器分支。但有时,我们有较大的项目需要长期开发,并且不能妨碍日常开发。
您可以修改 post-receive 挂钩来查找 refs/heads/(.*?),如果您执行类似 git push -u mad-experimental-long-term-branch 之类的操作,该挂钩就会触发,
这让我们可以创建一个长期项目分支,使用 -u 推送它,并通过一些简单的脚本在crazy-experimental-long-term-branch.site.com 自动设置一个子域。
日常开发发生,问题解决滚动并获得批准(每周计划合并到生产),并且可以在准备好时合并疯狂的实验性长期分支。
我确信我的这种部署策略冒犯了 Git 诸神的敏感度,但是我们已经用这种方法成功部署了一个大型应用程序大约 5 个月了,除了偶尔的合并冲突之外,还没有发生任何问题。问题。
希望这有帮助。
Here's what I ended up doing, this is a slight variation of what I proposed above and stems from another question I posted here: Deploy git branches
One post-receive hook to rule them all.#
Post receive hook looks at the refname:
If the refname = "refs/heads/master" (pushing to master branch):
Then I use the post-receive-email hook that came with git to send a nice little email about the commit. Currently developing an API for our issue tracker so that we can close issues with commits etc.
The same happens when refname = "ref/heads/develop" (pushing to develop):
Bonus Points
3 branches - production, develop (staging), and an issue tracker branch for small-ish projects. Sometimes though, we have larger projects that require long-term dev and can't get in the way of day to day dev.
You can modify the post-receive hook to look for refs/heads/(.*?), which would fire if you did something like git push -u crazy-experimental-long-term-branch
This lets us create a long term project branch, push it up with -u, and have a subdomain automatically set up at crazy-experimental-long-term-branch.site.com with some simple scripting.
Day to day dev occurs, issue resolution rolls and gets greenlit (with weekly scheduled merges to production), and crazy experimental long term branches can be merged in when ready.
I'm sure I am offending the sensibilities of the Git Gods with this deployment strategy, but we've been successfully deploying a large-scale application with this method for about 5 months and aside from the occasional merge conflict, haven't had any issues.
Hope this is helpful.
如果您只想部署主服务器,可以使用以下代码片段:
If you only want to deploy the master, you can use following snippet: