wiki/HowtoGitlab/8.14.md

455 lines
12 KiB
Markdown
Raw Normal View History

2016-11-24 16:51:15 +01:00
---
2016-11-30 20:45:58 +01:00
categories: web git
2016-11-24 16:51:15 +01:00
title: Howto GitLab
...
2016-11-30 20:45:58 +01:00
* Documentation : <https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md>
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
[GitLab](https://about.gitlab.com/) est un logiciel libre de gestion de développement de logiciels (appelé souvent une *forge*) permettant de créer des projets avec un dépôt Git pour le code source, la demande de fusion (*merge/pull requests*), un outil de tickets, un wiki, etc. GitLab ressemble sous certains aspects au logiciel propriétaire Github.
2016-11-24 16:51:15 +01:00
2016-11-30 20:45:58 +01:00
# Installation
2016-12-01 03:54:08 +01:00
Nous installons la version **8.14.X** sous **Debian 8** (Jessie) avec une approche multi-instances.
2016-11-30 20:45:58 +01:00
2016-12-01 03:54:08 +01:00
GitLab s'appuye sur Git, Ruby, Go, PostgreSQL et Redis.
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
> **Note** : dans les exemples ci-dessous, on va créer une instance nommée *foo*
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
## Dépendances
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
GitLab nécessite des version très récentes de Git, Ruby et Go.
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
On utilise pour l'instant des versions de Jessie Backports et Stretch via un « pinning » APT :
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
~~~
2016-11-24 16:51:15 +01:00
Package: *
Pin: release n=jessie-backports
2016-12-01 03:54:08 +01:00
Pin-Priority: 50
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
Package: *
2016-11-24 16:51:15 +01:00
Pin: release n=stretch
2016-12-01 03:54:08 +01:00
Pin-Priority: 50
2016-11-24 16:51:15 +01:00
Package: golang golang-doc golang-src golang-go
Pin: release n=jessie-backports
Pin-Priority: 999
2016-12-01 03:54:08 +01:00
Package: git git-man ruby ruby2.3 ruby-dev ruby2.3-dev libruby2.3 rake ruby-test-unit libncurses5 libreadline7 libtinfo5 libncursesw5 libncurses5-dev libtinfo-dev ncurses-bin
Pin: release n=stretch
Pin-Priority: 999
2016-11-30 20:45:58 +01:00
~~~
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
On peut ainsi installer toutes les dépendances pour Gitlab :
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
~~~
# apt install build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev \
libffi-dev curl openssh-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate \
python-docutils pkg-config cmake nodejs bundler ruby2.3 git golang
~~~
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
## Compte UNIX
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
Créer un compte UNIX *foo* :
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
~~~
# adduser --disabled-login --gecos 'GitLab instance foo' foo
~~~
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
> **Note** : Assurez-vous d'avoir `DIR_MODE=0755` dans `/etc/adduser.conf` (nécessaire pour Nginx)
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
## PostgreSQL
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
GitLab recommande [PostgreSQL](HowtoPostgreSQL). On utilise donc la version 9.4 de Debian Jessie :
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
~~~
2016-11-24 16:51:15 +01:00
# apt install postgresql postgresql-client libpq-dev postgresql-contrib
2016-12-01 03:54:08 +01:00
~~~
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
Création de l'utilisateur PostgreSQL :
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
~~~
# sudo -u postgres createuser foo -P -D -A -R
# sudo -u postgres psql -d template1 -c 'ALTER ROLE "foo" CREATEDB;'
~~~
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
> **Note** : On donne les droits CREATEDB car GitLab doit faire un DROP DATABASE puis CREATE DATABASE lors de l'installation…
2016-11-24 16:51:15 +01:00
> **Note** : Pensez à conserver le mot de passe pour le mettre par la suite dans la configuration GitLab.
Création de l'extension `pg_trgm` :
2016-12-01 03:54:08 +01:00
~~~
2016-11-24 16:51:15 +01:00
# sudo -u postgres psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
2016-12-01 03:54:08 +01:00
~~~
2016-11-24 16:51:15 +01:00
Création de la base pour GitLab :
2016-12-01 03:54:08 +01:00
~~~
# sudo -u postgres createdb -O foo -E UNICODE foo
~~~
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
Tester la connexion et si l'extension `pg_trgm` est bien activée :
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
~~~
# sudo -u foo -H psql --password -d foo
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
psql> SELECT true AS enabled FROM pg_available_extensions
WHERE name = 'pg_trgm' AND installed_version IS NOT NULL;
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
enabled
---------
t
(1 row)
~~~
2016-11-24 16:51:15 +01:00
## Redis
2016-12-01 03:54:08 +01:00
On utilise une instance Redis dédiée à chaque instance GitLab :
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
~~~
# apt install redis-server
2016-11-24 16:51:15 +01:00
# systemctl stop redis-server
# systemctl disable redis-server
2016-12-01 03:54:08 +01:00
~~~
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
Créer et activer le template d'unité systemd `/etc/systemd/system/redis@.service` :
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
~~~
2016-11-24 16:51:15 +01:00
[Unit]
Description=Advanced key-value store instance %i
After=network.target
[Service]
Type=forking
ExecStart=/usr/bin/redis-server /etc/redis/%i.conf
ExecStartPost=/bin/chgrp %i /var/run/redis/%i.sock
ExecStop=/usr/bin/redis-cli shutdown
Restart=always
User=redis
Group=%i
[Install]
WantedBy=multi-user.target
2016-12-01 03:54:08 +01:00
~~~
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
Puis :
~~~
# systemctl daemon-reload
~~~
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
Créer une configuration spéciale pour l'instance :
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
~~~
# cat /etc/redis/gitlab-demo00.conf
2016-11-24 16:51:15 +01:00
daemonize yes
2016-12-01 03:54:08 +01:00
pidfile /var/run/redis/foo.pid
2016-11-24 16:51:15 +01:00
port 0
2016-12-01 03:54:08 +01:00
unixsocket /var/run/redis/foo.sock
2016-11-24 16:51:15 +01:00
unixsocketperm 770
timeout 0
loglevel notice
2016-12-01 03:54:08 +01:00
logfile /var/log/redis/foo.log
2016-11-24 16:51:15 +01:00
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
2016-12-01 03:54:08 +01:00
dbfilename foo.rdb
2016-11-24 16:51:15 +01:00
dir /var/lib/redis
2016-12-01 03:54:08 +01:00
# chmod 644 /etc/redis/foo.conf
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
# systemctl enable redis@foo
# systemctl start redis@foo
~~~
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
## GitLag CE
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
~~~
# sudo -iu foo
2016-11-24 16:51:15 +01:00
$ umask 002
$ git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 8-14-stable gitlab
$ cd gitlab
2016-12-01 03:54:08 +01:00
$ cp config/gitlab.yml.example config/gitlab.yml
$ sed -i 's@/home/git@/home/foo@g' config/gitlab.yml
~~~
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
Éditer `config/gitlab.yml` :
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
~~~
host: foo.gitlab.example.com
2016-11-24 16:51:15 +01:00
port: 443
https: true
2016-12-01 03:54:08 +01:00
user: foo
email_from: gitlab@example.com
email_display_name: GitLab foo
email_reply_to: gitlab@example.com
~~~
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
~~~
$ cp config/secrets.yml.example config/secrets.yml
$ sed -i "s@^# db_key_base:@db_key_base: PASSWORD@" config/secrets.yml
$ chmod 600 config/secrets.yml
~~~
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
~~~
2016-11-24 16:51:15 +01:00
$ chmod -R u+rwX,go-w log/
$ chmod -R u+rwX tmp/
$ chmod -R u+rwX tmp/pids/
$ chmod -R u+rwX tmp/sockets/
$ install -d -m 700 public/uploads/
$ chmod -R u+rwX builds/
$ chmod -R u+rwX shared/artifacts/
2016-12-01 03:54:08 +01:00
~~~
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
## Unicorn
~~~
$ cp config/unicorn.rb.example config/unicorn.rb
$ sed -i -e \
2016-11-24 16:51:15 +01:00
-e 's#/home/git#/home/gitlab-demo00#g' \
-e 's/listen "127.0.0.1:8080", :tcp_nopush => true/#listen "127.0.0.1:8080", :tcp_nopush => true/' \
config/unicorn.rb
2016-12-01 03:54:08 +01:00
~~~
2016-11-24 16:51:15 +01:00
2016-12-01 03:54:08 +01:00
## Configuration de Rack attack
2016-11-24 16:51:15 +01:00
```
$ cp config/initializers/rack_attack.rb{.example,}
```
### Configuration de GIT
```
$ git config --global core.autocrlf input
$ git config --global gc.auto 0
$ git config --global repack.writeBitmaps true
```
### Configuration de Resque/Redis
```
$ cp config/resque.yml{.example,}
$ sed -i 's/redis.sock/gitlab-demo00.sock/' config/resque.yml
```
### Configuration des paramètres de connexion à la base
```
$ cp config/database.yml{.postgresql,}
$ sed -i -e 's/database: gitlabhq_production/database: gitlab-demo00/' \
-e 's/# username: git/username: gitlab-demo00/' \
-e 's/# password:/password: VotreMDP/' config/database.yml
$ chmod o-rwx config/database.yml
```
> **Note** : Conservez l'espace devant le sed pour ne pas enregistrer le mot de passe dans l'historique bash.
### Installation des Gems
> **Important**: Votre `/home` ne doit pas être monté avec l'option `noexec`.
```
$ bundle install -j$(nproc) --deployment --without development test mysql aws kerberos
```
### Installation de GitLab Shell
```
$ bundle exec rake gitlab:shell:install REDIS_URL=unix:/var/run/redis/gitlab-demo00.sock RAILS_ENV=production SKIP_STORAGE_VALIDATION=true
$ chmod -R ug+rwX,o-rwx ~/repositories/
$ chmod -R ug-s ~/repositories/
$ chmod g+s ~/repositories/
```
### Install gitlab-workhorse
```
$ cd
$ git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git
$ cd gitlab-workhorse
$ git checkout v$(cat ~/gitlab/GITLAB_WORKHORSE_VERSION)
$ make
```
### Création de la BDD
```
$ cd ~/gitlab
$ bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword GITLAB_ROOT_EMAIL=youremail
```
> **Note :** `GITLAB_ROOT_PASSWORD` concerne le mot de passe de l'utilisateur admin nommé root sur l'interface web de GitLab et `GITLAB_ROOT_EMAIL` le mail associé. Conservez un espace avant la commande pour qu'elle ne se retrouve pas dans l'historique bash.
### Sauvegarder secrets.yml
Le fichier `secrets.yml` contient les clés de chiffrements pour les sessions et les variables. On pourra le copier dans `/root` par exemple, à vous de choisir l'endroit approprié.
```
# install -m 600 -o root -g root /home/gitlab-demo00/gitlab/config/secrets.yml /root/gitlab-demo00.secrets.yml
```
### Mise en place d'un script d'init
GitLab ne supporte pas officiellement systemd… On doit donc encore passer pas un script d'init classique.
```
# sed -i -e \
's/app_user="git"/app_user="gitlab-demo00"/' \
-e 's/# Provides: .*gitlab/# Provides: gitlab-demo00/' \
/home/gitlab-demo00/gitlab/lib/support/init.d/gitlab
# install -m 755 /home/gitlab-demo00/gitlab/lib/support/init.d/gitlab /etc/init.d/gitlab-demo00
# systemctl enable gitlab-demo00
# sed -i 's#script_path = "/etc/init.d/gitlab"#script_path = "/etc/init.d/gitlab-demo00"#g' /home/gitlab-demo00/gitlab/lib/tasks/gitlab/check.rake
# sudo -iu gitlab-demo00
$ cd gitlab
$ git commit -a -m 'change default user'
```
### Logrotate
```
# install -m 644 /home/gitlab-demo00/gitlab/lib/support/logrotate/gitlab /etc/logrotate.d/gitlab-demo00
# sed -i 's#/home/git/#/home/gitlab-demo00/#g' /etc/logrotate.d/gitlab-demo00
```
### Vérifier l'état de l'installation
```
# sudo -iu gitlab-demo00
$ cd gitlab
$ bundle exec rake gitlab:env:info RAILS_ENV=production
```
### Compiler les Assets
```
$ bundle exec rake assets:precompile RAILS_ENV=production
```
### Démarrer l'instance
```
# /etc/init.d/gitlab-demo00 start
```
## Nginx
On utilise Nginx car c'est le seul serveur web supporté officiellement par GitLab.
> **Note** : La partie SSL/TLS n'est pas évoqué. À vous de faire le nécessaire avec un certificat let's encrypt par exemple. N'oubliez donc pas de modifier les directives ssl_ dans le vhost.
### Création du vhost
```
# install -m 644 /home/gitlab-demo00/gitlab/lib/support/nginx/gitlab-ssl /etc/nginx/sites-available/gitlab-demo00
# sed -i -e 's#/home/git/#/home/gitlab-demo00/#g' \
-e 's/YOUR_SERVER_FQDN/demo00.gitlab.example.com/g' \
-e 's#/var/log/nginx/gitlab#/var/log/nginx/gitlab-demo00#g' \
-e 's/upstream gitlab-workhorse/upstream gitlab-demoOO-workhorse/' \
-e 's#http://gitlab-workhorse#http://gitlab-demo00-workhorse#' \
/etc/nginx/sites-available/gitlab-demo00
# ln -s /etc/nginx/sites-available/gitlab-demo00 /etc/nginx/sites-enabled/
# /etc/init.d/nginx restart
```
## Terminé !
### Vérifier le status
```
# sudo -iu gitlab-demo00
$ cd gitlab
$ bundle exec rake gitlab:check RAILS_ENV=production
```
Si tout est au vert, c'est bon ! On pourra aller sur l'instance via https://demo00.gitlab.example.com
# Mise à jour
Le principe des mises à jour est basé sur un `git pull` et un `git checkout`.
## Mineure 8.14.0 vers 8.14.1
2016-11-24 16:51:15 +01:00
### Backup
```
# sudo -iu gitlab-demo00
$ cd gitlab
$ bundle exec rake gitlab:backup:create RAILS_ENV=production
```
### Mise à jour de GitLab
```
# sudo -iu gitlab-demo00
$ cd gitlab
$ git fetch --all
$ git checkout -- Gemfile.lock db/schema.rb
$ git checkout v8.14.1 -b v8.14.1
$ sed -i -e s'/app_user="git"/app_user="gitlab-demo00"/' \
2016-11-29 14:43:17 +01:00
-e 's/# Provides: .*gitlab$/# Provides: gitlab-demo00/' \
lib/support/init.d/gitlab
$ sed -i 's#script_path = "/etc/init.d/gitlab"#script_path = "/etc/init.d/gitlab-demo00"#g' lib/tasks/gitlab/check.rake
$ git commit -a -m 'change default user'
```
### Mise à jour BDD, gems et assets
```
$ cd ~/gitlab
$ bundle install --without development test mysql aws kerberos --deployment
$ bundle clean
$ bundle exec rake db:migrate RAILS_ENV=production
$ bundle exec rake assets:clean assets:precompile cache:clear RAILS_ENV=production
$ git commit -a -m 'upgraded to 8.14.1'
```
### Démarrer GitLab
```
# /etc/init.d/gitlab-demo00 restart
```
### Vérifier le status
```
# sudo -iu gitlab-demo00
$ cd gitlab
$ bundle exec rake gitlab:env:info RAILS_ENV=production
$ bundle exec rake gitlab:check RAILS_ENV=production
```
Si tout est au vert, la migration s'est bien passé !
2016-11-24 16:51:15 +01:00
## Majeure
En attente nouvelle release majeure.
# Création d'une autre instance
2016-11-25 10:26:56 +01:00
Il suffit de rejouer la procédure en modifiant « gitlab-demo00 » par le nom d'instance souhaitée.
# Backup
## Cron
```
# crontab -u gitlab-demo00 -e
```
```
# Create a full backup of the GitLab repositories and SQL database every day at 4am
0 4 * * * cd /home/gitlab-demo00/gitlab && bundle exec rake gitlab:backup:create RAILS_ENV=production CRON=1
```
Dans `~/gitlab/config/gitlab.yml` on pourra indiquer un temps de rétention. Par exemple pour garder 5j de backups :
```
keep_time: 432000
```
> **Note** : Par défaut, les backups sont dans ~/gitlab/tmp/backups. Il est conseillé de les sauvegarder ailleurs et sur une machine distante.