18
0
Fork 0

Changement de versions pour GitLab. On suit les majeures seulement.

This commit is contained in:
Benoît S. 2016-12-29 17:12:09 +01:00
parent 4edc7bb0f4
commit 027d652fbe
3 changed files with 492 additions and 1039 deletions

View File

@ -3,557 +3,4 @@ categories: web
title: Howto GitLab
...
Ce Howto concerne l'installation d'une version **8.13.X** sous **Debian 8** (Jessie). Il est basé sur la documentation officielle : <https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md>
Sa particularité est de décrire comment installer GitLab avec une approche multi-instances avec la création d'une instance nommée « demo00 ».
> **Note** : Vous pouvez bien entendu changer « demo00 » par le nom d'instance de votre choix.
> **Note** : Ce Howto est déprécié en faveur de la version [HowtoGitlab/8.14](8.14).
# Outils nécessaire
La brique de composants (stack) est composé de :
- GIT ;
- Ruby ;
- Go ;
- PostgreSQL ;
- Redis ;
# Installation
## Packages
GitLab a besoin d'une version récente de GIT, Ruby et Go. On utilisera les versions de Debian Stretch et Jessie Backports via un « pinning » apt.
```
Package: *
Pin: release n=stretch
Pin-Priority: 1
Package: *
Pin: release n=jessie-backports
Pin-Priority: 1
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
Package: golang golang-doc golang-src golang-go
Pin: release n=jessie-backports
Pin-Priority: 999
```
```
# 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
```
## Compte UNIX
Créer un compte UNIX « gitlab-demo00 ».
# adduser --disabled-login --gecos 'GitLab instance demo00' gitlab-demo00
> **Note** : Assurez-vous d'avoir `DIR_MODE=0755` dans `/etc/adduser.conf`. Cela sera nécessaire pour nginx.
## Base de données
GitLab recommande fortement PostgreSQL. On utilisera donc la version 9.4 de Debian Jessie.
Installation de PostgreSQL :
```
# apt install postgresql postgresql-client libpq-dev postgresql-contrib
```
> **Note** : Nous conseillons de désactiver le mode « peer » et d'utiliser des mots de passe.
Création de l'utilisateur :
```
# sudo -u postgres createuser gitlab-demo00 -P -D -A -R
# sudo -u postgres psql -d template1 -c 'ALTER ROLE "gitlab-demo00" CREATEDB;'
```
> **Note** : On lui donne les droits CREATEDB, car GitLab doit faire un DROP DATABASE, puis CREATE DATABASE lors de l'installation…
> **Note** : Pensez à conserver le mot de passe pour le mettre par la suite dans la configuration GitLab.
Création de l'extension `pg_trgm` :
```
# sudo -u postgres psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
```
Création de la base pour GitLab :
```
# sudo -u postgres createdb -O gitlab-demo00 -E UNICODE gitlab-demo00
```
Tester la connexion :
```
# sudo -u gitlab-demo00 -H psql --password -d gitlab-demo00
```
Tester si l'extension `pg_trgm` est bien activée :
```
SELECT true AS enabled
FROM pg_available_extensions
WHERE name = 'pg_trgm'
AND installed_version IS NOT NULL;
```
Cela doit retourner (« 1 row ») :
```
enabled
---------
t
(1 row)
```
## Redis
On utilisera redis en mode multi instances grâce à systemd et les templates d'unités.
# apt install redis-server
```
# systemctl stop redis-server
# systemctl disable redis-server
```
Créer et activer le template d'unité `/etc/systemd/system/redis@.service` :
```
[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
```
# systemctl daemon-reload
Créer une config spéciale pour l'instance :
```
# vim /etc/redis/gitlab-demo00.conf
daemonize yes
pidfile /var/run/redis/gitlab-demo00.pid
port 0
unixsocket /var/run/redis/gitlab-demo00.sock
unixsocketperm 770
timeout 0
loglevel notice
logfile /var/log/redis/gitlab-demo00.log
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename gitlab-demo00.rdb
dir /var/lib/redis
# chmod 644 /etc/redis/gitlab-demo00.conf
```
```
# systemctl enable redis@gitlab-demo00
# systemctl start redis@gitlab-demo00
```
## GitLab
### Configuration du cœur
```
# sudo -iu gitlab-demo00
$ umask 002
$ git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 8-13-stable gitlab
$ cd gitlab
$ cp config/gitlab.yml{.example,}
$ sed -i 's#/home/git#/home/gitlab-demo00#g' config/gitlab.yml
```
Éditer manuellement config/gitlab.yml sur cette base :
```
host: demo00.gitlab.example.com
port: 443
https: true
user: gitlab-demo00
email_from: demo00@gitlab.example.com
email_display_name: GitLab demo00
email_reply_to: demo00@gitlab.example.com
```
```
$ cp config/secrets.yml{.example,}
$ sed -i "s/# db_key_base:/db_key_base: $(apg -m30 -n1)/" config/secrets.yml
$ chmod 0600 config/secrets.yml
```
```
$ 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/
```
### Configuration Unicorn
```
$ cp config/unicorn.rb{.example,}
$ sed -i -e "s/worker_processes 3/worker_processes $(nproc)/" \
-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
```
### Configuration de Rack attack
```
$ 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
$ sed ca_file?
$ 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
```
TODO: Config mode multi instance ?
### 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.13.5 vers 8.13.6
### Backup
```
# sudo -iu gitlab-demo00
$ cd gitlab
$ bundle exec rake gitlab:backup:create RAILS_ENV=production
```
### Arrêt du service
```
# /etc/init.d/gitlab-demo00 stop
```
### Mise à jour de GitLab
```
# sudo -iu gitlab-demo00
$ cd gitlab
$ git fetch --all
$ git checkout -- Gemfile.lock db/schema.rb
$ git checkout v8.13.6 -b v8.13.6
$ sed -i -e s'/app_user="git"/app_user="gitlab-demo00"/' \
-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 de gitlab-shell
```
$ cd ~/gitlab-shell
$ git fetch
$ git checkout v$(cat ~/gitlab/GITLAB_SHELL_VERSION) -b v$(cat ~/gitlab/GITLAB_SHELL_VERSION)
```
### Mise à jour de gitlab-workhorse
```
$ cd ~/gitlab-workhorse
$ git fetch
$ git checkout v$(cat ~/gitlab/GITLAB_WORKHORSE_VERSION) -b v$(cat ~/gitlab/GITLAB_WORKHORSE_VERSION)
$ make
```
### 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
```
### Démarrer GitLab
```
# /etc/init.d/gitlab-demo00 start
# /etc/init.d/nginx 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é !
## Majeure 8.13 vers 8.14
Pour les mises à jour majeure, par exemple de 8.13 à 8.14, il y a une documentation officielle bien défini. Nous sommes évidement basé sur la documentation officielle.
[Liste des documentations d'upgrades majeure.](https://gitlab.com/gitlab-org/gitlab-ce/tree/master/doc/update)
> **Note** : Si nous n'avons pas encore écrit le howto de migration, il faudra bien penser à faire les adaptations nécessaires (chemin, nom d'utilisateur, …).
### Arrêt du service
```
# /etc/init.d/gitlab-demo00 stop
```
### Backup
```
# sudo -iu gitlab-demo00
$ cd gitlab
$ bundle exec rake gitlab:backup:create RAILS_ENV=production
```
### Mise à jour de GitLab
```
$ git fetch --all
$ git checkout -- db/schema.rb
$ git checkout 8-14-stable
$ sed -i -e s'/app_user="git"/app_user="gitlab-demo00"/' \
-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 de gitlab-shell
```
$ cd ~/gitlab-shell
$ git fetch --all --tags
$ git checkout v4.0.0
```
### Mise à jour de gitlab-workhrose
```
$ cd ~/gitlab-workhorse
$ git fetch --all
$ git checkout v1.0.0
$ make
```
### 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
```
### Mise à jour de la config
Il va falloir merger manuellement la configuration.
```
$ vimdiff <(git show origin/8-14-stable:config/gitlab.yml.example) config/gitlab.yml
$ git commit -a -m 'manually merged config file'
$ git config --global repack.writeBitmaps true
```
### Démarrer GitLab
```
# /etc/init.d/gitlab-demo00 start
# /etc/init.d/nginx 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é !
# Création d'une autre instance
Il suffit de rejouer la procédure en modifiant « gitlab-demo00 » par le nom d'instance souhaitée.
Voir [8]().

View File

@ -1,489 +1,6 @@
---
categories: web git
categories: web
title: Howto GitLab
...
* Documentation : <https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md>
[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, un outil de tickets, un wiki, une collaboration autour de Git (merge/pull requests, etc.). GitLab ressemble sous certains aspects au logiciel propriétaire *Github*.
# Installation
Nous installons la version **8.14.X** sous **Debian 8** (Jessie) avec une approche multi-instances.
GitLab s'appuie sur Git, Ruby, Go, PostgreSQL et Redis.
> **Note** : dans les exemples ci-dessous, on va créer une instance nommée *foo*
## Dépendances
GitLab nécessite des versions très récentes de Git, Ruby et Go.
On utilise pour l'instant des versions de Jessie Backports et Stretch via un « pinning » APT :
~~~
Package: *
Pin: release n=jessie-backports
Pin-Priority: 50
Package: *
Pin: release n=stretch
Pin-Priority: 50
Package: golang golang-doc golang-src golang-go
Pin: release n=jessie-backports
Pin-Priority: 999
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
~~~
On peut ainsi installer toutes les dépendances pour Gitlab :
~~~
# 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
~~~
## Compte UNIX
Créer un compte UNIX *foo* :
~~~
# adduser --disabled-login --gecos 'GitLab instance foo' foo
~~~
> **Note** : Assurez-vous d'avoir `DIR_MODE=0750` dans `/etc/adduser.conf` pour créer le home en 750.
## PostgreSQL
GitLab recommande [PostgreSQL](HowtoPostgreSQL). On utilise donc la version 9.4 de Debian Jessie :
~~~
# apt install postgresql postgresql-client libpq-dev postgresql-contrib
~~~
Création de l'utilisateur PostgreSQL :
~~~
# sudo -u postgres createuser foo -P -D -A -R
# sudo -u postgres psql -d template1 -c 'ALTER ROLE "foo" CREATEDB;'
~~~
> **Note** : On donne les droits CREATEDB car GitLab doit faire un DROP DATABASE puis CREATE DATABASE lors de l'installation…
> **Note** : Pensez à conserver le mot de passe pour le mettre par la suite pour [GitLab CE](#gitlab-ce).
Création de l'extension `pg_trgm` :
~~~
# sudo -u postgres psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
~~~
> **Note** : C'est à faire seulement la première fois.
Création de la base pour GitLab :
~~~
# sudo -u postgres createdb -O foo -E UNICODE foo
~~~
Tester la connexion et si l'extension `pg_trgm` est bien activée :
~~~
# sudo -u foo -H psql --password -d foo
psql> SELECT true AS enabled FROM pg_available_extensions
WHERE name = 'pg_trgm' AND installed_version IS NOT NULL;
enabled
---------
t
(1 row)
~~~
## Redis
On utilise une instance Redis dédiée à chaque instance GitLab :
~~~
# apt install redis-server
# systemctl stop redis-server
# systemctl disable redis-server
~~~
Créer et activer le template d'unité systemd `/etc/systemd/system/redis@.service` :
~~~
[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
~~~
Puis :
~~~
# systemctl daemon-reload
~~~
Configuration spéciale pour l'instance :
~~~
# cat /etc/redis/foo.conf
daemonize yes
pidfile /var/run/redis/foo.pid
port 0
unixsocket /var/run/redis/foo.sock
unixsocketperm 770
timeout 0
loglevel notice
logfile /var/log/redis/foo.log
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename foo.rdb
dir /var/lib/redis
# chmod 644 /etc/redis/foo.conf
# systemctl enable redis@foo
# systemctl start redis@foo
~~~
## GitLab CE
~~~
# sudo -iu foo
$ umask 002
$ git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 8-14-stable gitlab
$ cd gitlab
$ cp config/gitlab.yml.example config/gitlab.yml
$ sed -i 's@/home/git@/home/foo@g' config/gitlab.yml
~~~
Éditer `config/gitlab.yml` :
~~~
host: foo.gitlab.example.com
port: 443
https: true
user: foo
email_from: gitlab@example.com
email_display_name: GitLab foo
email_reply_to: gitlab@example.com
~~~
Mettre une clé secrète pour le chiffrement en base.
~~~
$ cp config/secrets.yml.example config/secrets.yml
$ sed -i "s@^# db_key_base:@db_key_base: YOURSECRETKEY@" config/secrets.yml
$ chmod 600 config/secrets.yml
~~~
> **Note** : Il est conseillé de générer `YOURSECRETKEY` ainsi : `apg -m30 -n1`.
> **Note** : Il est conseillé de sauvegarder le fichier secrets.yml. Voir la section [sauvegarde](#sauvegarde).
Mettre le mot de passe PostgreSQL :
~~~
$ cp config/database.yml.postgresql config/database.yml
$ sed -i -e 's/database: gitlabhq_production/database: foo/' \
-e 's/# username: git/username: foo/' \
-e 's/# password:/password: PASSWORD/' 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.
Ajuster les droits de certains répertoires :
~~~
$ chmod 750 ~
$ chmod -R u+rwX,go-w log/
$ chmod -R u+rwX tmp/
$ chmod -R u+rwX tmp/pids/
$ chmod -R u+rwX,g+rwX tmp/sockets/
$ install -d -m 700 public/uploads/
$ chmod -R u+rwX builds/
$ chmod -R u+rwX shared/artifacts/
~~~
## Unicorn
Configuration de base d'Unicorn :
~~~
$ cp config/unicorn.rb.example config/unicorn.rb
$ sed -i \
-e 's@/home/git@/home/foo@g' \
-e 's/listen "127.0.0.1:8080", :tcp_nopush => true/#listen "127.0.0.1:8080", :tcp_nopush => true/' \
config/unicorn.rb
~~~
## Rack attack
Initialisation de la configuration de Rack::Attack (qui permet du filtrage / rate-limiting) :
~~~
$ cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
~~~
## Git
Configuration :
~~~
$ git config --global core.autocrlf input
$ git config --global gc.auto 0
$ git config --global repack.writeBitmaps true
~~~
## Resque
Configuration :
~~~
$ cp config/resque.yml.example config/resque.yml
$ sed -i 's/redis.sock/foo.sock/' config/resque.yml
~~~
## Gems
> **Important**: Votre partition `/home` ne doit pas être montée avec l'option `noexec`.
On installe les Gems requise :
~~~
$ bundle install -j$(nproc) --deployment --without development test mysql aws kerberos
~~~
## GitLab Shell
Installation :
~~~
$ bundle exec rake gitlab:shell:install REDIS_URL=unix:/var/run/redis/foo.sock RAILS_ENV=production SKIP_STORAGE_VALIDATION=true
$ chmod -R ug+rwX,o-rwx ~/repositories/
$ chmod -R ug-s ~/repositories/
$ chmod g+s ~/repositories/
~~~
## gitlab-workhorse
Installation :
~~~
$ cd
$ git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git
$ cd gitlab-workhorse
$ git checkout v$(cat ~/gitlab/GITLAB_WORKHORSE_VERSION)
$ make
~~~
## Base de données
On crée la base de données avec l'identifiant (une adresse email) et un mot de passe pour l'utilisateur *root* sur l'interface web de GitLab :
~~~
$ cd ~/gitlab
$ bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword GITLAB_ROOT_EMAIL=admingitlab@example.com
~~~
> **Note** : Conservez l'espace devant le `bundle` pour ne pas enregistrer le mot de passe dans l'historique BASH.
## Script d'init
Attention, 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="foo"/' \
-e 's/# Provides: .*gitlab/# Provides: gitlab-foo/' \
lib/support/init.d/gitlab
$ sed -i 's@script_path = "/etc/init.d/gitlab"@script_path = "/etc/init.d/gitlab-foo"@g' lib/tasks/gitlab/check.rake
$ git commit -a -m 'change default user'
# install -m 755 /home/foo/gitlab/lib/support/init.d/gitlab /etc/init.d/gitlab-foo
# systemctl enable gitlab-foo
~~~
## Logrotate
~~~
# install -m 644 /home/foo/gitlab/lib/support/logrotate/gitlab /etc/logrotate.d/gitlab-foo
# sed -i 's@/home/git@/home/foo@g' /etc/logrotate.d/gitlab-foo
~~~
## Nginx
On utilise Nginx, c'est le seul serveur web supporté officiellement par GitLab :
~~~
# apt install nginx
# adduser www-data foo
# chmod -R g+rwX /home/foo/gitlab/tmp/{pids,sockets}
# install -m 644 /home/foo/gitlab/lib/support/nginx/gitlab-ssl /etc/nginx/sites-available/foo
# sed -i -e 's@/home/git@/home/foo@g' \
-e 's/YOUR_SERVER_FQDN/foo.gitlab.example.com/g' \
-e 's@/var/log/nginx/gitlab@/var/log/nginx/foo@g' \
-e 's/upstream gitlab-workhorse/upstream gitlab-foo-workhorse/' \
-e 's@http://gitlab-workhorse@http://gitlab-foo-workhorse@' \
/etc/nginx/sites-available/foo
# ln -s /etc/nginx/sites-available/foo /etc/nginx/sites-enabled/
# /etc/init.d/nginx restart
~~~
> **Note** : La partie SSL/TLS n'est pas évoquée. À 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.
> **Note** : `apt install nginx` est à faire seulement la première fois.
## Finalisation de l'installation
Vérification de l'état de l'installation :
~~~
# sudo -iu foo
$ cd gitlab
$ bundle exec rake gitlab:env:info RAILS_ENV=production
~~~
Compilation des assets :
~~~
$ bundle exec rake assets:precompile RAILS_ENV=production
~~~
Démarrage de l'instance :
~~~
# /etc/init.d/gitlab-foo start
~~~
Vérifier le statut :
~~~
# sudo -iu foo
$ 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 http://foo.gitlab.example.com
# Sauvegarde
On peut réaliser des sauvegardes grâce à la commande `bundle exec rake gitlab:backup:create RAILS_ENV=production`
On peut ainsi mettre un cron pour l'utilisateur foo :
~~~
# Create a full backup of the GitLab repositories and SQL database every day at 4am
0 4 * * * cd ~/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 sauvegardes sont stockées dans ~/gitlab/tmp/backups. Il est évidemment conseillé de les sauvegarder ailleurs et sur une machine distante.
Attention, le fichier `secrets.yml` contient les clés de chiffrements pour les sessions et les variables. Il n'est pas inclus dans les sauvegardes GitLab. Vous devez le copier au moins une fois dans un endroit sécurisé.
# Mises à jour
Le principe des mises à jour est basé sur un `git pull` et un `git checkout`.
## Mise à jour mineure 8.14.x vers 8.14.y
Procédure générique. Il est possible de « sauter » plusieurs versions. Par exemple, de 8.14.0 à 8.14.3.
### Sauvegarde
~~~
# sudo -iu foo
$ cd gitlab
$ bundle exec rake gitlab:backup:create RAILS_ENV=production
~~~
### Mise à jour de GitLab
~~~
$ umask 002
$ git fetch --all
$ git checkout -- Gemfile.lock db/schema.rb
$ git checkout v8.14.y -b v8.14.y
$ sed -i -e s'/app_user="git"/app_user="foo"/' \
-e 's/# Provides: .*gitlab$/# Provides: gitlab-foo/' \
lib/support/init.d/gitlab
$ sed -i 's#script_path = "/etc/init.d/gitlab"#script_path = "/etc/init.d/gitlab-foo"#g' lib/tasks/gitlab/check.rake
$ git commit -a -m 'change default user'
~~~
### Mise à jour de gitlab-shell
~~~
$ cd ~/gitlab-shell
$ git fetch
$ git checkout v$(cat ~/gitlab/GITLAB_SHELL_VERSION) -b v$(cat ~/gitlab/GITLAB_SHELL_VERSION)
~~~
### Mise à jour de gitlab-workhorse
~~~
$ cd ~/gitlab-workhorse
$ git fetch
$ git checkout v$(cat ~/gitlab/GITLAB_WORKHORSE_VERSION) -b v$(cat ~/gitlab/GITLAB_WORKHORSE_VERSION)
$ make
~~~
### Mise à jour base de données, 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.y'
~~~
### Redémarrer GitLab
~~~
# /etc/init.d/gitlab-foo restart
~~~
### Vérifier le statut
~~~
# sudo -iu foo
$ 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ée !
## Mise à jour majeure
En attente d'une nouvelle release majeure :)
Voir [8]().

489
HowtoGitlab/8.md Normal file
View File

@ -0,0 +1,489 @@
---
categories: web git
title: Howto GitLab
...
* Documentation : <https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md>
[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, un outil de tickets, un wiki, une collaboration autour de Git (merge/pull requests, etc.). GitLab ressemble sous certains aspects au logiciel propriétaire *Github*.
# Installation
Nous installons la version **8.14.X** sous **Debian 8** (Jessie) avec une approche multi-instances.
GitLab s'appuie sur Git, Ruby, Go, PostgreSQL et Redis.
> **Note** : dans les exemples ci-dessous, on va créer une instance nommée *foo*
## Dépendances
GitLab nécessite des versions très récentes de Git, Ruby et Go.
On utilise pour l'instant des versions de Jessie Backports et Stretch via un « pinning » APT :
~~~
Package: *
Pin: release n=jessie-backports
Pin-Priority: 50
Package: *
Pin: release n=stretch
Pin-Priority: 50
Package: golang golang-doc golang-src golang-go
Pin: release n=jessie-backports
Pin-Priority: 999
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
~~~
On peut ainsi installer toutes les dépendances pour Gitlab :
~~~
# 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
~~~
## Compte UNIX
Créer un compte UNIX *foo* :
~~~
# adduser --disabled-login --gecos 'GitLab instance foo' foo
~~~
> **Note** : Assurez-vous d'avoir `DIR_MODE=0750` dans `/etc/adduser.conf` pour créer le home en 750.
## PostgreSQL
GitLab recommande [PostgreSQL](HowtoPostgreSQL). On utilise donc la version 9.4 de Debian Jessie :
~~~
# apt install postgresql postgresql-client libpq-dev postgresql-contrib
~~~
Création de l'utilisateur PostgreSQL :
~~~
# sudo -u postgres createuser foo -P -D -A -R
# sudo -u postgres psql -d template1 -c 'ALTER ROLE "foo" CREATEDB;'
~~~
> **Note** : On donne les droits CREATEDB car GitLab doit faire un DROP DATABASE puis CREATE DATABASE lors de l'installation…
> **Note** : Pensez à conserver le mot de passe pour le mettre par la suite pour [GitLab CE](#gitlab-ce).
Création de l'extension `pg_trgm` :
~~~
# sudo -u postgres psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
~~~
> **Note** : C'est à faire seulement la première fois.
Création de la base pour GitLab :
~~~
# sudo -u postgres createdb -O foo -E UNICODE foo
~~~
Tester la connexion et si l'extension `pg_trgm` est bien activée :
~~~
# sudo -u foo -H psql --password -d foo
psql> SELECT true AS enabled FROM pg_available_extensions
WHERE name = 'pg_trgm' AND installed_version IS NOT NULL;
enabled
---------
t
(1 row)
~~~
## Redis
On utilise une instance Redis dédiée à chaque instance GitLab :
~~~
# apt install redis-server
# systemctl stop redis-server
# systemctl disable redis-server
~~~
Créer et activer le template d'unité systemd `/etc/systemd/system/redis@.service` :
~~~
[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
~~~
Puis :
~~~
# systemctl daemon-reload
~~~
Configuration spéciale pour l'instance :
~~~
# cat /etc/redis/foo.conf
daemonize yes
pidfile /var/run/redis/foo.pid
port 0
unixsocket /var/run/redis/foo.sock
unixsocketperm 770
timeout 0
loglevel notice
logfile /var/log/redis/foo.log
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename foo.rdb
dir /var/lib/redis
# chmod 644 /etc/redis/foo.conf
# systemctl enable redis@foo
# systemctl start redis@foo
~~~
## GitLab CE
~~~
# sudo -iu foo
$ umask 002
$ git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 8-14-stable gitlab
$ cd gitlab
$ cp config/gitlab.yml.example config/gitlab.yml
$ sed -i 's@/home/git@/home/foo@g' config/gitlab.yml
~~~
Éditer `config/gitlab.yml` :
~~~
host: foo.gitlab.example.com
port: 443
https: true
user: foo
email_from: gitlab@example.com
email_display_name: GitLab foo
email_reply_to: gitlab@example.com
~~~
Mettre une clé secrète pour le chiffrement en base.
~~~
$ cp config/secrets.yml.example config/secrets.yml
$ sed -i "s@^# db_key_base:@db_key_base: YOURSECRETKEY@" config/secrets.yml
$ chmod 600 config/secrets.yml
~~~
> **Note** : Il est conseillé de générer `YOURSECRETKEY` ainsi : `apg -m30 -n1`.
> **Note** : Il est conseillé de sauvegarder le fichier secrets.yml. Voir la section [sauvegarde](#sauvegarde).
Mettre le mot de passe PostgreSQL :
~~~
$ cp config/database.yml.postgresql config/database.yml
$ sed -i -e 's/database: gitlabhq_production/database: foo/' \
-e 's/# username: git/username: foo/' \
-e 's/# password:/password: PASSWORD/' 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.
Ajuster les droits de certains répertoires :
~~~
$ chmod 750 ~
$ chmod -R u+rwX,go-w log/
$ chmod -R u+rwX tmp/
$ chmod -R u+rwX tmp/pids/
$ chmod -R u+rwX,g+rwX tmp/sockets/
$ install -d -m 700 public/uploads/
$ chmod -R u+rwX builds/
$ chmod -R u+rwX shared/artifacts/
~~~
## Unicorn
Configuration de base d'Unicorn :
~~~
$ cp config/unicorn.rb.example config/unicorn.rb
$ sed -i \
-e 's@/home/git@/home/foo@g' \
-e 's/listen "127.0.0.1:8080", :tcp_nopush => true/#listen "127.0.0.1:8080", :tcp_nopush => true/' \
config/unicorn.rb
~~~
## Rack attack
Initialisation de la configuration de Rack::Attack (qui permet du filtrage / rate-limiting) :
~~~
$ cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
~~~
## Git
Configuration :
~~~
$ git config --global core.autocrlf input
$ git config --global gc.auto 0
$ git config --global repack.writeBitmaps true
~~~
## Resque
Configuration :
~~~
$ cp config/resque.yml.example config/resque.yml
$ sed -i 's/redis.sock/foo.sock/' config/resque.yml
~~~
## Gems
> **Important**: Votre partition `/home` ne doit pas être montée avec l'option `noexec`.
On installe les Gems requise :
~~~
$ bundle install -j$(nproc) --deployment --without development test mysql aws kerberos
~~~
## GitLab Shell
Installation :
~~~
$ bundle exec rake gitlab:shell:install REDIS_URL=unix:/var/run/redis/foo.sock RAILS_ENV=production SKIP_STORAGE_VALIDATION=true
$ chmod -R ug+rwX,o-rwx ~/repositories/
$ chmod -R ug-s ~/repositories/
$ chmod g+s ~/repositories/
~~~
## gitlab-workhorse
Installation :
~~~
$ cd
$ git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git
$ cd gitlab-workhorse
$ git checkout v$(cat ~/gitlab/GITLAB_WORKHORSE_VERSION)
$ make
~~~
## Base de données
On crée la base de données avec l'identifiant (une adresse email) et un mot de passe pour l'utilisateur *root* sur l'interface web de GitLab :
~~~
$ cd ~/gitlab
$ bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword GITLAB_ROOT_EMAIL=admingitlab@example.com
~~~
> **Note** : Conservez l'espace devant le `bundle` pour ne pas enregistrer le mot de passe dans l'historique BASH.
## Script d'init
Attention, 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="foo"/' \
-e 's/# Provides: .*gitlab/# Provides: gitlab-foo/' \
lib/support/init.d/gitlab
$ sed -i 's@script_path = "/etc/init.d/gitlab"@script_path = "/etc/init.d/gitlab-foo"@g' lib/tasks/gitlab/check.rake
$ git commit -a -m 'change default user'
# install -m 755 /home/foo/gitlab/lib/support/init.d/gitlab /etc/init.d/gitlab-foo
# systemctl enable gitlab-foo
~~~
## Logrotate
~~~
# install -m 644 /home/foo/gitlab/lib/support/logrotate/gitlab /etc/logrotate.d/gitlab-foo
# sed -i 's@/home/git@/home/foo@g' /etc/logrotate.d/gitlab-foo
~~~
## Nginx
On utilise Nginx, c'est le seul serveur web supporté officiellement par GitLab :
~~~
# apt install nginx
# adduser www-data foo
# chmod -R g+rwX /home/foo/gitlab/tmp/{pids,sockets}
# install -m 644 /home/foo/gitlab/lib/support/nginx/gitlab-ssl /etc/nginx/sites-available/foo
# sed -i -e 's@/home/git@/home/foo@g' \
-e 's/YOUR_SERVER_FQDN/foo.gitlab.example.com/g' \
-e 's@/var/log/nginx/gitlab@/var/log/nginx/foo@g' \
-e 's/upstream gitlab-workhorse/upstream gitlab-foo-workhorse/' \
-e 's@http://gitlab-workhorse@http://gitlab-foo-workhorse@' \
/etc/nginx/sites-available/foo
# ln -s /etc/nginx/sites-available/foo /etc/nginx/sites-enabled/
# /etc/init.d/nginx restart
~~~
> **Note** : La partie SSL/TLS n'est pas évoquée. À 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.
> **Note** : `apt install nginx` est à faire seulement la première fois.
## Finalisation de l'installation
Vérification de l'état de l'installation :
~~~
# sudo -iu foo
$ cd gitlab
$ bundle exec rake gitlab:env:info RAILS_ENV=production
~~~
Compilation des assets :
~~~
$ bundle exec rake assets:precompile RAILS_ENV=production
~~~
Démarrage de l'instance :
~~~
# /etc/init.d/gitlab-foo start
~~~
Vérifier le statut :
~~~
# sudo -iu foo
$ 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 http://foo.gitlab.example.com
# Sauvegarde
On peut réaliser des sauvegardes grâce à la commande `bundle exec rake gitlab:backup:create RAILS_ENV=production`
On peut ainsi mettre un cron pour l'utilisateur foo :
~~~
# Create a full backup of the GitLab repositories and SQL database every day at 4am
0 4 * * * cd ~/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 sauvegardes sont stockées dans ~/gitlab/tmp/backups. Il est évidemment conseillé de les sauvegarder ailleurs et sur une machine distante.
Attention, le fichier `secrets.yml` contient les clés de chiffrements pour les sessions et les variables. Il n'est pas inclus dans les sauvegardes GitLab. Vous devez le copier au moins une fois dans un endroit sécurisé.
# Mises à jour
Le principe des mises à jour est basé sur un `git pull` et un `git checkout`.
## Mise à jour mineure 8.14.x vers 8.14.y
Procédure générique. Il est possible de « sauter » plusieurs versions. Par exemple, de 8.14.0 à 8.14.3.
### Sauvegarde
~~~
# sudo -iu foo
$ cd gitlab
$ bundle exec rake gitlab:backup:create RAILS_ENV=production
~~~
### Mise à jour de GitLab
~~~
$ umask 002
$ git fetch --all
$ git checkout -- Gemfile.lock db/schema.rb
$ git checkout v8.14.y -b v8.14.y
$ sed -i -e s'/app_user="git"/app_user="foo"/' \
-e 's/# Provides: .*gitlab$/# Provides: gitlab-foo/' \
lib/support/init.d/gitlab
$ sed -i 's#script_path = "/etc/init.d/gitlab"#script_path = "/etc/init.d/gitlab-foo"#g' lib/tasks/gitlab/check.rake
$ git commit -a -m 'change default user'
~~~
### Mise à jour de gitlab-shell
~~~
$ cd ~/gitlab-shell
$ git fetch
$ git checkout v$(cat ~/gitlab/GITLAB_SHELL_VERSION) -b v$(cat ~/gitlab/GITLAB_SHELL_VERSION)
~~~
### Mise à jour de gitlab-workhorse
~~~
$ cd ~/gitlab-workhorse
$ git fetch
$ git checkout v$(cat ~/gitlab/GITLAB_WORKHORSE_VERSION) -b v$(cat ~/gitlab/GITLAB_WORKHORSE_VERSION)
$ make
~~~
### Mise à jour base de données, 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.y'
~~~
### Redémarrer GitLab
~~~
# /etc/init.d/gitlab-foo restart
~~~
### Vérifier le statut
~~~
# sudo -iu foo
$ 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ée !
## Mise à jour majeure
En attente d'une nouvelle release majeure :)