147 lines
3.7 KiB
Plaintext
147 lines
3.7 KiB
Plaintext
= Установка и настройка GitLab в LXC
|
||
:category: Программирование
|
||
:tags: программирование, gitlab, git, lxc, контейнеры, ubuntu,
|
||
|
||
:toc:
|
||
|
||
Установка выполняется в операционной системе Ubuntu Bionic.
|
||
|
||
== LXC
|
||
|
||
Создание базового контейнера:
|
||
|
||
[source,sh]
|
||
----
|
||
lxc-create -t download -n bionic-base -- --dist ubuntu --release bionic --arch amd64
|
||
----
|
||
|
||
Создание контейнеров для GitLab и GitLab Runner:
|
||
|
||
[source,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:
|
||
|
||
[source,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` и сгенерировать локали для
|
||
системы:
|
||
|
||
[source,sh]
|
||
----
|
||
sudo locale-gen
|
||
----
|
||
|
||
Отредактировать файл `/etc/gitlab/gitlab.rb` и выполнить:
|
||
|
||
[source,sh]
|
||
----
|
||
sudo gitlab-ctl reconfigure
|
||
sudo gitlab-ctl restart
|
||
----
|
||
|
||
== GitLab Runner и Docker
|
||
|
||
Установить GitLab Runner:
|
||
|
||
[source,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:
|
||
|
||
[source,sh]
|
||
----
|
||
sudo apt purge apparmor
|
||
----
|
||
|
||
Внутри контейнера для Docker желательно использовать драйвер `btrfs` cat
|
||
/etc/docker/daemon.json
|
||
|
||
\{ ``storage-driver'': ``btrfs'' }
|
||
|
||
== Ссылки
|
||
|
||
* 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]
|