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

时间:2014-09-05 23:36:33

标签: git deployment openshift redhat

我有一个正常运行的PHP盒式磁带,除了我无法找到一种简单的方法让OpenShift在递送我的核心repo文件时(递归地)推送我的git子模块的文件。

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

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

2 个答案:

答案 0 :(得分:7)

好的,我会为此加分50分;)

以下是我遵循的步骤:

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

 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

如果你在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.

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

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

答案 1 :(得分:6)

对于父级仓库(包含子模块),您只需要推送父仓库本身:它包含引用每个子模块的正确SHA1的gitlink (special entries in the index)

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

git submodule update --init --recursive

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

收件后挂钩位于父 bare repo /path/to/parent.git/hooks/post-receive中:

#! /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
相关问题