在gitlab上使用dind构建docker镜像

在gitlab上使用dind构建docker镜像

    • 注册gitlab-runner
    • .gitlab-ci.yaml



注册gitlab-runner

[[runners]]
  name = "docker executor at 172.20.6.188"
  url = "http://172.20.6.188:8089/"
  token = "xxz8mo**********Sa"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "docker:git"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0
    pull_policy = "if-not-present"
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]

.gitlab-ci.yaml

image: docker:git
services:
- docker:dind

variables:
  PROJECT_NAME: "wec-pay"
  PROJECT_WAR_PATH: "./wec-pay-web/target/wec-pay.war"
  image: ${DOCKER_REGISTRY}/${PROJECT_NAME}:${CI_COMMIT_TAG}_${CI_COMMIT_SHA}

stages:
  - test
  - package
  - build

job_test:
  stage: test
  tags:
    - mvn_test
  image: 172.16.9.100:5000/java_ci:latest
  script:
    - mvn test

job_package_prod:
  stage: package
  image: 172.16.9.100:5000/java_ci:latest
  only:
    - /^prod_v.*$/
  tags:
    - mvn_package
  variables:
    PROFILE: "production"
  script:
    - mvn clean install -f pom.xml -P ${PROFILE}
  artifacts:
    name: ${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}
    paths:
      - ${PROJECT_WAR_PATH}
    expire_in: 1 day

job_build_prod:
  stage: build
  only: 
    - /^prod_v.*$/
  tags:
    - docker_build
  variables:
    DOCKER_REGISTRY: "wecloud2:5000"
  script:
    - docker build --build-arg PROJECT_WAR_PATH=${PROJECT_WAR_PATH} -t $image .
    - docker push $image

你可能感兴趣的:(CI/CD)