Développement Git

Source: https://www.perhonen.fr/blog/2015/03/installer-gitlab-1254

Vous adorez Github et vous avez un projet top secret à développer. Vous avez la solution de prendre un abonnement Github à 7$/mois qui vous permet d’avoir 5 projets privés hébergés. Cette solution est la meilleure si vous ne souhaitez pas vous investir dans la gestion d’un serveur. Ici, nous vous parlerons de comment mettre en place votre propre serveur Gitlab pour moins de 7$/mois mais avec un peu plus de sueur et de travail.

Cet article traite de l’installation depuis les paquets communautaires. Si vous souhaitez installer Gitlab depuis les sources et pouvoir gérer l’ensemble de la configuration. Rendez vous sur l’article : Gitlab: Installation depuis les sources

Choix de l’emplacement

Vous pouvez installer GitLab, sur votre ordinateur en local, un serveur sur l’internet ou encore une machine virtuelle héberger sur un serveur sur l’internet. La procédure sera presque la même quelle que soit la destination. Mais je pense que c’est une bonne occasion pour louer un serveur virtuel privé au vu des prix actuels, pour information :

Minimum Recommandé

OVH 2€HT/mois 5€HT/mois
1and1 5€HT/mois 8€HT/mois
Oui, je vous l’ai fait façon pochette de jeux vidéo avec une version mini ou vous pouvez jouer mais avec des graphismes pourris et une version recommandée où vous pouvez jouer correctement.

Au niveau des recommandations concrètes, GitLab conseille de prendre 2 cores et 2 Go de RAM (bon c’est la recommandation pour 500 utilisateurs alors vu que je suis solo, j’ai pris le moins cher.

Donner une adresse à votre GitLab

Vous n’utiliserez pas l’adresse IP, qu’elle soit V4 ou V6, pour vous adresser à votre serveur. De plus, GitLab vous insultera lorsque vous terminerez sa configuration si vous n’avez pas de nom de domaine pleinement qualifié.

Si vous hébergez votre GitLab sur l’internet ou gérez vous-même votre DNS, il vous faudra ajouter une nouvelle entrée de type A sur votre DNS.

git.activpart.com. 70206 IN A 92.222.2.131

Cette adresse devra être utilisée dans la configuration de GitLab.

Pour les personnes souhaitant installer un GitLab sur un réseau local sans DNS. Vous pouvez spécifier dans le fichier hosts, de vos clients, qui se trouve dans /etc/hosts, le lien entre le nom et l’adresse IP de la machine. Cela vous évitera la mise en place d’un DNS qui n’est pas forcément utile dans les petites structures. Cependant, vous devrez spécifier le lien entre le nom de la machine et l’adresse IP sur chaque client (ce qui peut être rébarbatif). Exemple de fichier /etc/hosts :

 127.0.0.1 localhost
 127.0.0.1 client.perhonen.local client
 192.168.1.249 git.activpart.com

Vous trouverez ce même fichier sous Windows dans C:\Windows\system32\drivers\etc\.

Préparer votre machine virtuelle

Si vous avez pris votre machine virtuelle chez OVH ou chez un autre prestataire, vous devez déjà avoir le paquet openssh-server d’installé. Je passerais donc l’installation de celui-ci.

Pour la configuration du pare-feu, je vous laisse suivre l’article parlant de mes règles iptables. N’oubliez juste pas de dé-commenter la règles iptables permettant d’accéder à l’interface de GitLab.

$IPT -A INPUT -p tcp --dport 3550 -j ACCEPT

Votre serveur devra aussi pouvoir envoyer des mails vers vos utilisateurs Gitlab, nous installons donc le serveur mail postfix.

# apt-get install postfix

Sélectionner l’option Site Internet, puis entrer votre nom de domaine afin que les mails partant de votre serveur soient pleinement qualifiés.

Installer GitLab

Pour commencer, il vous faut télécharger le paquet communautaire correspondant à votre distribution sur le site GitLab. Pour ma part, je télécharge la version dédiée à Debian 7, la version actuellement proposée est la 7.8.1.

$ wget https://downloads-packages.s3.amazonaws.com/debian-7.8/gitlab_7.8.1-omnibus-1_amd64.deb
 # dpkg -i gitlab_7.8.1-omnibus-1_amd64.deb

Maintenant, nous allons demander à gitlab-ctl de configurer toute l’installation, c’est à dire rubis, unicorn, nginx, postgresql, redis et logrotate.

# gitlab-ctl reconfigure

L’installation est terminée, vous avez maintenant accès à votre GitLab perso à l’adresse http://gitlab.perhonen.fr:3550/. Les identifiants de connexion par défaut sont :

Utilisateur : root
Mot de passe : 5iveL!fe

Je vous conseille vivement de les modifier et de vous créer un utilisateur perso.

Problèmes rencontrés : FQDN unknown
Si lors de l’installation de Debian, vous n’avez pas pleinement qualifié le nom de domaine GitLab vous le rappellera avec l’erreur suivante :

# gitlab-ctl reconfigure
 ...
 RuntimeError
 ------------
 External URL must include a FQDN
 Un nom de domaine complètement qualifié comprend le nom de la machine (hostname) suivi du nom de domaine jusqu’à la racine. Par exemple, gitlab.perhonen.fr. est le nom de domaine pleinement qualifié de la machine gitlab du domaine perhonen.fr., le point final correspondant à la racine.

alors pour corriger cette erreur vous devez spécifier le nom de domaine que vous désirez attribuer à votre serveur GitLab comme cela :

# vi /etc/gitlab/gitlab.rb
 external_url='gitlab.perhonen.fr'

Ajouter dans votre PATH

/opt/gitlab/embedded/bin/git

Git global setup

Indiquez à Git qui vous êtes:

git config --global user.name "JF Rullier"
git config --global user.email "jf.rullier@activpart.com"

Créez les clés SSH (pour ne pas avoir à taper votre mot de passe à chaque « commit »

francou@srv1:/var/www/motoclic$ ssh-keygen -t rsa -C "jf.rullier@activpart.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/francou/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/francou/.ssh/id_rsa.
Your public key has been saved in /home/francou/.ssh/id_rsa.pub.
The key fingerprint is:
0f:a4:84:03:d4:6f:77:77:5c:fd:0f:42:7d:5a:56:a2 jf.rullier@activpart.com
The key's randomart image is:
+---[RSA 2048]----+
| .o. .. +|
| ... ....*|
| o.. . .E. *.|
| ooo. . o = .|
| ...S. . o ..|
| o .|
| . |
| |
| |
+-----------------+
francou@srv1:/var/www/motoclic$

Afficher le texte de la clé publique et le copier dans le presse papier

francou@srv1:/var/www/motoclic$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5PkpXIm3lAkCNhZUrqETFu/JRH1Wz31+fEPW0ySD/LZYicm1gVLxwBv3oX4n5j2r0QbVIgBm9Aq9q7+oluxSaCMIgwyQKrC1bUs36TX3NXejRVuTK4HWsPCG5OOXP4MKY+c0gZZpc3P3ALOHM3R40J3rIkBIw0SjPbifk+lbE+SgSqZJTlS+ssNaPcMdiZBUQOj3lgPBElohLAm/y6BijwVbH+lSX2Eczxer90piqpZMb9kWKaHMKQ14bWCs14pIn8vrGTftvGmb0GUiRE4iLP5upp76X5ZhCKUDl6M2diJ6vKX2KYrzCIerxEBoXQLiQmdSYqF46tSqQSZEuPboT jf.rullier@activpart.com
francou@srv1:/var/www/motoclic$

Puis sur l’interface, se connecter sous le user (ici « francou »), cliquer sur votre avatar en haut à droite, « Edit profil settings », « SSH Keys », entrez un titre (ex: Clé SSH de francou »,
puis collez le texte de la clé

it global setup
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
Create a new repository
mkdir motoclic
cd motoclic
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin git@gitlab.activpart.com:root/motoclic.git
git push -u origin master
Push an existing Git repository
cd existing_git_repo
git remote add origin git@gitlab.activpart.com:root/motoclic.git
git push -u origin master

Command line instructions

Git global setup
git config --global user.name "Jean-François Rullier"
git config --global user.email "jean-francois.rullier@supersonicimagine.com"
Create a new repository
git clone git@git.supersonicimagine.com:jfrullier/repogest.git
cd repogest
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Existing folder or Git repository
cd existing_folder
git init
git remote add origin git@git.supersonicimagine.com:jfrullier/repogest.git
git add .
git commit
git push -u origin master

Mise à jour des fichiers

git commit -m « Mise à jour 29 mars 2017 à midi »

git push -u origin master

En cas de problème

Si GitLab ne fonctionne pas, et que git-status indique que la base Postgresql est down, supprimer tous les dossiers Postgresql:
/opt/gitlab
/etc/gitlab
/var/opt/gitlab
et relancez l’installation

 

——————————–

Remplacer Nginx par Apache

I installed GitLab CE using the Omnibus package on a new CentOS 6 server. Since I had nothing else on the server at that time, everything GitLab setup and configured was sufficient. Later, however, I wanted to setup additional sites on the server using Apache, but now port 80 was already bound to by GitLab’s built-in Nginx web server.

What I really wanted to do is disable the built-in Nginx server and just use my self-managed Apache installation. Here’s how to do just that.

1. Arrêter les services GitLab

This will shutdown GitLab while we work on it.

$ gitlab-ctl stop
ok: down: logrotate: 0s, normally up
ok: down: postgresql: 1s, normally up
ok: down: redis: 0s, normally up
ok: down: nginx: 0s, normally up
ok: down: sidekiq: 0s, normally up
ok: down: unicorn: 0s, normally up

2. Désactiver le Nginx fourni

If you’re using GitLab out of the box, your GitLab configuration file should be located in /etc/gitlab. Go ahead and edit it.

vi /etc/gitlab/gitlab.rb

Scroll all the way down to the “GitLab Web Server” header. You can jump there by searching for “Web”: hit the forward slash on your keyboard (/), type in Web and hit ENTER.

Uncomment the web server username and group settings, and set both to Apache.

web_server['username'] = 'apache'
web_server['group'] = 'apache'

In the next section, “GitLab Nginx,” uncomment the first line and set it to false.

nginx['enable'] = false

3. Reconfigurer GitLab

This will parse your updated GitLab configuration file and disable Nginx.

$ gitlab-ctl reconfigure

4. Ajouter un virtualhost pour GitLab sous Apache

Create a new virtual host file for GitLab with the following directives (based on a GitLab recipe). Update git.domain.com to the domain you were using for GitLab.

<VirtualHost *:80>
  ServerName git.domain.com
  DocumentRoot /opt/gitlab/embedded/service/gitlab-rails/public
  
  ProxyPreserveHost On
  AllowEncodedSlashes Off
  
  <Location />
    Order deny,allow
    Allow from all
    ProxyPassReverse http://127.0.0.1:8080
    ProxyPassReverse http://git.domain.com/
  </Location>
  
  RewriteEngine on
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule .* http://127.0.0.1:8080%{REQUEST_URI} [P,QSA]
</VirtualHost>

I turned AllowEncodedSlashes off because I couldn’t find any URLs in GitLab that needed this, however, if you have issues with certain URLs not loading, try to set that directive to NoDecode.

AllowEncodedSlashes NoDecode

Note that your version of Apache would need to be 2.2.18 or later— NoDecode didn’t exist before that.

Restart or start Apache once the virtual host file is in place.

service httpd reload

5. Démarrer les services GitLab

Since we turned GitLab off earlier, let’s boot it back up.

$ gitlab-ctl start
ok: run: logrotate: (pid 22857) 0s
ok: run: postgresql: (pid 22860) 1s
ok: run: redis: (pid 22868) 0s
ok: run: sidekiq: (pid 22872) 1s
ok: run: unicorn: (pid 22876) 0s

Note that Nginx should not be listed anymore.

If there are other things you’re trying to figure out, I highly suggest GitLab’s README. It’s a great starting point and as tons of answers.

I hope this tutorial helped you get GitLab up and running with Apache. If you have any questions or issues, leave a comment and I’ll reply when I can.

Print Friendly, PDF & Email

Leave a Reply

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Blue Captcha Image
Refresh

*

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.