Plesk 在 git 存储库更改时自动更新子模块

Plesk automatically update submodule on git repository change

我已将我的 plesk 网站设置为通过 post-hooks 自动将更改从远程存储库提取到网络服务器的特定路径,如 here.

所述

但是我的存储库包含一个 git 子模块,我还需要 运行 自定义命令 git submodule update --remote。我怎样才能告诉 plesk 这样做。我可以在

中输入的命令

Enable Additional Deployment Actions

设置似乎没有在正确的路径中执行。此外,当我转到存储库在我的服务器上同步到的路径时,我得到:

fatal: Not a git repository (or any of the parent directories): .git

我怎样才能让 plesk 也使用 git 插件更新子模块?

检查您是否在正确的文件夹中 ()

然后检查您的环境变量 (seen here):GIT_DIRGIT_WORK_TREE,由 Plex 设置,以确保它们没有干扰。

就我而言,这是两个问题。这是一个子域的设置,其中的文件夹结构在 plesk 中是不同的。

首先我必须将 "Additional Deployment Action" 设置为

# find the correct git folders / repositorys by ssh-ing onto your server
git --git-dir=/var/www/vhosts/example.com/git/example.git --work-tree=/var/www/vhosts/example.com/subdomain.example.com/path/to/working-directory/ submodule update --init --recursive

第二个问题是子模块放在github上,所以我不得不将特定的子域ssh-key添加到github。可以在.

/var/www/vhosts/example.com/.ssh/id_rsa.pub

即使对于子域。希望对其他人有所帮助。

对我来说,除非我将 cd 放入工作树目录,否则 Niklas 的回答不起作用。您可以将其添加到 git 命令本身(使用 -C)。我还添加了一个同步命令,以防子模块原点发生变化:

git --git-dir=/git/repo_name.git --work-tree=. -C /httpdocs/website submodule sync --recursive
git --git-dir=/git/repo_name.git --work-tree=. -C /httpdocs/website submodule update --init --recursive

我还想指出,使用变量对我不起作用,我不得不为这两个命令使用绝对路径。

注意:我的主机是 netcup.com,也许这是他们这边的一个特定问题,但我想它与所有 plesk 安装相关。

虽然我的两分钱已经有一段时间了。 我很高兴给出的答案为我指明了正确的方向,但是我仍然不得不为此苦苦挣扎一段时间。

这是我的总结:

在 Plesk 中使用子模块

  • 要集成为子模块的 repos 不能 是私有的
  • 不要ssh!要集成外部仓库,我们必须使用 https 协议:git submodule add https://github.com/example.repo.git - 参见 https://github.com/docker-library/golang/issues/148
  • ${HOME} 用户(参见下面的代码)用于针对 github 进行授权,因此需要生成 his 密钥对并且 public 密钥必须存储在 Github
  • ssh 使用 ${HOME} 用户名和密码进入您的帐户。在 Plesk 中,${HOME} 用户是 domain.comsub.domain.com 所属订阅的所有者。
  • 生成密钥对:
ssh-keygen -t rsa

  • 密钥对自动存储在用户主目录下:${HOME}/.ssh/id_rsa${HOME}/.ssh/id_rsa.pub
  • 复制生成的public键到Github

用法

(在“其他部署操作”下)

git --git-dir=${HOME}/git/example.repo.git --work-tree=. submodule update --init &> ~/logs/git/example.repo.log
git --git-dir=${HOME}/git/example.repo.git --work-tree=. checkout master &>> ~/logs/git/example.repo.log
git --git-dir=${HOME}/git/example.repo.git --work-tree=. pull origin master &>> ~/logs/git/example.repo.log
git --git-dir=${HOME}/git/example.repo.git --work-tree=. submodule update --init --recursive &>> ~/logs/git/example.repo.log

git commit -am "submodule updated $(date)"

或捷径

git --git-dir=${HOME}/git/example.repo.git --work-tree=. submodule foreach 'git submodule update --init;git checkout master;git pull origin master;git submodule update --init --recursive;' &> ~/logs/git/example.repo.log

git commit -am "submodule updated $(date)"

说明:由于 Plesks 文件夹结构,我们必须在此处使用 --git-dir--work-tree。通常 .git 文件位于主存储库文件夹中。这些文件位于其自己的 git 文件夹中:

 -- domain.com
    -- git
       -- example.repo.git
    -- sub.domain.com