5

I have setup my plesk website to automatically pull changes from a remote repository to a certain path of the webserver via post-hooks as described here.

However my repository contains a git submodule and I need to run the custom command git submodule update --remote as well. How can I tell plesk to do that. The commands I can enter in the

Enable Additional Deployment Actions

Setting seem not to be executed in the correct path. Also when I go to the path the repository syncs to on my server i get:

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

How can I achive to tell plesk to update submodules too with the git plugin?

niklas
  • 2,887
  • 3
  • 38
  • 70
  • Seems that the same question has been asked here: https://talk.plesk.com/threads/git-deployment-with-submodules-and-error-handling.340329/ – niklas Nov 11 '18 at 23:20

4 Answers4

6

In my case it was two problems. It was a setting for a subdomain, where the folderstructure is different in plesk.

First I had to set the "Additional Deployment Action" to

# 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

The second problem was that the submodule was placed on github, so I had to add the specific subdomain ssh-key to github. It can be found in.

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

even for the subdomain. Hope that helps someone else.

niklas
  • 2,887
  • 3
  • 38
  • 70
  • 2
    So setting git-dir/git_work-tree was part of the solution. +1 – VonC Nov 12 '18 at 13:55
  • 1
    For background these are 2 different directories since Plesk uses a bare repository for git in $HOME/git/{site} which is separate to where the files are cloned to (usually $HOME/{site} for subdomains – Kian Nov 11 '19 at 01:49
2

Check if you are in the right folder (as I show here)

Then check your environment variables (seen here): GIT_DIR or GIT_WORK_TREE, as set by Plex, to make sure they are not interfering.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

For me Niklas answer did not work unless I did a cd into the worktree directory. You can add this to the git command itself (using -C). Also I have added a sync command, in case the submodules origin changes:

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

I want to also note, that using variables did not work for me, I had to use absolute path for both commands.

Note: My hoster is netcup.com, maybe that is a specific issue on their side, but I guess it is relevant for all plesk installations.

NicoHood
  • 687
  • 5
  • 12
  • Strange: `-C` (that I [documented here](https://stackoverflow.com/a/20115526/6309) in 2013 with Git 1.8.5) is precisely a shortcut to set `--git-dir` and `--work-tree`. I don't know how that would help in your case. – VonC Oct 31 '20 at 14:08
  • If I dont use `-C` I get the following error: https://stackoverflow.com/q/48767595/14348748 – NicoHood Oct 31 '20 at 18:30
0

Although it's been a while here my two cents. I'm glad the given answers where pointing me in the right direction, however I still had to struggle with this quite some time.

Here is my summary:

Using submodules in Plesk

  • repos to be integrated as submodules must not be privat
  • Don't ssh ! To integrate an external repo we must use https protocol: git submodule add https://github.com/example.repo.git - see https://github.com/docker-library/golang/issues/148
  • the ${HOME} user (see code below) is used to authorize against github, so his key pair needs to be generated and the public key must be stored at Github
  • ssh into your account using the ${HOME} users name and password. In Plesk the ${HOME} user is the owner of the subscription domain.com or sub.domain.com belongs to.
  • to generate a key pair do:
ssh-keygen -t rsa

  • key pairs are automatically stored under the users home directory: ${HOME}/.ssh/id_rsa and ${HOME}/.ssh/id_rsa.pub
  • copy the generated public key over to Github

Usage

(under "Additional deployment actions")

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)"

or the short way

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)"

Explanation: we must use --git-dir and --work-tree here because of Plesks folder structure. Normally .git files are located within the main repository folder. Here these files are in its own git folder:

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