如何在推送时自动部署我的git repo的子模块?

Mur*_*ith 9 git deployment redhat openshift

我有一个正常运行的PHP盒式磁带,除了我无法找到一种直接的方法来获取OpenShift(递归地)推送我的git子模块的文件在推送我的核心repo文件时/之后.

这似乎应该是一个超级简单和常见的用例.我忽略了什么吗?

我可以ssh进入我的服务器并手动拉它们,但我想完全自动化,所以如果我在我的仓库中更新子模块的引用,这些更改将在我部署时反映出来.

小智 7

好吧,我会为此加点50分;)

以下是我遵循的步骤:

1.)在克隆到本地机器上的OpenShift上创建php-5.3应用程序.
2.)在github上创建公共git存储库以用作子模块.
3.)使用以下命令将github存储库添加到OpenShift应用程序,确保使用https url而不是git @ url,否则当OpenShift Online尝试签出子模块时,您将收到私钥问题.

 cd into your locally cloned openshift application directory  
 git submodule add https://github.com/developercorey/somesubmodule.git ./directory_name
 git add .
 git commit -am "adding a submodule"
 git push
Run Code Online (Sandbox Code Playgroud)

如果你在git push中没有看到任何错误,那么一切都应该正常工作.如果你看到这样的错误

remote: Host key verification failed.
remote: fatal: Could not read from remote repository.
remote: 
remote: Please make sure you have the correct access rights
remote: and the repository exists.
Run Code Online (Sandbox Code Playgroud)

这意味着您使用git @ url而不是https url来添加您的git子模块,或者您正在尝试访问私有存储库.现在,您可以使用rhc ssh命令ssh进入您的应用程序并进入〜/ app-root/runtime/repo目录,您应该看到子模块目录,其中包含该存储库中的文件.

如果这对您不起作用,请告诉我您的git push的输出是什么,我们将从那里开始.


Von*_*onC 6

对于父repo(包含子模块),您只需要推送父repo本身:它包括引用每个子模块的正确SHA1 的gitlink(索引中的特殊条目).

一旦推送,后接收挂钩可以触发:

git submodule update --init --recursive
Run Code Online (Sandbox Code Playgroud)

这会将每个子模块更新为正确的SHA1.

post-receive钩子在父母裸仓中:/path/to/parent.git/hooks/post-receivewith:

#! /bin/bash
cd /path/to/non-bare/parent
git --git-dir=/path/to/parent.git checkout 
git --git-dir=/path/to/parent.git submodule update --init --recursive
Run Code Online (Sandbox Code Playgroud)