2019-06-01 21:08:41 +00:00
|
|
|
|
= Установка и настройка GitLab в LXC
|
|
|
|
|
:category: Программирование
|
|
|
|
|
:tags: программирование, gitlab, git, lxc, контейнеры, ubuntu,
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
:toc:
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
2019-04-20 20:24:14 +00:00
|
|
|
|
Установка выполняется в операционной системе Ubuntu Bionic.
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
== LXC
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
|
|
|
|
Создание базового контейнера:
|
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
[source,sh]
|
|
|
|
|
----
|
2019-04-20 16:11:30 +00:00
|
|
|
|
lxc-create -t download -n bionic-base -- --dist ubuntu --release bionic --arch amd64
|
2019-06-01 21:08:41 +00:00
|
|
|
|
----
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
|
|
|
|
Создание контейнеров для GitLab и GitLab Runner:
|
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
[source,sh]
|
|
|
|
|
----
|
2019-04-20 16:11:30 +00:00
|
|
|
|
lxc-copy -n bionic-base -N gitlab-bionic -s
|
|
|
|
|
lxc-copy -n bionic-base -N gitlab-runner-bionic -s
|
2019-06-01 21:08:41 +00:00
|
|
|
|
----
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
|
|
|
|
Файл `/var/lib/lxc/gitlab-bionic/config`:
|
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
....
|
2019-04-20 16:11:30 +00:00
|
|
|
|
# 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
|
2019-06-01 21:08:41 +00:00
|
|
|
|
....
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
|
|
|
|
Файл `/var/lib/lxc/gitlab-runner-bionic/config`:
|
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
....
|
2019-04-20 16:11:30 +00:00
|
|
|
|
# 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
|
2019-06-01 21:08:41 +00:00
|
|
|
|
....
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
== GitLab
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
|
|
|
|
Установить GitLab:
|
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
[source,sh]
|
|
|
|
|
----
|
2019-04-20 16:11:30 +00:00
|
|
|
|
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
|
2019-06-01 21:08:41 +00:00
|
|
|
|
----
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
Отредактировать файл `/etc/locale.gen` и сгенерировать локали для
|
|
|
|
|
системы:
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
[source,sh]
|
|
|
|
|
----
|
2019-04-20 16:11:30 +00:00
|
|
|
|
sudo locale-gen
|
2019-06-01 21:08:41 +00:00
|
|
|
|
----
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
|
|
|
|
Отредактировать файл `/etc/gitlab/gitlab.rb` и выполнить:
|
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
[source,sh]
|
|
|
|
|
----
|
2019-04-20 16:11:30 +00:00
|
|
|
|
sudo gitlab-ctl reconfigure
|
|
|
|
|
sudo gitlab-ctl restart
|
2019-06-01 21:08:41 +00:00
|
|
|
|
----
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
== GitLab Runner и Docker
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
|
|
|
|
Установить GitLab Runner:
|
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
[source,sh]
|
|
|
|
|
----
|
2019-04-20 16:11:30 +00:00
|
|
|
|
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
|
2019-06-01 21:08:41 +00:00
|
|
|
|
----
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
|
|
|
|
Во время установки ввести токен приведённый на странице `admin/runners`,
|
|
|
|
|
а в качестве исполнителя задач `docker`.
|
|
|
|
|
|
|
|
|
|
Для работы Docker внутри контейнера нужно удалить AppArmor:
|
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
[source,sh]
|
|
|
|
|
----
|
2019-04-20 16:11:30 +00:00
|
|
|
|
sudo apt purge apparmor
|
2019-06-01 21:08:41 +00:00
|
|
|
|
----
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
Внутри контейнера для Docker желательно использовать драйвер `btrfs` cat
|
|
|
|
|
/etc/docker/daemon.json
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
\{ ``storage-driver'': ``btrfs'' }
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
== Ссылки
|
2019-04-20 16:11:30 +00:00
|
|
|
|
|
2019-06-01 21:08:41 +00:00
|
|
|
|
* https://docs.gitlab.com/runner/register/index.html[GitLab Runner]
|
|
|
|
|
* https://docs.gitlab.com/ee/ci/runners/[Runners]
|
|
|
|
|
* https://habr.com/ru/company/southbridge/blog/306596/[Gitlab-CI]
|