148 lines
3.6 KiB
Markdown
148 lines
3.6 KiB
Markdown
---
|
||
title: "Установка и настройка GitLab в LXC"
|
||
category: Программирование
|
||
tags: программирование, gitlab, git, lxc, контейнеры, ubuntu
|
||
summary:
|
||
toc: yes
|
||
...
|
||
|
||
[TOC]
|
||
|
||
Установка вылолняется в операционной системе Ubuntu Bionic.
|
||
|
||
### 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/)
|