簡體   English   中英

Gradle bootBuildImage 使用 docker:dind 服務在 GitLab CI/CD 中失敗並出現“未找到摘要”

[英]Gradle bootBuildImage fails with 'No digest found' in GitLab CI/CD using docker:dind service

我想使用bootBuildImage任務構建 Spring 引導 2.4 服務的 docker 映像,並將其推送到 GitLab 注冊表。

我有以下.gitlab-ci.yml文件:

stages:
  - build
  - deploy

build:
  stage: build
  rules:
    - if: $CI_MERGE_REQUEST_ID
  image: azul/zulu-openjdk:15.0.2
  script:
    - export GRADLE_OPTS="-Dorg.gradle.daemon=false -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false"
    - ./gradlew clean build

docker-build:
  variables:
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: "/certs"
  stage: build
  image: azul/zulu-openjdk:15.0.2
  services:
    - docker:dind
  script:
    - apt-get update
    - apt-get install -y apt-transport-https ca-certificates curl software-properties-common
    - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add
    - add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    - apt-get update -y
    - apt-get install -y docker-ce
    - service docker start
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
    - ./gradlew bootBuildImage --imageName="$CI_REGISTRY_IMAGE"
    - docker push "$CI_REGISTRY_IMAGE"
  only:
    - develop

但我收到以下錯誤,這不足以進一步挖掘:

$ service docker start
 * Starting Docker: docker
   ...done.
$ docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
$ ./gradlew bootBuildImage --imageName="$CI_REGISTRY_IMAGE"
Downloading https://services.gradle.org/distributions/gradle-6.7.1-bin.zip
.........10%..........20%..........30%..........40%..........50%.........60%..........70%..........80%..........90%..........100%
Welcome to Gradle 6.7.1!
Here are the highlights of this release:
 - File system watching is ready for production use
 - Declare the version of Java your build requires
 - Java 15 support
For more details see https://docs.gradle.org/6.7.1/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :compileJava
> Task :processResources
> Task :classes
> Task :bootJarMainClassName
> Task :bootJar
> Task :bootBuildImage
Building image 'registry.gitlab.com/company/project/web-api:latest'
 > Pulling builder image 'docker.io/paketobuildpacks/builder:base' ..................................................
> Task :bootBuildImage FAILED
5 actionable tasks: 5 executed
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootBuildImage'.
> No digest found
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 4m 32s

如果有更好的方法可以通過 GitLab CI/CD 實現這一點,請告訴我:)

任何幫助表示贊賞!

謝謝

在仔細閱讀了 GitLab CI 文檔后,發現我不得不添加這些變量:

DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"

完整.gitlab-ci.yml文件:

stages:
  - build
  - deploy

build:
  stage: build
  rules:
    - if: $CI_MERGE_REQUEST_ID
  image: azul/zulu-openjdk:15.0.2
  script:
    - export GRADLE_OPTS="-Dorg.gradle.daemon=false -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false"
    - ./gradlew clean build

docker-build:
  variables:
    DOCKER_HOST: tcp://docker:2376
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: "/certs"
    DOCKER_TLS_VERIFY: 1
    DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
  stage: build
  image: azul/zulu-openjdk:15.0.2
  services:
    - docker:dind
  script:
    - apt-get update
    - apt-get install -y apt-transport-https ca-certificates curl software-properties-common
    - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add
    - add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    - apt-get update -y
    - apt-get install -y docker-ce
    - service docker start
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
    - ./gradlew bootBuildImage --imageName="$CI_REGISTRY_IMAGE"
    - docker push "$CI_REGISTRY_IMAGE"
  only:
    - develop

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM