【问题标题】:Plesk automatically update submodule on git repository changePlesk 在 git 存储库更改时自动更新子模块
【发布时间】:2018-11-11 23:18:20
【问题描述】:

我已将我的 plesk 网站设置为通过 here 所述的后挂钩自动将更改从远程存储库拉取到网络服务器的特定路径。

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

启用其他部署操作

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

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

如何使用 git 插件告诉 plesk 也更新子模块?

【问题讨论】:

标签: git git-submodules plesk


【解决方案1】:

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

首先我必须将“附加部署操作”设置为

# 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上,所以只好在github上添加具体的子域ssh-key。它可以在中找到。

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

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

【讨论】:

  • 所以设置 git-dir/git_work-tree 是解决方案的一部分。 +1
  • 对于后台,这是 2 个不同的目录,因为 Plesk 在 $HOME/git/{site} 中使用 git 的裸存储库,该存储库与文件克隆到的位置(通常是 $HOME/{site}对于子域
【解决方案2】:

检查您是否在正确的文件夹中 (as I show here)

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

【讨论】:

    【解决方案3】:

    对我来说 Niklas 的回答不起作用,除非我将 cd 放入工作树目录。您可以将其添加到 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 安装有关。

    【讨论】:

    【解决方案4】:

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

    这是我的总结:

    在 Plesk 中使用子模块

    • 要作为子模块集成的存储库不得是私有的
    • 不要ssh!要集成外部存储库,我们必须使用 https 协议:git submodule add https://github.com/example.repo.git - 请参阅 https://github.com/docker-library/golang/issues/148
    • ${HOME} 用户(参见下面的代码)用于对 github 进行授权,因此需要生成 他的密钥对,并且公钥必须存储在 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
    
    

    【讨论】:

      猜你喜欢
      • 2010-10-29
      • 1970-01-01
      • 2017-06-13
      • 1970-01-01
      • 2018-10-15
      • 2020-09-23
      • 2013-04-30
      • 2019-11-24
      • 1970-01-01
      相关资源
      最近更新 更多