2017-09-26 7 views
0

Gurucomment puis-je faire git/crochets/travail de pré-réception pendant que nous utilisons HTTP comme protocole accès

Je viens de découvrir que les crochets git (pré-réception, après réception) ne peut pas être exécuté tout en faisant-git push via HTTP, cependant ces hooks peuvent être appelés en faisant git-push via SSH.
Est-ce vrai?
Alors, comment puis-je faire fonctionner git/hooks/pre-receive alors que nous utilisons HTTP comme protocole d'accès?

/// ------------------------------------------ -------------------------------------------------- ----

/// /// @SERVER Ceci est le code crochet post-recevoir

hello.git $ cat hooks/post-receive 
#!/bin/bash 
while read oldrev newrev ref 
do 
    if [[ $ref =~ .*/master$ ]]; 
    then 
     echo "Master ref received. Deploying master branch to production..." 
     #git --work-tree=/var/www/html --git-dir=/home/demo/proj checkout -f 
    else 
     echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server." 
    fi 
done 

/// ---------------- -------------------------------------------------- ------------------------------
/// @ CLIENT
/// Ici git/hooks/post-receive fonctionne tout en poussant git via SSH.

$ git push 
[email protected]'s password: 
Counting objects: 5, done. 
Delta compression using up to 8 threads. 
Compressing objects: 100% (3/3), done. 
Writing objects: 100% (5/5), 390 bytes | 390.00 KiB/s, done. 
Total 5 (delta 1), reused 0 (delta 0) 
remote: Master ref received. Deploying master branch to production... 
To hostxxx.net:/var/www/html/repo/hello.git 
    a308dbc..82184b8 master -> master 
+0

Quel serveur utilisez-vous pour basculer sur HTTP? – phd

+0

Nous installons un serveur pour notre entreprise qui se trouve sur Internet, et en raison de la limitation de sécurité dans le serveur proxy, nous devons utiliser le protocole HTTP/HTTPS au lieu de SSH. Alors pourriez-vous me donner des conseils s'il vous plaît? – zhengfish

+0

Oui, mais quel est exactement le serveur? Le serveur HTTP simple n'exécutera certainement pas de hook côté serveur, vous devez configurer [git-http-backend] (https://www.kernel.org/pub/software/scm/git/docs/git-http-backend. html). – phd

Répondre

0

Après le guide @phd, j'améliore ma conf de apache2 et maintenant cela fonctionne.

Voici la conf complète apache2 pour votre référence.

# @file /etc/apache2/conf-enabled/git_http_backend.conf 
# 
# @brief 
# This conf to enable git accessing via HTTP over apaches. 
# 
# Tested on Ubuntu-14.04.5 
# 
# a2enmod dav dav_fs env alias proxy rewrite proxy_http 
# 

SetEnv GIT_PROJECT_ROOT   /var/www/html 
SetEnv GIT_HTTP_EXPORT_ALL  1 
SetEnv REMOTE_USER    $REDIRECT_REMOTE_USER 

ScriptAliasMatch \ 
    "(?x)^/(.*/(HEAD | \ 
     info/refs | \ 
     objects/(info/[^/]+ | \ 
      [0-9a-f]{2}/[0-9a-f]{38} | \ 
      pack/pack-[0-9a-f]{40}\.(pack|idx)) | \ 
      git-(upload|receive)-pack))$" \ 
    "/usr/lib/git-core/git-http-backend/$1" 

<Directory "/usr/lib/git-core"> 
    Options +ExecCgi -MultiViews +SymLinksIfOwnerMatch 
    AllowOverride none 
    Order allow,deny 
    Allow from all 
    Require all granted 
</Directory> 


# disable anonymous accessing /repo/* 
<LocationMatch "^/repo/.*"> 
    AuthType Basic 
    AuthName "Git" 
    AuthUserFile /etc/apache2/users.htpasswd 
    Require valid-user 
    Order allow,deny 
</LocationMatch> 


## foobar.git 
<Location /repo/foobar.git> 
    Options +ExecCGI 
    AuthType Basic 
    DAV on 
    AuthName "Git" 
    AuthUserFile /etc/apache2/users.htpasswd 
    Require valid-user 

    Order allow,deny 
    Allow from all 
</Location> 

###END###