2019-04-20 16:11:30 +00:00
|
|
|
|
---
|
|
|
|
|
title: "Установка и настройка GitLab в LXC"
|
|
|
|
|
category: Программирование
|
2019-04-23 17:40:06 +00:00
|
|
|
|
tags: программирование, gitlab, git, lxc, контейнеры, ubuntu,
|
2019-04-20 16:11:30 +00:00
|
|
|
|
summary:
|
|
|
|
|
toc: yes
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
[TOC]
|
|
|
|
|
|
2019-04-20 20:24:14 +00:00
|
|
|
|
Установка выполняется в операционной системе Ubuntu Bionic.
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
|
|
|
|
### LXC
|
|
|
|
|
|
|
|
|
|
Создание базового контейнера:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
lxc-create -t download -n bionic-base -- --dist ubuntu --release bionic --arch amd64
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Создание контейнеров для GitLab и GitLab Runner:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
lxc-copy -n bionic-base -N gitlab-bionic -s
|
|
|
|
|
lxc-copy -n bionic-base -N gitlab-runner-bionic -s
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Файл `/var/lib/lxc/gitlab-bionic/config`:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
# Distribution configuration
|
|
|
|
|
lxc.include = /usr/share/lxc/config/common.conf
|
|
|
|
|
|
|
|
|
|
lxc.arch = linux64
|
|
|
|
|
lxc.start.auto = 1
|
|
|
|
|
|
|
|
|
|
# Network configuration
|
|
|
|
|
lxc.net.0.type = veth
|
|
|
|
|
lxc.net.0.link = br0
|
|
|
|
|
lxc.net.0.flags = up
|
|
|
|
|
lxc.net.0.ipv4.address = 192.168.0.216/24
|
|
|
|
|
lxc.net.0.ipv4.gateway = 192.168.0.1
|
|
|
|
|
lxc.net.0.hwaddr = 00:16:3e:00:02:16
|
|
|
|
|
|
|
|
|
|
# Container specific configuration
|
|
|
|
|
lxc.rootfs.path = overlay:/var/lib/lxc/bionic-base/rootfs:/var/lib/lxc/gitlab-bionic/delta0
|
|
|
|
|
lxc.uts.name = gitlab-bionic
|
|
|
|
|
|
|
|
|
|
lxc.autodev = 1
|
|
|
|
|
lxc.pty.max = 16384
|
|
|
|
|
lxc.cgroup.devices.allow = c 10:200 rwm
|
|
|
|
|
lxc.mount.entry = /dev/net dev/net none bind,create=dir
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Файл `/var/lib/lxc/gitlab-runner-bionic/config`:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
# Distribution configuration
|
|
|
|
|
lxc.include = /usr/share/lxc/config/common.conf
|
|
|
|
|
|
|
|
|
|
lxc.arch = linux64
|
|
|
|
|
lxc.start.auto = 1
|
|
|
|
|
|
|
|
|
|
# Network configuration
|
|
|
|
|
lxc.net.0.type = veth
|
|
|
|
|
lxc.net.0.link = br0
|
|
|
|
|
lxc.net.0.flags = up
|
|
|
|
|
lxc.net.0.ipv4.address = 192.168.0.217/24
|
|
|
|
|
lxc.net.0.ipv4.gateway = 192.168.0.1
|
|
|
|
|
lxc.net.0.hwaddr = 00:16:3e:00:02:17
|
|
|
|
|
|
|
|
|
|
# Container specific configuration
|
|
|
|
|
lxc.rootfs.path = overlay:/var/lib/lxc/bionic-base/rootfs:/var/lib/lxc/gitlab-runner-bionic/delta0
|
|
|
|
|
lxc.uts.name = gitlab-runner-bionic
|
|
|
|
|
|
|
|
|
|
# Required for Docker
|
|
|
|
|
lxc.aa_profile = unconfined
|
|
|
|
|
lxc.cgroup.devices.allow = a
|
|
|
|
|
lxc.cap.drop =
|
|
|
|
|
|
|
|
|
|
lxc.autodev = 1
|
|
|
|
|
lxc.pty.max = 16384
|
|
|
|
|
lxc.cgroup.devices.allow = c 10:200 rwm
|
|
|
|
|
lxc.mount.entry = /dev/net dev/net none bind,create=dir
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### GitLab
|
|
|
|
|
|
|
|
|
|
Установить GitLab:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
sudo lxc-start -n gitlab-bionic
|
|
|
|
|
sudo lxc-attach -n gitlab-bionic
|
|
|
|
|
sudo apt install curl
|
|
|
|
|
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
|
|
|
|
|
sudo apt install gitlab-ce
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Отредактировать файл `/etc/locale.gen` и сгенерировать локали для системы:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
sudo locale-gen
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Отредактировать файл `/etc/gitlab/gitlab.rb` и выполнить:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
sudo gitlab-ctl reconfigure
|
|
|
|
|
sudo gitlab-ctl restart
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### GitLab Runner и Docker
|
|
|
|
|
|
|
|
|
|
Установить GitLab Runner:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
sudo lxc-start -n runner-bionic
|
|
|
|
|
sudo lxc-attach -n runner-bionic
|
|
|
|
|
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
|
|
|
|
|
sudo apt install gitlab-runner docker.io
|
|
|
|
|
sudo gitlab-runner register
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Во время установки ввести токен приведённый на странице `admin/runners`,
|
|
|
|
|
а в качестве исполнителя задач `docker`.
|
|
|
|
|
|
|
|
|
|
Для работы Docker внутри контейнера нужно удалить AppArmor:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
sudo apt purge apparmor
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Внутри контейнера для Docker желательно использовать драйвер `btrfs`
|
|
|
|
|
cat /etc/docker/daemon.json
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"storage-driver": "btrfs"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Ссылки
|
|
|
|
|
|
|
|
|
|
* [GitLab Runner](https://docs.gitlab.com/runner/register/index.html)
|
|
|
|
|
* [Runners](https://docs.gitlab.com/ee/ci/runners/)
|
|
|
|
|
* [Gitlab-CI](https://habr.com/ru/company/southbridge/blog/306596/)
|