Docker gitlab-runner安装

# Gitlab-runner
### gitlab-runner 安装
```Powershell
docker run -d --name gitlab-runner --restart always -v /docker/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest
```
### runner注册
`# docker exec -it gitlab-runner /bin/sh`
```Powershell
gitlab-runner register
```
- IP

    `http://192.168.19.128:9902/`
- Token

    `46-cAq6zBGhsUEGZs8b5`  
- Tags

    `Test`
- Description

    `Test`
- Image 

    `docker`
- Image version

    `alpine:latest`

---
# 修改配置

### config.toml 修改
> 由安装时映射
路径` /docker/gitlab-runner/config`

```toml
[[runners]]
  name = "Test"
  url = "http://192.168.19.128:9902/"
  token = "NPCM563xkdAg5-yYjPo9"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "alpine:latest"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/docker/gitlab-runner/builds:/builds","/cache"]
    shm_size = 0
```
此处需要在`volumes`处将`/builds`映射到宿主机
```Powershell
#before
volumes = ["/cache"]

#after
volumes = ["/docker/gitlab-runner/builds:/builds","/cache"]
```

### .gitlab-ci.yml 修改
```YAML
image: mcr.microsoft.com/dotnet/sdk:latest

stages:          
  - publish

publish-job:
  stage: publish
  script:
    - cd WebApplication1/WebApplication1
    - dotnet publish -c Release --output /builds/publish
  tags:
    - Test
```

发布路径在宿主机为`/docker/gitlab-runner/builds/publish`
posted @ 2021-11-02 15:54  BrainK_1400  阅读(216)  评论(0编辑  收藏  举报