Далее будет подробная инструкция как развернуть Gitlab с помощью docker-compose и настроить CI/CD
1. Развернуть Gitlab и Gitlab Runner локально с помощью docker-compose:
version: '3.5' services: gitlab: image: gitlab/gitlab-ce:latest hostname: gitlab restart: unless-stopped environment: GITLAB_OMNIBUS_CONFIG: | gitlab_rails['gitlab_shell_ssh_port'] = 8022 ports: - '8080:80' - '8022:22' volumes: - ./config/gitlab:/etc/gitlab - ./data/gitlab:/var/opt/gitlab - ./logs:/var/log/gitlab networks: - gitlab-network gitlab-runner: image: gitlab/gitlab-runner:alpine container_name: gitlab-runner restart: unless-stopped depends_on: - gitlab volumes: - ./config/gitlab-runner:/etc/gitlab-runner - /var/run/docker.sock:/var/run/docker.sock networks: - gitlab-network networks: gitlab-network: name: gitlab-network
2. Открыть в браузере http://localhost:8080/ и создать пользователя
3. Создать проект в Gitlab http://localhost:8080/projects/new
4. Клонировать проект локально
5. Добавить файл .gitlab-ci.yml
image: docker:latest before_script: - docker info build: stage: build script: - docker ps -a only: - master test: stage: test script: - docker ps -a only: - merge_requests deploy: stage: deploy script: - docker ps -a only: - master
Подробная документация тут https://docs.gitlab.com/ee/ci/yaml/README.html
6. Добавить Gitlab runner
- посмотреть токен http://localhost:8080/$user/$project/-/settings/ci_cdsettings/ci_cd для проекта
- добавить и запустить sh скрипт gitlab-runner-register.sh:
#!/bin/sh # Get the registration token from: # http://localhost:8080/$user/$project/-/settings/ci_cdsettings/ci_cd -> Runners -> Expand registration_token=zjsv7YBZTVT8kNgu2_hy docker exec -it gitlab-runner \ gitlab-runner register \ --non-interactive \ --registration-token ${registration_token} \ --locked=false \ --description docker-stable \ --url http://gitlab \ --executor docker \ --docker-image docker:stable \ --docker-volumes "/var/run/docker.sock:/var/run/docker.sock" \ --docker-network-mode gitlab-network
7. Перейти на страницу http://localhost:8080/$user/$project/-/pipelines , например, http://localhost:8080/root/test/-/pipelines
и проверить, что есть задания в очереди и они выполняются