简体   繁体   中英

CI/CD Gitlab with Harbor Registry

I have 3 server

  1. Gitlab
  2. Gitlab Runner
  3. Harbor Registry

When I run CI/CD on Gitlab but it cannot login to Harbor Registry. This is error.

Get https://172.21.5.247/v1/users/: x509: cannot validate certificate for 172.21.5.247 because it doesn't contain any IP SANs

When I try login docker on server Gitlab and Gitlab Runner is successfully. I added "insecure-registries" to two server. 在此处输入图像描述

.gitlab.ci.yml file

image: docker:18-git

variables:
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: ""
  DOCKER_HOST: tcp://localhost:2375

stages:
  - build
  - push
services:
  - name: docker:dind
    command: ["--insecure-registry=172.21.5.247:443"]

before_script:
  - echo $HARBOR_USERNAME
  - echo -n $HARBOR_PASSWORD | docker login -u $HARBOR_USERNAME -p $HARBOR_PASSWORD $HARBOR_REGISTRY
  - docker version
  - docker info

after_script:
  - docker logout $HARBOR_REGISTRY

Build:
  stage: build
  script:
    - docker pull $HARBOR_REGISTRY_IMAGE:latest || true
    - >
      docker build
      --pull
      --cache-from $HARBOR_REGISTRY_IMAGE:latest
      --tag $HARBOR_REGISTRY_IMAGE:$CI_COMMIT_SHA .
    - docker push $HARBOR_REGISTRY_IMAGE:$CI_COMMIT_SHA

Push_When_tag:
  stage: push
  only:
    - tags
  script:
    - docker pull $HARBOR_REGISTRY_IMAGE:$CI_COMMIT_SHA
    - docker tag $HARBOR_REGISTRY_IMAGE:$CI_COMMIT_SHA $HARBOR_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
    - docker push $HARBOR_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME

It have error in docker login.

Since Harbor 2.2 minor release you are able to create a harbor robot login, afterwards write these credentials to Settings -> CI/CD -> Variables :

-HARBOR_ROBOT_USER (Important. you have to escape the $ in the robot username eg. robot$$myuser robot account name containing "$" will cause... )

-HARBOR_ROBOT_PASSWORD

Now you are able to use these Variables in before script as follows

- HARBOR_ROBOT_PASSWORD=${HARBOR_ROBOT_PASSWORD}
- HARBOR_ROBOT_USER=${HARBOR_ROBOT_USER}

## login process to harbor docker registry
  echo $HARBOR_ROBOT_PASSWORD | docker login --username $HARBOR_ROBOT_USER  --password-stdin ${HARBOR_REGISTRY}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM