Git -> Push Hook

Hallo,

ich habe die Option USE GIT VERSION CONTROL FOR WATO aktiviert, funktioniert auch wie erwartet.

Nun habe ich auf unserem Git-Server einen User angelegt und diesem einem SSH-Key zugewiesen, bei den Git-Repository auf dem Checkmk-Server den Server als Remote eingetragen und den SSH-Private-Key für den Site-User hinterlegt.

Wenn ich nun auf dem Checkmk-Server im Verzeichnis ~/etc/check_mk den Befehl git push origin master ausführe, überträgt er die Änderungen auch wie gewünscht an unseren Server.

So weit, so gut

Nun wollte ich einen post-commit hook erstellen, um nach einem Commit von Checkmk die Änderungen automatisch auf unseren Server zu pushen (wie hier … nur leider wird der Hook nicht ausgeführt, wenn ein Commit von Checkmk gemacht wird.

Mache ich händisch ein Commit pusht git den Commit gleich wie gewünscht auf den Server … hatte jemand schon mal das Problem?

Ich benutze kein Git an dieser Stelle, aber die Tage hatte jemand ein ähnliches Problem mit einer .gitignore, die nicht respektiert wurde. Wer weiß, mit welchen --force und ähnlichen Schaltern da commited wird…
Wenn alles nichts hilft, könntest Du von hinten einen gezielten Schuss durch die checkmk-Brust abfeuern und mit einer systemd.path Unit oder einem inotifywait-Prozess auf das .git-Verzeichnis gucken und bei Änderungen den push-Befehl erteilen. Nur so 'ne Idee.

Das habe ich mir auch schon gedacht, habe mir aber dann den Source-Code angesehen und es sieht aus als würde dort eh nur ein normales git commit --author xx -m BLA gemacht werden:

Ja wenn ich nicht draufkomme, warum es nicht funktioniert, werde ich es so machen

1 Like

Hi, you need these steps to make wato commit for remote git:
1)Wato -enable git feature
2)configure upstream(git configuration,init,push)
3)post hook
~/etc/check_mk/.git$ cat hooks/post-commit
#!/bin/sh
git push origin {branch}
Configured this for checkmk_v2.
Probably issue with ssh-key - by default commit is authored by checkmk user@host

Thanks, thats the steps I tried.

However I think I just got one step closer to the problem, committing with an different author (git commit --author "testadmin <testadmin >" -m "TEST") seems to cause an issue with the ssh-key:

git@xxxxx.at: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

In your first post you wrote you put the site user’s private key in the authorized_keys of the git server. Correct would be the public key. Or was that just a mistyping?

I meant that I copied the private key of the ssh-key-pair to the checkmk server and the public key to the git server.

However I just found the issue :smiley:
I first just add the private key to the ssh-agent (https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/error-permission-denied-publickey#make-sure-you-have-a-key-that-is-being-used) which stopped working… so I created the ~/.ssh/config and put the correct private key for the server in there (like here: https://superuser.com/a/232406)

And now it works :slight_smile:
Thanks @Dirk and @bohdan.udovenko!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact @fayepal if you think this should be re-opened.