Friday 2 November 2012

Create a git server

Git

Create a git server

  1. apt-get install git
  2. adduser git
  3. Become the git user and add team's ssh keys to /home/git/.ssh/authorized_keys
  4. Change the git user's shell in /etc/passwd to /usr/bin/git-shell or to whichever path it is otherwise located
  5. mkdir /opt/git
  6. chown -Rv git.git /opt/git
  7. chmod -Rv g+ws /opt/git
  8. cd /opt/git
  9. mkdir myproject.git
  10. cd myproject.git
  11. git init --bare --shared
  12. See addition to /opt/git/myproject.git/config below
  13. mv /opt/git/myproject.git/hooks/post-update.sample /opt/git/myproject.git/hooks/post-update
  14. On your local computer do:
    1. mkdir ~/tmp
    2. cd ~/tmp
    3. git config --global user.name "Your Full Name"
    4. git config --global user.email your.name@abc.net
    5. git init
    6. git add .
    7. git commit -m 'initial commit'
    8. git remote add origin git@git.yourserver.com:/opt/git/myproject.git
    9. git push origin master
      1. NOTE: if you get an error that origin already exists, do "git remote rm origin" before push
  15. Debug the set up, this guide probably has a few mistakes
Add this to /opt/git/myproject.git/config
[http]
    receivepack = true

Add apache functionality

  1. apt-get install apache2
  2. addgroup www-data git
  3. a2enmod auth_basic
  4. a2enmod authnz_ldap
  5. Add virtual host definition below
  6. service apache2 restart
The virtual host file is something like this, but you need to fix the "XXXX" part, best luck:
<VirtualHost *:80>
 ServerName git.abc.net
 DocumentRoot /opt/git
 ErrorLog ${APACHE_LOG_DIR}/git_error.log
 CustomLog ${APACHE_LOG_DIR}/git_access.log combined
 
 SetEnv GIT_PROJECT_ROOT /opt/git
 SetEnv GIT_HTTP_EXPORT_ALL
 ScriptAlias / /usr/lib/git-core/git-http-backend/
 AliasMatch ^/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /opt/git/$1
 AliasMatch ^/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /opt/git/$1
 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
 <LocationMatch ".*">
  AuthType Basic
  AuthName "XXXX"
  AuthLDAPURL ldap://bananas:389/XXXX
  AuthBasicProvider ldap
  AuthLDAPBindDN "XXXX"
  AuthLDAPBindPassword XXXX
  require valid-user
 </LocationMatch>
</VirtualHost>

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Interview questions: 2020-12

Terraform provider vs provisioner Load balancing Network Load Balancer vs Application Load Balancer  Networking Layer 1 vs Layer 4 haproxy u...