【系列】CentOS 7.3 离线安装(无网络环境)CI CD环境之gitlab runner 关于私有docker仓库配置

目录

1.【系列】CentOS 7.3 离线安装(无网络环境)CI CD环境之docker+docker compose

2.【系列】CentOS 7.3 离线安装(无网络环境)CI CD环境之gitlab + gitlab runner(docker in docker)

3.【系列】CentOS 7.3 离线安装(无网络环境)CI CD环境之harbor 

4.【系列】CentOS 7.3 离线安装(无网络环境)CI CD环境之gitlab runner 关于私有docker仓库配置 (本篇在此)

5.【系列】CentOS 7.3 离线安装(无网络环境)CI CD环境之sonarqube配置 

 

1.为gitlab runner 所在的机器配置insecure-registries

因为docker默认是不允许使用http协议进行通信的,所有必须要做此配置,才可以是docker使用http协议连接仓库

命令如下:

vim  /etc/docker/daemon.json #如果没有该文件则创建
 
#添加你的配置
{
    "registry-mirrors": [
      "http://188.6.7.147"
    ],
    "insecure-registries": ["188.6.7.147"]
}

#重启docker
systemctl daemon-load
systemctl restart docker.service

 

重启docker服务后 使用docker login登陆测试以下

2.修改gitlab runner comfig.toml

增加docker.sock的映射,配置修改完如下:

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "gis-group-runner1"
  url = "http://188.6.7.131/"
  token = "qQZ1p2hETvf94F7hNFJt"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
  [runners.docker]
    tls_verify = false
    image = "Docker:19.03.11"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
    shm_size = 0
    pull_policy = "if-not-present"

3.gitlab-ci.yml的配置

在gitlab runner docker in docker 中,一定要使用dind的docker镜像在特权模式下运行脚本,这一点需要注意,否则会出现 dial tcp 188.6.7.147:443: connect: no route to host 的错误,具体gitlab-ci.yml配置如下:

image: docker:latest
# before_script:
#    - "docker info"
#   - curl 188.6.7.147
#   - docker login -u gitlab -p $CI_JOB_TOKEN $CI_REGISTRY

stages:
    - build
    - docker_build

build:
    stage: build
    image: $CI_REGISTRY/library/mcr.microsoft.com/dotnet/core/sdk:3.1
    script:
       # - dotnet
       # - export DOCKER_HOST="tcp://docker:2375/"
       # - chcp 65001
        
        - "dotnet restore k8s.NET.Demo.sln --interactive --source $NUGET_SOURCE"
        - "dotnet build --no-restore"
       # - "dotnet msbuild restore /p:RestoreSources=$NUGET_SOURCE"
        

docker-build-and-push:
    stage: docker_build
    image: docker:latest
    services:
        # - docker:dind
    script: 
      #  - chcp 65001
        - "docker info"
        - echo $CI_REGISTRY_TOKEN | docker login $CI_REGISTRY -u $CI_REGISTRY_USERNAME --password-stdin 
        - docker build -t $CI_REGISTRY/test.gis/k8s.net.demo:0.1.1 .
        - docker push $CI_REGISTRY/test.gis/k8s.net.demo:0.1.1

 然后提交代码测试,结果如下:

 

 至此,关于gitlab runner 结合内网harbor私库的配置就完成,这里只讲了关于docker镜像的拉取和推送,关于结合k8s的自动部署没有展开,会在后续文章中记录。

posted @ 2020-06-26 16:16  C_supreme  阅读(1257)  评论(0编辑  收藏  举报